Skip to content

Commit 8b5ef1d

Browse files
committed
[GR-30433] Image builder JPMS cleanups.
PullRequest: graal/8799
2 parents b50eec6 + a0732d1 commit 8b5ef1d

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

sdk/mx.sdk/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
"org.graalvm.word",
341341
"org.graalvm.polyglot.impl to org.graalvm.truffle",
342342
"org.graalvm.word.impl to jdk.internal.vm.compiler",
343-
"org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder",
343+
"org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder,com.oracle.svm.svm_enterprise",
344344
],
345345
"uses" : [
346346
"org.graalvm.polyglot.impl.AbstractPolyglotImpl"

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,12 @@ def hellomodule(args):
11741174
proj_dir = join(suite.dir, 'src', 'native-image-module-tests', 'hello.app')
11751175
mx.run_maven(['-e', 'install'], cwd=proj_dir)
11761176
module_path.append(join(proj_dir, 'target', 'hello-app-1.0-SNAPSHOT.jar'))
1177-
with native_image_context(hosted_assertions=False) as native_image:
1177+
with native_image_context(hosted_assertions=False, config=graalvm_jvm_config(), build_if_missing=True) as native_image:
11781178
build_dir = join(svmbuild_dir(), 'hellomodule')
11791179
# Build module into native image
11801180
mx.log('Building image from java modules: ' + str(module_path))
11811181
module_path_sep = ';' if mx.is_windows() else ':'
1182-
built_image = native_image(['--verbose', '-H:Path=' + build_dir, '-p', module_path_sep.join(module_path), '-m', 'moduletests.hello.app'])
1182+
built_image = native_image(['--verbose', '-ea', '-H:Path=' + build_dir, '-p', module_path_sep.join(module_path), '-m', 'moduletests.hello.app'])
11831183
mx.log('Running image ' + built_image + ' built from module:')
11841184
mx.run([built_image])
11851185

substratevm/mx.substratevm/suite.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,9 @@
10371037
"java.desktop",
10381038
"java.security.sasl",
10391039
"java.smartcardio",
1040+
"java.net.http",
1041+
"jdk.sctp",
1042+
10401043
],
10411044
"uses" : [
10421045
"org.graalvm.nativeimage.Platform",

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ private void applyEnabled(MacroOption.EnabledOption enabledOption, String argume
9898
NativeImage.getJars(imageJarsDirectory).forEach(nativeImage::addImageClasspath);
9999
}
100100

101+
enabledOption.forEachPropertyValue(config, "ImageModulePath", entry -> nativeImage.addImageModulePath(ClasspathUtils.stringToClasspath(entry)), PATH_SEPARATOR_REGEX);
102+
101103
String imageName = enabledOption.getProperty(config, "ImageName");
102104
if (imageName != null) {
103105
nativeImage.addPlainImageBuilderArg(nativeImage.oHName + imageName);

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@
9393
import com.oracle.svm.hosted.AbstractNativeImageClassLoaderSupport;
9494
import com.oracle.svm.hosted.NativeImageGeneratorRunner;
9595
import com.oracle.svm.hosted.NativeImageSystemClassLoader;
96+
import com.oracle.svm.util.ModuleSupport;
9697

9798
public class NativeImage {
9899

99100
/* Used to enable native-image JPMS support (WIP) - will become default once completed */
100101
static final boolean USE_NI_JPMS = System.getenv().getOrDefault("USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM", "false").toLowerCase().equals("true");
101102

102103
private static final String DEFAULT_GENERATOR_CLASS_NAME = NativeImageGeneratorRunner.class.getName();
104+
private static final String DEFAULT_GENERATOR_MODULE_NAME = ModuleSupport.getModuleName(NativeImageGeneratorRunner.class);
105+
103106
private static final String DEFAULT_GENERATOR_9PLUS_SUFFIX = "$JDK9Plus";
104107
private static final String CUSTOM_SYSTEM_CLASS_LOADER = NativeImageSystemClassLoader.class.getCanonicalName();
105108

@@ -1474,7 +1477,11 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> bcp, LinkedH
14741477
if (!cp.isEmpty()) {
14751478
command.addAll(Arrays.asList("-cp", cp.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator))));
14761479
}
1477-
command.add(USE_NI_JPMS ? DEFAULT_GENERATOR_CLASS_NAME : config.getGeneratorMainClass());
1480+
if (USE_NI_JPMS) {
1481+
command.addAll(Arrays.asList("--module", DEFAULT_GENERATOR_MODULE_NAME + "/" + DEFAULT_GENERATOR_CLASS_NAME));
1482+
} else {
1483+
command.add(config.getGeneratorMainClass());
1484+
}
14781485
if (IS_AOT && OS.getCurrent().hasProcFS) {
14791486
/*
14801487
* GR-8254: Ensure image-building VM shuts down even if native-image dies unexpected

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ protected AbstractNativeImageClassLoaderSupport(ClassLoader defaultSystemClassLo
7979
classPathClassLoader = new URLClassLoader(Util.verifyClassPathAndConvertToURLs(classpath), defaultSystemClassLoader);
8080

8181
imagecp = Collections.unmodifiableList(Arrays.stream(classPathClassLoader.getURLs()).map(Util::urlToPath).collect(Collectors.toList()));
82-
buildcp = Collections.unmodifiableList(Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).map(Paths::get).collect(Collectors.toList()));
82+
String builderClassPathString = System.getProperty("java.class.path");
83+
String[] builderClassPathEntries = builderClassPathString.isEmpty() ? new String[0] : builderClassPathString.split(File.pathSeparator);
84+
if (Arrays.asList(builderClassPathEntries).contains(".")) {
85+
VMError.shouldNotReachHere("The classpath of " + NativeImageGeneratorRunner.class.getName() +
86+
" must not contain \".\". This can happen implicitly if the builder runs exclusively on the --module-path" +
87+
" but specifies the " + NativeImageGeneratorRunner.class.getName() + " main class without --module.");
88+
}
89+
buildcp = Collections.unmodifiableList(Arrays.stream(builderClassPathEntries)
90+
.map(Paths::get).map(Path::toAbsolutePath)
91+
.collect(Collectors.toList()));
8392
}
8493

8594
List<Path> classpath() {

substratevm/src/native-image-module-tests/hello.app/src/main/java/hello/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828

2929
public class Main {
3030
public static void main(String[] args) {
31+
Module helloAppModule = Main.class.getModule();
32+
assert helloAppModule.getName().equals("moduletests.hello.app");
33+
assert helloAppModule.isExported("hello");
34+
35+
Module helloLibModule = Greeter.class.getModule();
36+
assert helloLibModule.getName().equals("moduletests.hello.lib");
37+
assert helloLibModule.isExported("hello.lib");
38+
39+
assert helloAppModule.canRead(helloLibModule);
40+
// assert !helloLibModule.canRead(helloAppModule); GR-30957
41+
42+
System.out.println("Basic Module test involving " + helloAppModule + " and " + helloLibModule);
3143
Greeter.greet();
3244
}
3345
}

0 commit comments

Comments
 (0)