From 7662df010649091d6598912cc7c8cc521c154455 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 29 Sep 2022 18:38:37 +0200 Subject: [PATCH] Only require libmanagement_ext if it's actually needed. On some systems/apps, libawt_headless gets pulled in. This currently brings in libmanagement_ext unconditionally. However, libmanagement_ext should only be present for linking iff com.sun.management.internal.OperatingSystemImpl class becomes reachable. Closes: #5119 --- .../svm/hosted/jdk/JNIRegistrationManagementExt.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationManagementExt.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationManagementExt.java index 90dc6d3ca7d7..c7af55bb1e1d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationManagementExt.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationManagementExt.java @@ -43,15 +43,17 @@ @AutomaticallyRegisteredFeature public class JNIRegistrationManagementExt extends JNIRegistrationUtil implements InternalFeature { + + private static final String OPERATING_SYSTEM_IMPL = "com.sun.management.internal.OperatingSystemImpl"; private NativeLibraries nativeLibraries; @Override public void beforeAnalysis(BeforeAnalysisAccess access) { nativeLibraries = ((BeforeAnalysisAccessImpl) access).getNativeLibraries(); - rerunClassInit(access, "com.sun.management.internal.OperatingSystemImpl"); + rerunClassInit(access, OPERATING_SYSTEM_IMPL); - access.registerReachabilityHandler(this::linkManagementExt, clazz(access, "com.sun.management.internal.OperatingSystemImpl")); + access.registerReachabilityHandler(this::linkManagementExt, clazz(access, OPERATING_SYSTEM_IMPL)); PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("com_sun_management_internal_OperatingSystemImpl"); } @@ -77,7 +79,8 @@ private void linkManagementExt(@SuppressWarnings("unused") DuringAnalysisAccess @Override public void afterAnalysis(AfterAnalysisAccess access) { - if (NativeLibrarySupport.singleton().isPreregisteredBuiltinLibrary("awt_headless")) { + boolean managementExtNeeded = access.isReachable(clazz(access, OPERATING_SYSTEM_IMPL)); + if (managementExtNeeded && NativeLibrarySupport.singleton().isPreregisteredBuiltinLibrary("awt_headless")) { /* * Ensure that `management_ext` comes before `awt_headless` on the linker command line. * This is necessary to prevent linker errors such as JDK-8264047.