From d05444465f798a53775c13e0ff64959da2b5daf4 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 21 Mar 2023 10:13:32 +0100 Subject: [PATCH] Avoid emitting `rmi` library. It is not needed as it only provides an implementation for `maxObjectInspectionAge()`, which is substituted in SVM. --- .../core/jdk/Target_sun_rmi_transport_GC.java | 12 ++++++++- .../hosted/jdk/JDKInitializationFeature.java | 2 ++ .../svm/hosted/jdk/JmxClientFeature.java | 25 ++++--------------- .../svm/hosted/jdk/JmxCommonFeature.java | 1 - 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_rmi_transport_GC.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_rmi_transport_GC.java index 6436feb1b700..73eef6313ea5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_rmi_transport_GC.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_rmi_transport_GC.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -26,12 +26,22 @@ package com.oracle.svm.core.jdk; +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.heap.Heap; +/** + * Note that sun.rmi.transport.GC is initialized at build-time to avoid including the rmi library, + * which is not needed as it only implements the native maxObjectInspectionAge() method, which in + * turn is {@link Target_sun_rmi_transport_GC#maxObjectInspectionAge substituted in here}. + */ @TargetClass(className = "sun.rmi.transport.GC") final class Target_sun_rmi_transport_GC { + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset)// + private static Thread daemon = null; + @Substitute public static long maxObjectInspectionAge() { return Heap.getHeap().getMillisSinceLastWholeHeapExamined(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java index 30b2a94a9541..e5f4d9947207 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JDKInitializationFeature.java @@ -159,6 +159,8 @@ public void afterRegistration(AfterRegistrationAccess access) { rci.initializeAtBuildTime("apple.security", JDK_CLASS_REASON); } + rci.initializeAtBuildTime("sun.rmi.transport.GC", "Loaded an unneeded library (rmi) in static initializer."); + rci.rerunInitialization("com.sun.jndi.dns.DnsClient", "Contains Random references, therefore can't be included in the image heap."); rci.rerunInitialization("sun.net.www.protocol.http.DigestAuthentication$Parameters", "Contains Random references, therefore can't be included in the image heap."); rci.rerunInitialization("sun.security.krb5.KrbServiceLocator", "Contains Random references, therefore can't be included in the image heap."); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java index 3889021e42b8..86431033db23 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -25,18 +25,14 @@ */ package com.oracle.svm.hosted.jdk; -import com.oracle.svm.core.feature.InternalFeature; import org.graalvm.nativeimage.hosted.RuntimeReflection; +import com.oracle.svm.core.VMInspectionOptions; +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; +import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.jdk.JNIRegistrationUtil; -import com.oracle.svm.core.util.VMError; - -import com.oracle.svm.core.jdk.NativeLibrarySupport; -import com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl; -import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport; import com.oracle.svm.core.jni.JNIRuntimeAccess; -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; -import com.oracle.svm.core.VMInspectionOptions; +import com.oracle.svm.core.util.VMError; import com.oracle.svm.util.ReflectionUtil; @AutomaticallyRegisteredFeature @@ -46,22 +42,11 @@ public boolean isInConfiguration(IsInConfigurationAccess access) { return VMInspectionOptions.hasJmxClientSupport(); } - private static void handleNativeLibraries(BeforeAnalysisAccess access) { - BeforeAnalysisAccessImpl a = (BeforeAnalysisAccessImpl) access; - NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("rmi"); - a.getNativeLibraries().addStaticJniLibrary("rmi"); - - // Resolve calls to sun_rmi_transport* as builtIn. For calls to native method - // maxObjectInspectionAge() - PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_rmi_transport"); - } - @Override public void beforeAnalysis(BeforeAnalysisAccess access) { try { configureJNI(); configureReflection(access); - handleNativeLibraries(access); } catch (Exception e) { throw VMError.shouldNotReachHere("ManagementClientFeature configuration failed: " + e); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxCommonFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxCommonFeature.java index 3e152c3ac53e..d61e319fba95 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxCommonFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxCommonFeature.java @@ -94,7 +94,6 @@ public void afterRegistration(AfterRegistrationAccess access) { rci.initializeAtRunTime("com.sun.jmx.remote.security.JMXPluggableAuthenticator$FileLoginConfig", "JMX support"); rci.initializeAtRunTime("sun.rmi.transport.DGCImpl", "JMX support"); rci.initializeAtRunTime("sun.rmi.transport.DGCAckHandler", "JMX support"); - rci.initializeAtRunTime("sun.rmi.transport.GC", "JMX support"); rci.initializeAtRunTime("sun.rmi.transport.DGCClient", "JMX support"); rci.initializeAtRunTime("sun.rmi.transport.ObjectTable", "JMX support"); rci.initializeAtRunTime("sun.rmi.transport.tcp.TCPEndpoint", "JMX support");