Skip to content

Commit e3ba98d

Browse files
committed
svm: migrate to HostModuleUtil#addReads
1 parent f8dbcc1 commit e3ba98d

File tree

14 files changed

+63
-39
lines changed

14 files changed

+63
-39
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinSubstitutions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.svm.core.posix.PosixUtils;
4444
import com.oracle.svm.core.posix.headers.darwin.DarwinTime;
4545
import com.oracle.svm.core.util.BasedOnJDKFile;
46+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
4647

4748
import jdk.internal.misc.Unsafe;
4849

@@ -138,7 +139,7 @@ final class Target_java_util_prefs_FileSystemPreferences {
138139
final class IsJavaUtilPrefsPresent implements BooleanSupplier {
139140
@Override
140141
public boolean getAsBoolean() {
141-
var prefsMod = ModuleLayer.boot().findModule("java.prefs");
142+
var prefsMod = ResolvedJavaModuleLayer.boot().findModule("java.prefs");
142143
return prefsMod.isPresent();
143144
}
144145
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.oracle.svm.core.util.UserError;
8282
import com.oracle.svm.core.util.VMError;
8383
import com.oracle.svm.util.LogUtils;
84+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
8485

8586
import jdk.graal.compiler.api.replacements.Fold;
8687
import jdk.graal.compiler.asm.amd64.AMD64Assembler;
@@ -975,7 +976,7 @@ public static boolean hasFramePointer() {
975976
@Override
976977
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String oldValue, String newValue) {
977978
if ("llvm".equals(newValue)) {
978-
boolean isLLVMBackendMissing = ModuleLayer.boot().findModule("org.graalvm.nativeimage.llvm").isEmpty();
979+
boolean isLLVMBackendMissing = ResolvedJavaModuleLayer.boot().findModule("org.graalvm.nativeimage.llvm").isEmpty();
979980
if (isLLVMBackendMissing) {
980981
throw UserError.invalidOptionValue(CompilerBackend, newValue,
981982
"The LLVM backend for GraalVM Native Image is missing and needs to be built from source. " +

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@
3838
import com.oracle.svm.core.traits.BuiltinTraits.NoLayeredCallbacks;
3939
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
4040
import com.oracle.svm.core.traits.SingletonTraits;
41+
import com.oracle.svm.util.HostModuleUtil;
42+
import com.oracle.svm.util.ResolvedJavaModule;
43+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
4144

4245
@AutomaticallyRegisteredFeature
4346
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
4447
public class JavaNetHttpFeature extends JNIRegistrationUtil implements InternalFeature {
4548

46-
private static Optional<Module> requiredModule() {
47-
return ModuleLayer.boot().findModule("java.net.http");
49+
private static Optional<ResolvedJavaModule> requiredModule() {
50+
return ResolvedJavaModuleLayer.boot().findModule("java.net.http");
4851
}
4952

5053
@Override
@@ -54,7 +57,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
5457

5558
@Override
5659
public void afterRegistration(AfterRegistrationAccess access) {
57-
JavaNetHttpFeature.class.getModule().addReads(requiredModule().get());
60+
HostModuleUtil.addReads(JavaNetHttpFeature.class, requiredModule().get());
5861
}
5962

6063
@Override
@@ -80,8 +83,8 @@ private static void registerInitFiltersAccess(DuringAnalysisAccess a) {
8083
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = NoLayeredCallbacks.class, layeredInstallationKind = Independent.class)
8184
class SimpleWebServerFeature implements InternalFeature {
8285

83-
private static Optional<Module> requiredModule() {
84-
return ModuleLayer.boot().findModule("jdk.httpserver");
86+
private static Optional<ResolvedJavaModule> requiredModule() {
87+
return ResolvedJavaModuleLayer.boot().findModule("jdk.httpserver");
8588
}
8689

8790
@Override
@@ -91,7 +94,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
9194

9295
@Override
9396
public void afterRegistration(AfterRegistrationAccess access) {
94-
SimpleWebServerFeature.class.getModule().addReads(requiredModule().get());
97+
HostModuleUtil.addReads(SimpleWebServerFeature.class, requiredModule().get());
9598

9699
RuntimeClassInitializationSupport rci = ImageSingletons.lookup(RuntimeClassInitializationSupport.class);
97100
rci.initializeAtRunTime("sun.net.httpserver.simpleserver", "Allocates InetAddress in class initializers");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.oracle.svm.core.annotate.RecomputeFieldValue;
3131
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
3232
import com.oracle.svm.core.annotate.TargetClass;
33+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
3334

3435
/**
3536
* These substitutions are necessary because the static initializations of these fields are copies
@@ -101,6 +102,6 @@ final class Target_sun_misc_Unsafe {
101102
class JdkUnsupportedIsEnabled implements BooleanSupplier {
102103
@Override
103104
public boolean getAsBoolean() {
104-
return ModuleLayer.boot().findModule("jdk.unsupported").isPresent();
105+
return ResolvedJavaModuleLayer.boot().findModule("jdk.unsupported").isPresent();
105106
}
106107
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.oracle.svm.core.annotate.Substitute;
3434
import com.oracle.svm.core.annotate.TargetClass;
3535
import com.oracle.svm.core.heap.Heap;
36+
import com.oracle.svm.util.HostModuleUtil;
37+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
3638

3739
/**
3840
* Note that sun.rmi.transport.GC is initialized at build-time to avoid including the rmi library,
@@ -55,9 +57,9 @@ class JavaRMIModuleAvailable implements BooleanSupplier {
5557
private static final boolean hasModule;
5658

5759
static {
58-
var module = ModuleLayer.boot().findModule("java.rmi");
60+
var module = ResolvedJavaModuleLayer.boot().findModule("java.rmi");
5961
if (module.isPresent()) {
60-
JavaRMIModuleAvailable.class.getModule().addReads(module.get());
62+
HostModuleUtil.addReads(JavaRMIModuleAvailable.class, module.get());
6163
}
6264
hasModule = module.isPresent();
6365
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementAgentModule.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import java.util.function.BooleanSupplier;
3030

3131
import com.oracle.svm.core.util.VMError;
32+
import com.oracle.svm.util.HostModuleUtil;
3233
import com.oracle.svm.util.ReflectionUtil;
34+
import com.oracle.svm.util.ResolvedJavaModule;
35+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
3336

3437
public class ManagementAgentModule {
3538

@@ -42,9 +45,9 @@ public class ManagementAgentModule {
4245
static final String CONFIG_FILE_OPEN_FAILED;
4346

4447
static {
45-
Optional<Module> agentModule = ModuleLayer.boot().findModule("jdk.management.agent");
48+
Optional<ResolvedJavaModule> agentModule = ResolvedJavaModuleLayer.boot().findModule("jdk.management.agent");
4649
if (agentModule.isPresent()) {
47-
ManagementAgentModule.class.getModule().addReads(agentModule.get());
50+
HostModuleUtil.addReads(ManagementAgentModule.class, agentModule.get());
4851
var agentClass = ReflectionUtil.lookupClass(false, "jdk.internal.agent.Agent");
4952
agentStartAgent = ReflectionUtil.lookupMethod(agentClass, "startAgent");
5053
agentError = ReflectionUtil.lookupMethod(agentClass, "error", String.class, String.class);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import com.oracle.svm.core.thread.ThreadListener;
6565
import com.oracle.svm.core.util.UserError;
6666
import com.oracle.svm.core.util.VMError;
67+
import com.oracle.svm.util.HostModuleUtil;
68+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
6769
import com.sun.jmx.mbeanserver.MXBeanLookup;
6870

6971
import jdk.graal.compiler.api.replacements.Fold;
@@ -297,9 +299,9 @@ private synchronized PlatformManagedObject getFlightRecorderMXBean() {
297299
@Platforms(Platform.HOSTED_ONLY.class)
298300
@SuppressWarnings("unchecked")
299301
private static Class<? extends PlatformManagedObject> getFlightRecorderMXBeanClass() {
300-
var jfrModule = ModuleLayer.boot().findModule("jdk.management.jfr");
302+
var jfrModule = ResolvedJavaModuleLayer.boot().findModule("jdk.management.jfr");
301303
if (jfrModule.isPresent()) {
302-
ManagementSupport.class.getModule().addReads(jfrModule.get());
304+
HostModuleUtil.addReads(ManagementSupport.class, jfrModule.get());
303305
try {
304306
return (Class<? extends PlatformManagedObject>) Class.forName("jdk.management.jfr.FlightRecorderMXBean", false, Object.class.getClassLoader());
305307
} catch (ClassNotFoundException ex) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionSupport.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
*/
2525
package com.oracle.svm.hosted;
2626

27-
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
28-
import com.oracle.svm.util.ReflectionUtil;
29-
30-
import org.graalvm.collections.EconomicMap;
31-
import org.graalvm.nativeimage.ImageSingletons;
32-
3327
import java.io.ObjectInputStream;
3428
import java.io.ObjectOutputStream;
3529
import java.io.ObjectStreamClass;
@@ -54,6 +48,13 @@
5448
import java.util.ResourceBundle;
5549
import java.util.Set;
5650

51+
import org.graalvm.collections.EconomicMap;
52+
import org.graalvm.nativeimage.ImageSingletons;
53+
54+
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
55+
import com.oracle.svm.util.ReflectionUtil;
56+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
57+
5758
import jdk.internal.access.JavaLangAccess;
5859
import jdk.internal.loader.BuiltinClassLoader;
5960
import jdk.internal.misc.Unsafe;
@@ -99,7 +100,7 @@ public static DynamicAccessDetectionSupport instance() {
99100

100101
public DynamicAccessDetectionSupport(AnalysisMetaAccess metaAccess) {
101102
this.metaAccess = metaAccess;
102-
boolean jdkUnsupportedModulePresent = ModuleLayer.boot().findModule("jdk.unsupported").isPresent();
103+
boolean jdkUnsupportedModulePresent = ResolvedJavaModuleLayer.boot().findModule("jdk.unsupported").isPresent();
103104

104105
put(reflectionMethods, Class.class, Set.of(
105106
new MethodSignature("forName", String.class),

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/LoggingFeature.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@
3838
import com.oracle.svm.core.util.VMError;
3939
import com.oracle.svm.hosted.FeatureImpl.DuringAnalysisAccessImpl;
4040
import com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl;
41+
import com.oracle.svm.util.HostModuleUtil;
4142
import com.oracle.svm.util.ReflectionUtil;
43+
import com.oracle.svm.util.ResolvedJavaModule;
44+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
4245

4346
import jdk.graal.compiler.options.Option;
4447
import jdk.graal.compiler.options.OptionType;
4548

4649
@AutomaticallyRegisteredFeature
4750
public class LoggingFeature implements InternalFeature {
4851

49-
private static Optional<Module> requiredModule() {
50-
return ModuleLayer.boot().findModule("java.logging");
52+
private static Optional<ResolvedJavaModule> requiredModule() {
53+
return ResolvedJavaModuleLayer.boot().findModule("java.logging");
5154
}
5255

5356
public static class Options {
@@ -74,7 +77,7 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
7477

7578
@Override
7679
public void afterRegistration(AfterRegistrationAccess access) {
77-
LoggingFeature.class.getModule().addReads(requiredModule().get());
80+
HostModuleUtil.addReads(LoggingFeature.class, requiredModule().get());
7881
}
7982

8083
@Override

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SecurityServicesFeature.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor;
115115
import com.oracle.svm.util.ModuleSupport;
116116
import com.oracle.svm.util.ReflectionUtil;
117+
import com.oracle.svm.util.ResolvedJavaModuleLayer;
117118
import com.oracle.svm.util.TypeResult;
118119

119120
import jdk.graal.compiler.debug.Assertions;
@@ -205,20 +206,20 @@ public static class Options {
205206
KeyStore.class, Mac.class, MessageDigest.class, SSLContext.class,
206207
SecretKeyFactory.class, SecureRandom.class, Signature.class, TrustManagerFactory.class));
207208

208-
if (ModuleLayer.boot().findModule("java.security.sasl").isPresent()) {
209+
if (ResolvedJavaModuleLayer.boot().findModule("java.security.sasl").isPresent()) {
209210
classList.add(ReflectionUtil.lookupClass(false, "javax.security.sasl.SaslClientFactory"));
210211
classList.add(ReflectionUtil.lookupClass(false, "javax.security.sasl.SaslServerFactory"));
211212
}
212-
if (ModuleLayer.boot().findModule("java.xml.crypto").isPresent()) {
213+
if (ResolvedJavaModuleLayer.boot().findModule("java.xml.crypto").isPresent()) {
213214
classList.add(ReflectionUtil.lookupClass(false, "javax.xml.crypto.dsig.TransformService"));
214215
classList.add(ReflectionUtil.lookupClass(false, "javax.xml.crypto.dsig.XMLSignatureFactory"));
215216
classList.add(ReflectionUtil.lookupClass(false, "javax.xml.crypto.dsig.keyinfo.KeyInfoFactory"));
216217
}
217-
if (ModuleLayer.boot().findModule("java.smartcardio").isPresent()) {
218+
if (ResolvedJavaModuleLayer.boot().findModule("java.smartcardio").isPresent()) {
218219
classList.add(ReflectionUtil.lookupClass(false, "javax.smartcardio.TerminalFactory"));
219220
}
220221

221-
isMscapiModulePresent = ModuleLayer.boot().findModule("jdk.crypto.mscapi").isPresent();
222+
isMscapiModulePresent = ResolvedJavaModuleLayer.boot().findModule("jdk.crypto.mscapi").isPresent();
222223

223224
knownServices = Collections.unmodifiableList(classList);
224225
}

0 commit comments

Comments
 (0)