Skip to content

Commit

Permalink
Only require libmanagement_ext if it's actually needed.
Browse files Browse the repository at this point in the history
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: oracle#5119
  • Loading branch information
jerboaa authored and zakkak committed Nov 1, 2022
1 parent bb1b1e6 commit 7662df0
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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.
Expand Down

0 comments on commit 7662df0

Please sign in to comment.