Skip to content

Commit ea9046a

Browse files
committed
Register layered AWT JNI access before analysis
1 parent 87d1985 commit ea9046a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
@AutomaticallyRegisteredFeature
4848
public class JNIRegistrationAWTSupport extends JNIRegistrationUtil implements InternalFeature {
4949
private ResolvedJavaMethod systemLoadMethod;
50+
private boolean headlessJavaDesktopSupportRegistered;
5051

5152
@Override
5253
public void beforeAnalysis(BeforeAnalysisAccess access) {
@@ -56,16 +57,15 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
5657
}
5758
if (isLinux() || isDarwin()) {
5859
JNIRegistrationSupport.singleton().addLibraryRegistrationHandler(this::registerHeadlessJavaDesktopSupport);
60+
if (JNIRegistrationSupport.singleton().isPreviousLayerRegisteredLibrary("awt")) {
61+
registerHeadlessJavaDesktopSupport("awt");
62+
}
5963
}
6064
}
6165

6266
@Override
6367
public void afterAnalysis(AfterAnalysisAccess access) {
6468
JNIRegistrationSupport jniRegistrationSupport = JNIRegistrationSupport.singleton();
65-
if ((isLinux() || isDarwin()) && jniRegistrationSupport.isPreviousLayerRegisteredLibrary("awt") &&
66-
!jniRegistrationSupport.isCurrentLayerRegisteredLibrary("awt")) {
67-
registerHeadlessJavaDesktopSupport("awt");
68-
}
6969
if (jniRegistrationSupport.isAnyLayerRegisteredLibrary("awt")) {
7070
jniRegistrationSupport.addJvmShimExports(
7171
"JVM_IsStaticallyLinked");
@@ -166,9 +166,10 @@ private static void registerDarwinBuiltinPkgNatives() {
166166
}
167167

168168
private void registerHeadlessJavaDesktopSupport(String libname) {
169-
if (!"awt".equals(libname)) {
169+
if (!"awt".equals(libname) || headlessJavaDesktopSupportRegistered) {
170170
return;
171171
}
172+
headlessJavaDesktopSupportRegistered = true;
172173
JVMCIRuntimeJNIAccess.register(systemLoadMethod);
173174
if (isDarwin()) {
174175
NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("awt");

0 commit comments

Comments
 (0)