diff --git a/jcl/src/java.base/share/classes/java/lang/Access.java b/jcl/src/java.base/share/classes/java/lang/Access.java
index 56076b869ea..033bd8d5fa7 100644
--- a/jcl/src/java.base/share/classes/java/lang/Access.java
+++ b/jcl/src/java.base/share/classes/java/lang/Access.java
@@ -592,7 +592,7 @@ public PrintStream initialSystemErr() {
/*[ENDIF] JAVA_SPEC_VERSION >= 23 */
public long findNative(ClassLoader loader, String entryName) {
- return ClassLoader.findNative(loader, entryName);
+ return ClassLoader.findNative0(loader, entryName);
}
@Override
diff --git a/jcl/src/java.base/share/classes/java/lang/ClassLoader.java b/jcl/src/java.base/share/classes/java/lang/ClassLoader.java
index 49274f54637..d0c758c0631 100644
--- a/jcl/src/java.base/share/classes/java/lang/ClassLoader.java
+++ b/jcl/src/java.base/share/classes/java/lang/ClassLoader.java
@@ -72,6 +72,10 @@
import jdk.internal.reflect.CallerSensitiveAdapter;
/*[ENDIF] JAVA_SPEC_VERSION >= 18 */
+/*[IF JAVA_SPEC_VERSION >= 24]*/
+import jdk.internal.reflect.Reflection;
+/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
+
/*[IF CRIU_SUPPORT]*/
import openj9.internal.criu.NotCheckpointSafe;
/*[ENDIF] CRIU_SUPPORT*/
@@ -2101,13 +2105,27 @@ static void loadLibrary(Class> caller, String libName) {
}
}
-static long findNative(ClassLoader loader, String entryName) {
+/*[IF JAVA_SPEC_VERSION >= 24]*/
+static long findNative1(ClassLoader loader, String entryName, Class> cls, String javaName) {
+ long address = findNative0(loader, entryName);
+
+ if ((loader != null) && (address != 0)) {
+ Reflection.ensureNativeAccess(cls, cls, javaName, true);
+ }
+
+ return address;
+}
+/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
+
+static long findNative0(ClassLoader loader, String entryName) {
NativeLibraries nativelib;
+
if ((loader == null) || (loader == bootstrapClassLoader)) {
nativelib = BootLoader.getNativeLibraries();
} else {
nativelib = loader.nativelibs;
}
+
return nativelib.find(entryName);
}
/*[ENDIF] JAVA_SPEC_VERSION >= 15 */
diff --git a/runtime/oti/vmconstantpool.xml b/runtime/oti/vmconstantpool.xml
index 1f98a9bdc2c..9d71c0dd48f 100644
--- a/runtime/oti/vmconstantpool.xml
+++ b/runtime/oti/vmconstantpool.xml
@@ -474,7 +474,8 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
-
+
+
diff --git a/runtime/vm/bindnatv.cpp b/runtime/vm/bindnatv.cpp
index 19a68f0dbc0..1eb662bd343 100644
--- a/runtime/vm/bindnatv.cpp
+++ b/runtime/vm/bindnatv.cpp
@@ -1105,17 +1105,32 @@ lookupJNINative(J9VMThread *currentThread, J9NativeLibrary *nativeLibrary, J9Met
#if JAVA_SPEC_VERSION >= 17
if (NULL == nativeLibrary) {
internalAcquireVMAccess(currentThread);
- j9object_t entryName = vm->memoryManagerFunctions->j9gc_createJavaLangString(currentThread, (U_8*)symbolName, strlen(symbolName), 0);
+ J9MemoryManagerFunctions *mmFuncs = vm->memoryManagerFunctions;
+ j9object_t entryName = mmFuncs->j9gc_createJavaLangString(currentThread, (U_8*)symbolName, strlen(symbolName), 0);
if (NULL != entryName) {
- j9object_t classLoaderObject = J9_CLASS_FROM_METHOD(nativeMethod)->classLoader->classLoaderObject;
- J9Method *findNativeMethod = J9VMJAVALANGCLASSLOADER_FINDNATIVE_METHOD(vm);
- UDATA args[] = {(UDATA)classLoaderObject, (UDATA)entryName};
- internalRunStaticMethod(currentThread, findNativeMethod, TRUE, (sizeof(args) / sizeof(UDATA)), args);
- functionAddress = (UDATA*)(*(U_64*)&(currentThread->returnValue));
+#if JAVA_SPEC_VERSION >= 24
+ J9ROMMethod *nativeROMMethod = J9_ROM_METHOD_FROM_RAM_METHOD(nativeMethod);
+ j9object_t javaName = mmFuncs->j9gc_createJavaLangStringWithUTFCache(currentThread, J9ROMMETHOD_NAME(nativeROMMethod));
+ if (NULL != javaName)
+#endif /* JAVA_SPEC_VERSION >= 24 */
+ {
+ J9Class *nativeMethodCls = J9_CLASS_FROM_METHOD(nativeMethod);
+ j9object_t classLoaderObject = nativeMethodCls->classLoader->classLoaderObject;
+#if JAVA_SPEC_VERSION >= 24
+ j9object_t classObject = nativeMethodCls->classObject;
+ J9Method *findNativeMethod = J9VMJAVALANGCLASSLOADER_FINDNATIVE1_METHOD(vm);
+ UDATA args[] = {(UDATA)classLoaderObject, (UDATA)entryName, (UDATA)classObject, (UDATA)javaName};
+#else /* JAVA_SPEC_VERSION >= 24 */
+ J9Method *findNativeMethod = J9VMJAVALANGCLASSLOADER_FINDNATIVE0_METHOD(vm);
+ UDATA args[] = {(UDATA)classLoaderObject, (UDATA)entryName};
+#endif /* JAVA_SPEC_VERSION >= 24 */
+ internalRunStaticMethod(currentThread, findNativeMethod, TRUE, (sizeof(args) / sizeof(UDATA)), args);
+ functionAddress = (UDATA*)(*(U_64*)&(currentThread->returnValue));
#if defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT)
- doSwitching = ((UDATA)functionAddress) & J9_NATIVE_LIBRARY_SWITCH_MASK;
- functionAddress = (UDATA *)(((UDATA)functionAddress) & ~(UDATA)J9_NATIVE_LIBRARY_SWITCH_MASK);
+ doSwitching = ((UDATA)functionAddress) & J9_NATIVE_LIBRARY_SWITCH_MASK;
+ functionAddress = (UDATA *)(((UDATA)functionAddress) & ~(UDATA)J9_NATIVE_LIBRARY_SWITCH_MASK);
#endif /* defined(J9VM_OPT_JAVA_OFFLOAD_SUPPORT) */
+ }
}
/* always clear pending exception, might retry later */
VM_VMHelpers::clearException(currentThread);