Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Update FFI related code for compilation in JDK20 #12

Conversation

ChengJin01
Copy link

@ChengJin01 ChengJin01 commented Jan 20, 2023

The change is to update the code specific to FFI in OpenJDK
to ensure it gets compiled in JDK20 as we have been working
on the changes in OpenJDK & OpenJ9 to deal with the latest
APIs intended for JEP434.

Commit 1: Replace part of FFI APIs with the latest APIs in JDK20
Commit 2: Disable FFI related code in OpenJDK for JDK20

Note:
Further changes for all FFI related code in JEP434/JDK20 will be made via eclipse-openj9/openj9#16329.

Signed-off-by: ChengJin01 jincheng@ca.ibm.com

Daniel D. Daugherty and others added 30 commits December 3, 2022 04:13
8298070: ProblemList jdk/internal/vm/Continuation/Fuzz.java#default with ZGC on X64
8298071: ProblemList tests failing due to JDK-8298059
8298072: ProblemList compiler/c1/TestPrintC1Statistics.java in Xcomp mode on linux-aarch64

Reviewed-by: azvegint
…g too narrow type which is later replaced by top

Reviewed-by: thartmann, rcastanedalo, kvn
…ecTest.java intermittently timeout

Reviewed-by: weijun, wetmore
Reviewed-by: dfuchs, mullan, rriggs, alanb
Reviewed-by: coleenp, stuefe, dholmes
…eview)

Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Per Minborg <pminborg@openjdk.org>
Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Reviewed-by: jvernee, pminborg, psandoz, alanb, sundar
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Nick Gasson <ngasson@openjdk.org>
Co-authored-by: Per Minborg <pminborg@openjdk.org>
Reviewed-by: rehn, mcimadamore, vlivanov
Reviewed-by: mdoerr, stuefe
Reviewed-by: mcimadamore
…hange of TextComponent sends TextEvent

Reviewed-by: honkar, aivanov
…th "Expected outer stream to have 3 events"

Reviewed-by: mgronlun
Fixes: eclipse-openj9/openj9#16276

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
…e number of mismatched pixels [1024] of [1024] is < [0.100000] threshold"

Reviewed-by: almatvee
@tajila
Copy link
Member

tajila commented Jan 24, 2023

@tajila do you have any concerns with 7fa5db1c1d16 ?

@pshipton No concerns

The change is to simply replace the outdated APIs in all
FFI specific code against the latest APIs for JEP434
as follows to have them compiled successfully in JDK20:
1) replaced MemorySession with SegmentScope
2) replaced MemoryAddress with MemorySegment

Note:
The code is likely to be updated further to ensure it
literally works in this way after all FFI related code
is updated for JEP434 in JDK20.

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
@ChengJin01 ChengJin01 force-pushed the ffi_disable_java_code_in_compiling_jdk20 branch from 9128833 to d7fae96 Compare January 24, 2023 22:42
@pshipton
Copy link
Member

Pls fix the PR title and description to cover both of the commits.

@ChengJin01 ChengJin01 changed the title [FFI] Disable FFI related code in OpenJDK for JDK20 [FFI] Update FFI related code for compilation in JDK20 Jan 24, 2023
@ChengJin01
Copy link
Author

Pls fix the PR title and description to cover both of the commits.

The PR title plus description is updated accordingly as requested.

@ChengJin01 ChengJin01 force-pushed the ffi_disable_java_code_in_compiling_jdk20 branch from d7fae96 to 501a63b Compare January 25, 2023 19:02
@pshipton
Copy link
Member

@keithc-ca did you get all the changes you requested?

@keithc-ca
Copy link
Member

@keithc-ca did you get all the changes you requested?

Almost: #12 (comment)

@keithc-ca
Copy link
Member

@ChengJin01 Can you remove the redundant uses of "[FFI]" in the commit messages and descriptions of this and eclipse-openj9/openj9#16585, please?

@ChengJin01 ChengJin01 force-pushed the ffi_disable_java_code_in_compiling_jdk20 branch from 501a63b to 96ac28c Compare January 31, 2023 16:45
@ChengJin01 ChengJin01 changed the title [FFI] Update FFI related code for compilation in JDK20 Update FFI related code for compilation in JDK20 Jan 31, 2023
@ChengJin01
Copy link
Author

@ChengJin01 Can you remove the redundant uses of "[FFI]" in the commit messages and descriptions of this and eclipse-openj9/openj9#16585, please?

Removed as suggested above.

@keithc-ca
Copy link
Member

This doesn't compile in its current state; make java.base-java yields errors like:

jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/ppc64/aix/AixPPC64Linker.java:63: error: non-static method arrangeDowncall(MethodType,FunctionDescriptor,LinkerOptions) cannot be referenced from a static context
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/ppc64/aix/AixPPC64Linker.java:68: error: non-static method arrangeUpcall(MethodHandle,MethodType,FunctionDescriptor,SegmentScope) cannot be referenced from a static context
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/ppc64/sysv/SysVPPC64leLinker.java:63: error: non-static method arrangeDowncall(MethodType,FunctionDescriptor,LinkerOptions) cannot be referenced from a static context
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/ppc64/sysv/SysVPPC64leLinker.java:68: error: non-static method arrangeUpcall(MethodHandle,MethodType,FunctionDescriptor,SegmentScope) cannot be referenced from a static context
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/SysVS390xLinker.java:63: error: non-static method arrangeDowncall(MethodType,FunctionDescriptor,LinkerOptions) cannot be referenced from a static context
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/SysVS390xLinker.java:68: error: non-static method arrangeUpcall(MethodHandle,MethodType,FunctionDescriptor,SegmentScope) cannot be referenced from a static context
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java:57: error: non-static method arrangeDowncall(MethodType,FunctionDescriptor,LinkerOptions) cannot be referenced from a static context
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java:62: error: non-static method arrangeUpcall(MethodHandle,MethodType,FunctionDescriptor,SegmentScope) cannot be referenced from a static context
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java:57: error: non-static method arrangeDowncall(MethodType,FunctionDescriptor,LinkerOptions) cannot be referenced from a static context
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
                           ^
jdk20/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64Linker.java:62: error: non-static method arrangeUpcall(MethodHandle,MethodType,FunctionDescriptor,SegmentScope) cannot be referenced from a static context
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
                           ^
10 errors

@keithc-ca keithc-ca self-requested a review February 1, 2023 21:53
@ChengJin01
Copy link
Author

This doesn't compile in its current state; make java.base-java yields errors like:

This is because we removed static from arrangeDowncall() & arrangeUpcall() in CallArranger.java

Please note the static keyword remains arrangeDowncall & arrangeUpcall for the last changes in JDK20.

e.g.
https://github.com/ibmruntimes/openj9-openjdk-jdk20/blob/master/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java#L122

 --->    public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
...
        return handle;
    }

---> public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope scope) {
 ...
return UpcallLinker.make(CSysV, target, bindings.callingSequence, scope);
    }

which means we need to restore static back to the two methods.

The change is to disable all downcall & upcall code
specific to FFI in OpenJDK for the moment to ensure
it gets compiled in JDK20 as we have been working
on the changes in OpenJDK & OpenJ9 to deal with
the latest APIs intended for JEP434.

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
@ChengJin01 ChengJin01 force-pushed the ffi_disable_java_code_in_compiling_jdk20 branch from 96ac28c to 7608d05 Compare February 1, 2023 22:59
@ChengJin01
Copy link
Author

ChengJin01 commented Feb 1, 2023

As discussed with @keithc-ca offline, we have to restore static on X64 (Linux & Win) (which remains unchanged since JDK16) and on Power & zLinux which follow the pattern on X64 (there was compilation error on Aarch64 because we removed static in there to keep consistent with the existing signature of methods in CallArranger on Aarch64). (Restored at 7608d05)

As for the non-static methods on Aarch64 in which static was removed since JDK18, I think it is specific to Hotspot but inappropriate for OpenJ9 given the underlying code at java level remain the same on all supported platforms.

@ChengJin01
Copy link
Author

ChengJin01 commented Feb 2, 2023

I double-checked the code at https://github.com/ibmruntimes/openj9-openjdk-jdk20/blob/master/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java#L99

    public static final CallArranger LINUX = new LinuxAArch64CallArranger();
    public static final CallArranger MACOS = new MacOsAArch64CallArranger();

and

protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDescriptor function, LinkerOptions options) {

    protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDescriptor function, LinkerOptions options) {
        return CallArranger.LINUX.arrangeDowncall(inferredMethodType, function, options); <----
    }

    @Override
    protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType, FunctionDescriptor function, SegmentScope scope) {
        return CallArranger.LINUX.arrangeUpcall(target, targetType, function, scope); <----
    }

The reason why the instance method arrangeDowncall/arrangeUpcall is invoked from the Linker on Aarch64 is that a CallArranger instance (namely CallArranger.LINUX for Linux or CallArranger.MACOS for macOS) is already created in CallArranger in advance as the code in CallArranger is shared by Linux and macOS, which is different from the CallArranger on x64. e.g. Linux/x64 in https://github.com/ibmruntimes/openj9-openjdk-jdk20/blob/master/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64Linker.java.

    protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDescriptor function, LinkerOptions options) {
        return CallArranger.arrangeDowncall(inferredMethodType, function, options);
    }

    @Override
    protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType, FunctionDescriptor function, SegmentScope scope) {
        return CallArranger.arrangeUpcall(target, targetType, function, scope);
    }

where there is no CallArranger instance created for Linux or Win on x64 given CallArranger on Linux is different from Windows.

Based on the setting above in OpenJDK, it's correct for the latest changes (already done in 7608d05) in which case non-static arrangeDowncall/arrangeUpcall of CallArranger is only intended for Aarch64 while static arrangeDowncall/arrangeUpcall of CallArranger is intended for x64, Power and zLinux.

@keithc-ca
Copy link
Member

Jenkins compile alinux64 jdk20 depends eclipse-openj9/openj9#16585

@keithc-ca keithc-ca self-assigned this Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.