Skip to content

[GR-65209] Use RuntimeJNIAccessSupport only when JNI is set. #11232

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,9 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
new SubstrateClassInitializationPlugin((SVMHost) aUniverse.hostVM()), this.isStubBasedPluginsSupported(), aProviders);

loader.classLoaderSupport.getClassesToIncludeUnconditionally().forEach(cls -> bb.registerTypeForBaseImage(cls));
PreserveOptionsSupport.registerPreservedClasses(loader.classLoaderSupport);
if (loader.classLoaderSupport.isPreserveMode()) {
PreserveOptionsSupport.registerPreservedClasses(loader.classLoaderSupport);
}

registerEntryPointStubs(entryPoints);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL
.toList();

final RuntimeReflectionSupport reflection = ImageSingletons.lookup(RuntimeReflectionSupport.class);
final RuntimeJNIAccessSupport jni = ImageSingletons.lookup(RuntimeJNIAccessSupport.class);
final RuntimeProxyCreationSupport proxy = ImageSingletons.lookup(RuntimeProxyCreationSupport.class);
final ConfigurationCondition always = ConfigurationCondition.alwaysTrue();

Expand Down Expand Up @@ -178,20 +177,29 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL
proxy.addProxyClass(always, c);
}

jni.register(ConfigurationCondition.alwaysTrue(), c);
try {
for (Method declaredMethod : c.getDeclaredMethods()) {
jni.register(always, false, declaredMethod);
}
for (Constructor<?> declaredConstructor : c.getDeclaredConstructors()) {
jni.register(always, false, declaredConstructor);
}
for (Field declaredField : c.getDeclaredFields()) {
jni.register(always, false, declaredField);
reflection.register(always, false, declaredField);
}
} catch (LinkageError e) {
/* If we can't link we can not register for JNI and reflection */
/* If we can't link we can not register for reflection */
}
if (SubstrateOptions.JNI.getValue()) {
final RuntimeJNIAccessSupport jni = ImageSingletons.lookup(RuntimeJNIAccessSupport.class);
jni.register(always, c);
try {
for (Method declaredMethod : c.getDeclaredMethods()) {
jni.register(always, false, declaredMethod);
}
for (Constructor<?> declaredConstructor : c.getDeclaredConstructors()) {
jni.register(always, false, declaredConstructor);
}
for (Field declaredField : c.getDeclaredFields()) {
jni.register(always, false, declaredField);
}
} catch (LinkageError e) {
/* If we can't link we can not register for JNI and reflection */
}
}

// if we register as unsafe allocated earlier there are build-time
Expand Down