Skip to content

Commit 675b69b

Browse files
committed
[GR-35914] Reduce module dependencies of the native image generator.
PullRequest: graal/14684
2 parents 4d9fe29 + 0ed02af commit 675b69b

29 files changed

+360
-255
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@
183183
"sdk:GRAAL_SDK",
184184
"compiler:GRAAL",
185185
],
186-
"requires" : [
187-
"java.instrument",
188-
],
189186
"requiresConcealed" : {
190187
"java.base" : ["jdk.internal.module"],
191188
},
@@ -244,13 +241,9 @@
244241
],
245242
"requires" : [
246243
"java.compiler",
247-
"java.logging",
248-
"java.scripting",
249-
"jdk.httpserver",
250244
"jdk.jfr",
251245
"jdk.management",
252246
"jdk.management.jfr",
253-
"jdk.unsupported",
254247
],
255248
"requiresConcealed" : {
256249
"java.base" : [
@@ -293,9 +286,6 @@
293286
"jdk.management.agent": [
294287
"jdk.internal.agent",
295288
],
296-
"jdk.httpserver@19+": [
297-
"sun.net.httpserver.simpleserver",
298-
],
299289
"jdk.jfr": [
300290
"jdk.jfr.events",
301291
"jdk.jfr.internal",
@@ -536,9 +526,6 @@
536526
"dependencies": [
537527
"com.oracle.graal.pointsto",
538528
],
539-
"requires" : [
540-
"jdk.unsupported" # sun.misc.Unsafe
541-
],
542529
"requiresConcealed" : {
543530
"java.base" : [
544531
"jdk.internal.misc"
@@ -613,13 +600,8 @@
613600
"com.oracle.graal.reachability"
614601
],
615602
"requires" : [
616-
"java.instrument",
617-
"java.security.sasl",
618-
"java.smartcardio",
619-
"java.xml.crypto",
620603
"jdk.jfr",
621604
"jdk.management",
622-
"jdk.unsupported",
623605
],
624606
"requiresConcealed" : {
625607
"java.base" : [
@@ -647,9 +629,6 @@
647629
"com.sun.jmx.mbeanserver", # Needed for javadoc links (MXBeanIntrospector,DefaultMXBeanMappingFactory, MXBeanProxy)
648630
"sun.management", # Needed for javadoc links (MappedMXBeanType)
649631
],
650-
"java.rmi": [
651-
"sun.rmi.server", # Needed for javadoc links (UnicastRef, UnicastRef2)
652-
],
653632
"jdk.internal.vm.ci" : [
654633
"jdk.vm.ci.meta",
655634
"jdk.vm.ci.code",
@@ -664,11 +643,6 @@
664643
"jdk.jfr.internal",
665644
"jdk.jfr.internal.jfc",
666645
],
667-
"java.management.rmi": [
668-
"com.sun.jmx.remote.internal.rmi", # Needed for javadoc links (ProxyRef)
669-
"com.sun.jmx.remote.protocol.rmi", # Needed for javadoc links (ClientProvider, ServerProvider)
670-
"javax.management.remote.rmi", # Needed for javadoc links (RMIServer, RMIServerImpl_Stub, RMIConnection, RMIConnectionImpl_Stub)
671-
],
672646
},
673647
"javaCompliance" : "17+",
674648
"checkstyleVersion": "10.7.0",
@@ -997,10 +971,7 @@
997971
"subDir": "src",
998972
"sourceDirs": ["src"],
999973
"dependencies": [
1000-
"com.oracle.svm.core",
1001-
],
1002-
"requires" : [
1003-
"jdk.unsupported",
974+
"com.oracle.svm.util",
1004975
],
1005976
"checkstyle": "com.oracle.svm.core",
1006977
"javaCompliance" : "17+",
@@ -1281,9 +1252,6 @@
12811252
"dependencies": [
12821253
"com.oracle.svm.hosted",
12831254
],
1284-
"requires" : [
1285-
"jdk.unsupported",
1286-
],
12871255
"requiresConcealed": {
12881256
"jdk.internal.vm.ci": [
12891257
"jdk.vm.ci.meta",
@@ -1359,12 +1327,6 @@
13591327
"requires": [
13601328
"java.management",
13611329
"jdk.management",
1362-
"java.xml.crypto",
1363-
"java.security.sasl",
1364-
"java.smartcardio",
1365-
"java.net.http",
1366-
"jdk.sctp",
1367-
"jdk.scripting.nashorn@11..14",
13681330
"jdk.management.agent",
13691331
"jdk.management.jfr",
13701332
],
@@ -1416,9 +1378,6 @@
14161378
"java.management": [
14171379
"sun.management",
14181380
],
1419-
"java.xml.crypto": [
1420-
"org.jcp.xml.dsig.internal.dom",
1421-
],
14221381
},
14231382
},
14241383
"noMavenJavadoc": True,

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ private static void raise0(int signalNumber) {
8080
}
8181

8282
/**
83-
* Called by the VM to execute Java signal handlers. Except that in sun.misc.Signal, this method
84-
* is private.
83+
* Called by the VM to execute Java signal handlers. Except that in jdk.internal.misc.Signal,
84+
* this method is private.
8585
*/
8686
@Alias
8787
static native void dispatch(int number);
8888
}
8989

90-
/** Support for Target_sun_misc_Signal. */
90+
/** Support for Target_jdk_internal_misc_Signal. */
9191
final class Util_jdk_internal_misc_Signal {
9292

9393
/** A thread to dispatch signals as they are raised. */
@@ -105,7 +105,7 @@ private Util_jdk_internal_misc_Signal() {
105105
/* All-static class. */
106106
}
107107

108-
/** Constants for the longs from sun.misc.Signal. */
108+
/** Constants for the longs from jdk.internal.misc.Signal. */
109109
private static final long sunMiscSignalDefaultHandler = 0;
110110
private static final long sunMiscSignalIgnoreHandler = 1;
111111
private static final long sunMiscSignalDispatchHandler = 2;
@@ -182,9 +182,9 @@ private static void ensureInitialized() throws IllegalArgumentException {
182182
throw new IllegalArgumentException("C signal handling mechanism is in use.");
183183
}
184184
/* Report other failure. */
185-
Log.log().string("Util_sun_misc_Signal.ensureInitialized: CSunMiscSignal.create() failed.")
185+
Log.log().string("Util_jdk_internal_misc_Signal.ensureInitialized: CSunMiscSignal.create() failed.")
186186
.string(" errno: ").signed(openErrno).string(" ").string(Errno.strerror(openErrno)).newline();
187-
throw VMError.shouldNotReachHere("Util_sun_misc_Signal.ensureInitialized: CSunMiscSignal.open() failed.");
187+
throw VMError.shouldNotReachHere("Util_jdk_internal_misc_Signal.ensureInitialized: CSunMiscSignal.open() failed.");
188188
}
189189

190190
/* Initialize the table of signal states. */
@@ -240,7 +240,7 @@ protected static int numberFromName(String javaSignalName) {
240240
return entry.getNumber();
241241
}
242242
}
243-
/* {@link sun.misc.Signal#findSignal(String)} expects a -1 on failure. */
243+
/* {@link jdk.internal.misc.Signal#findSignal(String)} expects a -1 on failure. */
244244
return -1;
245245
}
246246

@@ -377,12 +377,12 @@ protected void setDispatcher(Signal.SignalDispatcher value) {
377377

378378
protected static void await() {
379379
final int awaitResult = CSunMiscSignal.await();
380-
PosixUtils.checkStatusIs0(awaitResult, "Util_sun_misc_Signal.SignalState.await(): CSunMiscSignal.await() failed.");
380+
PosixUtils.checkStatusIs0(awaitResult, "Util_jdk_internal_misc_Signal.SignalState.await(): CSunMiscSignal.await() failed.");
381381
}
382382

383383
protected static void wakeUp() {
384384
final int awaitResult = CSunMiscSignal.post();
385-
PosixUtils.checkStatusIs0(awaitResult, "Util_sun_misc_Signal.SignalState.post(): CSunMiscSignal.post() failed.");
385+
PosixUtils.checkStatusIs0(awaitResult, "Util_jdk_internal_misc_Signal.SignalState.post(): CSunMiscSignal.post() failed.");
386386
}
387387

388388
/*

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpHeapOnSignalFeature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import com.oracle.svm.core.jdk.RuntimeSupport;
3939
import com.oracle.svm.core.log.Log;
4040

41-
import sun.misc.Signal;
42-
import sun.misc.SignalHandler;
41+
import jdk.internal.misc.Signal;
4342

4443
@AutomaticallyRegisteredFeature
4544
public class DumpHeapOnSignalFeature implements InternalFeature {
@@ -64,7 +63,7 @@ public void execute(boolean isFirstIsolate) {
6463
}
6564
}
6665

67-
class DumpHeapReport implements SignalHandler {
66+
class DumpHeapReport implements Signal.Handler {
6867
private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC");
6968

7069
static void install() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpRuntimeCompilationOnSignalFeature.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727
import org.graalvm.nativeimage.Platform;
2828
import org.graalvm.nativeimage.Platform.WINDOWS;
2929

30+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3031
import com.oracle.svm.core.feature.InternalFeature;
3132
import com.oracle.svm.core.graal.RuntimeCompilation;
3233
import com.oracle.svm.core.heap.VMOperationInfos;
3334
import com.oracle.svm.core.jdk.RuntimeSupport;
3435
import com.oracle.svm.core.log.Log;
3536
import com.oracle.svm.core.thread.JavaVMOperation;
36-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3737

38-
import sun.misc.Signal;
39-
import sun.misc.SignalHandler;
38+
import jdk.internal.misc.Signal;
4039

4140
@AutomaticallyRegisteredFeature
4241
public class DumpRuntimeCompilationOnSignalFeature implements InternalFeature {
@@ -61,7 +60,7 @@ public void execute(boolean isFirstIsolate) {
6160
}
6261
}
6362

64-
class DumpRuntimeCompilation implements SignalHandler {
63+
class DumpRuntimeCompilation implements Signal.Handler {
6564
static void install() {
6665
Signal.handle(new Signal("USR2"), new DumpRuntimeCompilation());
6766
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/DumpThreadStacksOnSignalFeature.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.graalvm.nativeimage.Platform;
3030
import org.graalvm.nativeimage.Platform.WINDOWS;
3131

32+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3233
import com.oracle.svm.core.feature.InternalFeature;
3334
import com.oracle.svm.core.heap.VMOperationInfos;
3435
import com.oracle.svm.core.jdk.RuntimeSupport;
@@ -39,10 +40,8 @@
3940
import com.oracle.svm.core.thread.JavaVMOperation;
4041
import com.oracle.svm.core.thread.PlatformThreads;
4142
import com.oracle.svm.core.thread.VMThreads;
42-
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
4343

44-
import sun.misc.Signal;
45-
import sun.misc.SignalHandler;
44+
import jdk.internal.misc.Signal;
4645

4746
@AutomaticallyRegisteredFeature
4847
public class DumpThreadStacksOnSignalFeature implements InternalFeature {
@@ -67,7 +66,7 @@ public void execute(boolean isFirstIsolate) {
6766
}
6867
}
6968

70-
class DumpAllStacks implements SignalHandler {
69+
class DumpAllStacks implements Signal.Handler {
7170
static void install() {
7271
Signal.handle(Platform.includedIn(WINDOWS.class) ? new Signal("BREAK") : new Signal("QUIT"), new DumpAllStacks());
7372
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ private static void validateUseOldDebugInfo(HostedOptionKey<Boolean> optionKey)
676676
@Option(help = "Directory under which to create source file cache for Application or GraalVM classes")//
677677
public static final HostedOptionKey<String> DebugInfoSourceCacheRoot = new HostedOptionKey<>("sources");
678678

679+
@Option(help = "Temporary option to disable checking of image builder module dependencies or increasing its verbosity", type = OptionType.Debug)//
680+
public static final HostedOptionKey<Integer> CheckBootModuleDependencies = new HostedOptionKey<>(ModuleSupport.modulePathBuild ? 1 : 0);
681+
679682
public static Path getDebugInfoSourceCacheRoot() {
680683
try {
681684
return Paths.get(Path.getValue()).resolve(DebugInfoSourceCacheRoot.getValue());

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474

7575
import org.graalvm.compiler.core.common.NumUtil;
7676
import org.graalvm.compiler.core.common.SuppressFBWarnings;
77-
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
7877
import org.graalvm.nativeimage.AnnotationAccess;
7978
import org.graalvm.nativeimage.ImageSingletons;
8079
import org.graalvm.nativeimage.Platform;
@@ -1932,20 +1931,20 @@ final class Target_java_lang_Class_Atomic {
19321931
static <T> boolean casReflectionData(DynamicHub clazz,
19331932
SoftReference<Target_java_lang_Class_ReflectionData<T>> oldData,
19341933
SoftReference<Target_java_lang_Class_ReflectionData<T>> newData) {
1935-
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), reflectionDataOffset, oldData, newData);
1934+
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), reflectionDataOffset, oldData, newData);
19361935
}
19371936

19381937
@Substitute
19391938
static boolean casAnnotationType(DynamicHub clazz,
19401939
AnnotationType oldType,
19411940
AnnotationType newType) {
1942-
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), annotationTypeOffset, oldType, newType);
1941+
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), annotationTypeOffset, oldType, newType);
19431942
}
19441943

19451944
@Substitute
19461945
static boolean casAnnotationData(DynamicHub clazz,
19471946
Target_java_lang_Class_AnnotationData oldData,
19481947
Target_java_lang_Class_AnnotationData newData) {
1949-
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), annotationDataOffset, oldData, newData);
1948+
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), annotationDataOffset, oldData, newData);
19501949
}
19511950
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ protected static Optional<Class<?>> optionalClazz(FeatureAccess access, String c
8484
}
8585

8686
protected static Optional<Method> optionalMethod(FeatureAccess access, String className, String methodName, Class<?>... parameterTypes) {
87-
return Optional.ofNullable(ReflectionUtil.lookupMethod(true, clazz(access, className), methodName, parameterTypes));
87+
return optionalClazz(access, className)
88+
.flatMap(clazz -> Optional.ofNullable(ReflectionUtil.lookupMethod(true, clazz, methodName, parameterTypes)));
8889
}
8990

9091
protected static Method method(FeatureAccess access, String className, String methodName, Class<?>... parameterTypes) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetHttpFeature.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,35 @@
2424
*/
2525
package com.oracle.svm.core.jdk;
2626

27+
import java.util.Optional;
28+
2729
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
2830
import org.graalvm.nativeimage.ImageSingletons;
2931
import org.graalvm.nativeimage.hosted.RuntimeReflection;
3032
import org.graalvm.nativeimage.impl.ConfigurationCondition;
3133
import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport;
3234

3335
import com.oracle.svm.core.configure.ResourcesRegistry;
34-
import com.oracle.svm.core.feature.InternalFeature;
3536
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
37+
import com.oracle.svm.core.feature.InternalFeature;
3638

3739
@AutomaticallyRegisteredFeature
3840
public class JavaNetHttpFeature extends JNIRegistrationUtil implements InternalFeature {
3941

42+
private static Optional<Module> requiredModule() {
43+
return ModuleLayer.boot().findModule("java.net.http");
44+
}
45+
46+
@Override
47+
public boolean isInConfiguration(IsInConfigurationAccess access) {
48+
return requiredModule().isPresent();
49+
}
50+
51+
@Override
52+
public void afterRegistration(AfterRegistrationAccess access) {
53+
JavaNetHttpFeature.class.getModule().addReads(requiredModule().get());
54+
}
55+
4056
@Override
4157
public void duringSetup(DuringSetupAccess access) {
4258
RuntimeClassInitializationSupport rci = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
@@ -59,13 +75,19 @@ private static void registerInitFiltersAccess(DuringAnalysisAccess a) {
5975
@AutomaticallyRegisteredFeature
6076
class SimpleWebServerFeature implements InternalFeature {
6177

78+
private static Optional<Module> requiredModule() {
79+
return ModuleLayer.boot().findModule("jdk.httpserver");
80+
}
81+
6282
@Override
6383
public boolean isInConfiguration(IsInConfigurationAccess access) {
64-
return JavaVersionUtil.JAVA_SPEC >= 19;
84+
return JavaVersionUtil.JAVA_SPEC >= 19 && requiredModule().isPresent();
6585
}
6686

6787
@Override
6888
public void afterRegistration(AfterRegistrationAccess access) {
89+
SimpleWebServerFeature.class.getModule().addReads(requiredModule().get());
90+
6991
RuntimeClassInitializationSupport rci = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
7092
rci.initializeAtRunTime("sun.net.httpserver.simpleserver.SimpleFileServerImpl", "Allocates InetAddress in class initializer");
7193
}

0 commit comments

Comments
 (0)