From 2e39007bf852a34017daa075d8601434d75b1c6f Mon Sep 17 00:00:00 2001 From: Cheng Jin Date: Wed, 31 Aug 2022 12:32:15 -0400 Subject: [PATCH] [JEP424] Enable FFI Upcall on s390x/Aarch64/x86 in JDK19 The changes aim to enable the Linker's upcall handler to support primitives and struct by replacing UpcallLinker with the equivalent implemented in OpenJ9 on s390x, Aarch64 and x86. Signed-off-by: Cheng Jin --- .../jdk/internal/foreign/abi/aarch64/CallArranger.java | 2 +- .../jdk/internal/foreign/abi/s390x/sysv/CallArranger.java | 2 +- .../jdk/internal/foreign/abi/x64/sysv/CallArranger.java | 2 +- .../jdk/internal/foreign/abi/x64/windows/CallArranger.java | 2 +- .../share/classes/jdk/internal/loader/NativeLibraries.java | 7 ++++++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java index bf6e700067a..5cee3e2aaef 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java @@ -164,7 +164,7 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe /* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */ public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) { - throw new InternalError("arrangeUpcall is not yet implemented"); //$NON-NLS-1$ + return UpcallLinker.make(target, mt, cDesc, session); } private static boolean isInMemoryReturn(Optional returnLayout) { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/CallArranger.java index eb23f9e5266..2aa3e4d281e 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/s390x/sysv/CallArranger.java @@ -55,6 +55,6 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe /* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */ public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) { - throw new InternalError("arrangeUpcall is not yet implemented"); //$NON-NLS-1$ + return UpcallLinker.make(target, mt, cDesc, session); } } diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java index 9e7a0ed6008..d45c36cf1e3 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java @@ -133,7 +133,7 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe /* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */ public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) { - throw new InternalError("arrangeUpcall is not yet implemented"); //$NON-NLS-1$ + return UpcallLinker.make(target, mt, cDesc, session); } private static boolean isInMemoryReturn(Optional returnLayout) { diff --git a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java index 33a59a31abb..342abcfde43 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java +++ b/src/java.base/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java @@ -136,7 +136,7 @@ public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDe /* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */ public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) { - throw new InternalError("arrangeUpcall is not yet implemented"); //$NON-NLS-1$ + return UpcallLinker.make(target, mt, cDesc, session); } private static boolean isInMemoryReturn(Optional returnLayout) { diff --git a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java index 44d44c28dd9..80eaafc9730 100644 --- a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java +++ b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java @@ -355,7 +355,12 @@ boolean open() { @Override public long find(String name) { - return NativeLibraries.findEntryInProcess(name); + boolean isAixOS = System.getProperty("os.name").toLowerCase().contains("aix"); + if (isAixOS) { + return NativeLibraries.findEntryInProcess(name); + } else { + throw new UnsupportedOperationException("Cannot find on non-AIX platforms"); + } } };