Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-35914] Reduce module dependencies of the native image generator. #6807

Merged
merged 12 commits into from
Jun 20, 2023
43 changes: 1 addition & 42 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@
"sdk:GRAAL_SDK",
"compiler:GRAAL",
],
"requires" : [
"java.instrument",
],
"requiresConcealed" : {
"java.base" : ["jdk.internal.module"],
},
Expand Down Expand Up @@ -244,13 +241,9 @@
],
"requires" : [
"java.compiler",
"java.logging",
"java.scripting",
"jdk.httpserver",
"jdk.jfr",
"jdk.management",
"jdk.management.jfr",
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
Expand Down Expand Up @@ -293,9 +286,6 @@
"jdk.management.agent": [
"jdk.internal.agent",
],
"jdk.httpserver@19+": [
"sun.net.httpserver.simpleserver",
],
"jdk.jfr": [
"jdk.jfr.events",
"jdk.jfr.internal",
Expand Down Expand Up @@ -536,9 +526,6 @@
"dependencies": [
"com.oracle.graal.pointsto",
],
"requires" : [
"jdk.unsupported" # sun.misc.Unsafe
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc"
Expand Down Expand Up @@ -613,13 +600,8 @@
"com.oracle.graal.reachability"
],
"requires" : [
"java.instrument",
"java.security.sasl",
"java.smartcardio",
"java.xml.crypto",
"jdk.jfr",
"jdk.management",
"jdk.unsupported",
],
"requiresConcealed" : {
"java.base" : [
Expand Down Expand Up @@ -647,9 +629,6 @@
"com.sun.jmx.mbeanserver", # Needed for javadoc links (MXBeanIntrospector,DefaultMXBeanMappingFactory, MXBeanProxy)
"sun.management", # Needed for javadoc links (MappedMXBeanType)
],
"java.rmi": [
"sun.rmi.server", # Needed for javadoc links (UnicastRef, UnicastRef2)
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.meta",
"jdk.vm.ci.code",
Expand All @@ -664,11 +643,6 @@
"jdk.jfr.internal",
"jdk.jfr.internal.jfc",
],
"java.management.rmi": [
"com.sun.jmx.remote.internal.rmi", # Needed for javadoc links (ProxyRef)
"com.sun.jmx.remote.protocol.rmi", # Needed for javadoc links (ClientProvider, ServerProvider)
"javax.management.remote.rmi", # Needed for javadoc links (RMIServer, RMIServerImpl_Stub, RMIConnection, RMIConnectionImpl_Stub)
],
},
"javaCompliance" : "17+",
"checkstyleVersion": "10.7.0",
Expand Down Expand Up @@ -997,10 +971,7 @@
"subDir": "src",
"sourceDirs": ["src"],
"dependencies": [
"com.oracle.svm.core",
],
"requires" : [
"jdk.unsupported",
"com.oracle.svm.util",
],
"checkstyle": "com.oracle.svm.core",
"javaCompliance" : "17+",
Expand Down Expand Up @@ -1281,9 +1252,6 @@
"dependencies": [
"com.oracle.svm.hosted",
],
"requires" : [
"jdk.unsupported",
],
"requiresConcealed": {
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
Expand Down Expand Up @@ -1359,12 +1327,6 @@
"requires": [
"java.management",
"jdk.management",
"java.xml.crypto",
"java.security.sasl",
"java.smartcardio",
"java.net.http",
"jdk.sctp",
"jdk.scripting.nashorn@11..14",
"jdk.management.agent",
"jdk.management.jfr",
],
Expand Down Expand Up @@ -1416,9 +1378,6 @@
"java.management": [
"sun.management",
],
"java.xml.crypto": [
"org.jcp.xml.dsig.internal.dom",
],
},
},
"noMavenJavadoc": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ private static void raise0(int signalNumber) {
}

/**
* Called by the VM to execute Java signal handlers. Except that in sun.misc.Signal, this method
* is private.
* Called by the VM to execute Java signal handlers. Except that in jdk.internal.misc.Signal,
* this method is private.
*/
@Alias
static native void dispatch(int number);
}

/** Support for Target_sun_misc_Signal. */
/** Support for Target_jdk_internal_misc_Signal. */
final class Util_jdk_internal_misc_Signal {

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

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

/* Initialize the table of signal states. */
Expand Down Expand Up @@ -240,7 +240,7 @@ protected static int numberFromName(String javaSignalName) {
return entry.getNumber();
}
}
/* {@link sun.misc.Signal#findSignal(String)} expects a -1 on failure. */
/* {@link jdk.internal.misc.Signal#findSignal(String)} expects a -1 on failure. */
return -1;
}

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

protected static void await() {
final int awaitResult = CSunMiscSignal.await();
PosixUtils.checkStatusIs0(awaitResult, "Util_sun_misc_Signal.SignalState.await(): CSunMiscSignal.await() failed.");
PosixUtils.checkStatusIs0(awaitResult, "Util_jdk_internal_misc_Signal.SignalState.await(): CSunMiscSignal.await() failed.");
}

protected static void wakeUp() {
final int awaitResult = CSunMiscSignal.post();
PosixUtils.checkStatusIs0(awaitResult, "Util_sun_misc_Signal.SignalState.post(): CSunMiscSignal.post() failed.");
PosixUtils.checkStatusIs0(awaitResult, "Util_jdk_internal_misc_Signal.SignalState.post(): CSunMiscSignal.post() failed.");
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import com.oracle.svm.core.jdk.RuntimeSupport;
import com.oracle.svm.core.log.Log;

import sun.misc.Signal;
import sun.misc.SignalHandler;
import jdk.internal.misc.Signal;

@AutomaticallyRegisteredFeature
public class DumpHeapOnSignalFeature implements InternalFeature {
Expand All @@ -64,7 +63,7 @@ public void execute(boolean isFirstIsolate) {
}
}

class DumpHeapReport implements SignalHandler {
class DumpHeapReport implements Signal.Handler {
private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC");

static void install() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.WINDOWS;

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.graal.RuntimeCompilation;
import com.oracle.svm.core.heap.VMOperationInfos;
import com.oracle.svm.core.jdk.RuntimeSupport;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.thread.JavaVMOperation;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;

import sun.misc.Signal;
import sun.misc.SignalHandler;
import jdk.internal.misc.Signal;

@AutomaticallyRegisteredFeature
public class DumpRuntimeCompilationOnSignalFeature implements InternalFeature {
Expand All @@ -61,7 +60,7 @@ public void execute(boolean isFirstIsolate) {
}
}

class DumpRuntimeCompilation implements SignalHandler {
class DumpRuntimeCompilation implements Signal.Handler {
static void install() {
Signal.handle(new Signal("USR2"), new DumpRuntimeCompilation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platform.WINDOWS;

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.heap.VMOperationInfos;
import com.oracle.svm.core.jdk.RuntimeSupport;
Expand All @@ -39,10 +40,8 @@
import com.oracle.svm.core.thread.JavaVMOperation;
import com.oracle.svm.core.thread.PlatformThreads;
import com.oracle.svm.core.thread.VMThreads;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;

import sun.misc.Signal;
import sun.misc.SignalHandler;
import jdk.internal.misc.Signal;

@AutomaticallyRegisteredFeature
public class DumpThreadStacksOnSignalFeature implements InternalFeature {
Expand All @@ -67,7 +66,7 @@ public void execute(boolean isFirstIsolate) {
}
}

class DumpAllStacks implements SignalHandler {
class DumpAllStacks implements Signal.Handler {
static void install() {
Signal.handle(Platform.includedIn(WINDOWS.class) ? new Signal("BREAK") : new Signal("QUIT"), new DumpAllStacks());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ private static void validateUseOldDebugInfo(HostedOptionKey<Boolean> optionKey)
@Option(help = "Directory under which to create source file cache for Application or GraalVM classes")//
public static final HostedOptionKey<String> DebugInfoSourceCacheRoot = new HostedOptionKey<>("sources");

@Option(help = "Temporary option to disable checking of image builder module dependencies or increasing its verbosity", type = OptionType.Debug)//
public static final HostedOptionKey<Integer> CheckBootModuleDependencies = new HostedOptionKey<>(ModuleSupport.modulePathBuild ? 1 : 0);

public static Path getDebugInfoSourceCacheRoot() {
try {
return Paths.get(Path.getValue()).resolve(DebugInfoSourceCacheRoot.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@

import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.core.common.SuppressFBWarnings;
import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -1932,20 +1931,20 @@ final class Target_java_lang_Class_Atomic {
static <T> boolean casReflectionData(DynamicHub clazz,
SoftReference<Target_java_lang_Class_ReflectionData<T>> oldData,
SoftReference<Target_java_lang_Class_ReflectionData<T>> newData) {
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), reflectionDataOffset, oldData, newData);
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), reflectionDataOffset, oldData, newData);
}

@Substitute
static boolean casAnnotationType(DynamicHub clazz,
AnnotationType oldType,
AnnotationType newType) {
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), annotationTypeOffset, oldType, newType);
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), annotationTypeOffset, oldType, newType);
}

@Substitute
static boolean casAnnotationData(DynamicHub clazz,
Target_java_lang_Class_AnnotationData oldData,
Target_java_lang_Class_AnnotationData newData) {
return GraalUnsafeAccess.getUnsafe().compareAndSwapObject(clazz.getCompanion(), annotationDataOffset, oldData, newData);
return Unsafe.getUnsafe().compareAndSetReference(clazz.getCompanion(), annotationDataOffset, oldData, newData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected static Optional<Class<?>> optionalClazz(FeatureAccess access, String c
}

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

protected static Method method(FeatureAccess access, String className, String methodName, Class<?>... parameterTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,35 @@
*/
package com.oracle.svm.core.jdk;

import java.util.Optional;

import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.RuntimeReflection;
import org.graalvm.nativeimage.impl.ConfigurationCondition;
import org.graalvm.nativeimage.impl.RuntimeClassInitializationSupport;

import com.oracle.svm.core.configure.ResourcesRegistry;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;

@AutomaticallyRegisteredFeature
public class JavaNetHttpFeature extends JNIRegistrationUtil implements InternalFeature {

private static Optional<Module> requiredModule() {
return ModuleLayer.boot().findModule("java.net.http");
}

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return requiredModule().isPresent();
}

@Override
public void afterRegistration(AfterRegistrationAccess access) {
JavaNetHttpFeature.class.getModule().addReads(requiredModule().get());
}

@Override
public void duringSetup(DuringSetupAccess access) {
RuntimeClassInitializationSupport rci = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
Expand All @@ -59,13 +75,19 @@ private static void registerInitFiltersAccess(DuringAnalysisAccess a) {
@AutomaticallyRegisteredFeature
class SimpleWebServerFeature implements InternalFeature {

private static Optional<Module> requiredModule() {
return ModuleLayer.boot().findModule("jdk.httpserver");
}

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return JavaVersionUtil.JAVA_SPEC >= 19;
return JavaVersionUtil.JAVA_SPEC >= 19 && requiredModule().isPresent();
}

@Override
public void afterRegistration(AfterRegistrationAccess access) {
SimpleWebServerFeature.class.getModule().addReads(requiredModule().get());

RuntimeClassInitializationSupport rci = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
rci.initializeAtRunTime("sun.net.httpserver.simpleserver.SimpleFileServerImpl", "Allocates InetAddress in class initializer");
}
Expand Down
Loading