Skip to content

Commit c8d83d3

Browse files
committed
[GR-65209] Use RuntimeJNIAccessSupport only when JNI is set.
PullRequest: graal/20867
2 parents 87bfe1c + 33b728b commit c8d83d3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,9 @@ protected void setupNativeImage(String imageName, OptionValues options, Map<Meth
11121112
new SubstrateClassInitializationPlugin(hostVM), this.isStubBasedPluginsSupported(), aProviders);
11131113

11141114
loader.classLoaderSupport.getClassesToIncludeUnconditionally().forEach(cls -> bb.registerTypeForBaseImage(cls));
1115-
PreserveOptionsSupport.registerPreservedClasses(loader.classLoaderSupport);
1115+
if (loader.classLoaderSupport.isPreserveMode()) {
1116+
PreserveOptionsSupport.registerPreservedClasses(loader.classLoaderSupport);
1117+
}
11161118

11171119
registerEntryPointStubs(entryPoints);
11181120
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/PreserveOptionsSupport.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL
150150
.toList();
151151

152152
final RuntimeReflectionSupport reflection = ImageSingletons.lookup(RuntimeReflectionSupport.class);
153-
final RuntimeJNIAccessSupport jni = ImageSingletons.lookup(RuntimeJNIAccessSupport.class);
154153
final RuntimeProxyCreationSupport proxy = ImageSingletons.lookup(RuntimeProxyCreationSupport.class);
155154
final ConfigurationCondition always = ConfigurationCondition.alwaysTrue();
156155

@@ -178,20 +177,29 @@ public static void registerPreservedClasses(NativeImageClassLoaderSupport classL
178177
proxy.addProxyClass(always, c);
179178
}
180179

181-
jni.register(ConfigurationCondition.alwaysTrue(), c);
182180
try {
183-
for (Method declaredMethod : c.getDeclaredMethods()) {
184-
jni.register(always, false, declaredMethod);
185-
}
186-
for (Constructor<?> declaredConstructor : c.getDeclaredConstructors()) {
187-
jni.register(always, false, declaredConstructor);
188-
}
189181
for (Field declaredField : c.getDeclaredFields()) {
190-
jni.register(always, false, declaredField);
191182
reflection.register(always, false, declaredField);
192183
}
193184
} catch (LinkageError e) {
194-
/* If we can't link we can not register for JNI and reflection */
185+
/* If we can't link we can not register for reflection */
186+
}
187+
if (SubstrateOptions.JNI.getValue()) {
188+
final RuntimeJNIAccessSupport jni = ImageSingletons.lookup(RuntimeJNIAccessSupport.class);
189+
jni.register(always, c);
190+
try {
191+
for (Method declaredMethod : c.getDeclaredMethods()) {
192+
jni.register(always, false, declaredMethod);
193+
}
194+
for (Constructor<?> declaredConstructor : c.getDeclaredConstructors()) {
195+
jni.register(always, false, declaredConstructor);
196+
}
197+
for (Field declaredField : c.getDeclaredFields()) {
198+
jni.register(always, false, declaredField);
199+
}
200+
} catch (LinkageError e) {
201+
/* If we can't link we can not register for JNI and reflection */
202+
}
195203
}
196204

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

0 commit comments

Comments
 (0)