From 96fdebee3bc74345ca7fbb9d2f3dd581c5366e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Fri, 9 Apr 2021 16:25:57 +0200 Subject: [PATCH 1/7] Ensure buildcp entries are all absolute path --- .../svm/hosted/AbstractNativeImageClassLoaderSupport.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java index 663054656621..dc709c08d17e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java @@ -79,7 +79,10 @@ protected AbstractNativeImageClassLoaderSupport(ClassLoader defaultSystemClassLo classPathClassLoader = new URLClassLoader(Util.verifyClassPathAndConvertToURLs(classpath), defaultSystemClassLoader); imagecp = Collections.unmodifiableList(Arrays.stream(classPathClassLoader.getURLs()).map(Util::urlToPath).collect(Collectors.toList())); - buildcp = Collections.unmodifiableList(Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).map(Paths::get).collect(Collectors.toList())); + buildcp = Collections.unmodifiableList(Arrays.stream(System.getProperty("java.class.path") + .split(File.pathSeparator)) + .map(Paths::get).map(Path::toAbsolutePath) + .collect(Collectors.toList())); } List classpath() { From 77f8a4d1c71f7a097704c66408acbc5f8e03fa0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Fri, 9 Apr 2021 17:00:48 +0200 Subject: [PATCH 2/7] Add missing export to org.graalvm.sdk module --- sdk/mx.sdk/suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index 9cd838695de5..e0ff14ca5f52 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -340,7 +340,7 @@ "org.graalvm.word", "org.graalvm.polyglot.impl to org.graalvm.truffle", "org.graalvm.word.impl to jdk.internal.vm.compiler", - "org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder", + "org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder,com.oracle.svm.svm_enterprise", ], "uses" : [ "org.graalvm.polyglot.impl.AbstractPolyglotImpl" From 565ae4412a06f3ed6f5a205844f7f05559eb2b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Fri, 9 Apr 2021 17:36:30 +0200 Subject: [PATCH 3/7] Fix mx hellomodule --- substratevm/mx.substratevm/mx_substratevm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 8eacaf3bcb1e..e172845102b3 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1174,7 +1174,7 @@ def hellomodule(args): proj_dir = join(suite.dir, 'src', 'native-image-module-tests', 'hello.app') mx.run_maven(['-e', 'install'], cwd=proj_dir) module_path.append(join(proj_dir, 'target', 'hello-app-1.0-SNAPSHOT.jar')) - with native_image_context(hosted_assertions=False) as native_image: + with native_image_context(hosted_assertions=False, config=graalvm_jvm_config(), build_if_missing=True) as native_image: build_dir = join(svmbuild_dir(), 'hellomodule') # Build module into native image mx.log('Building image from java modules: ' + str(module_path)) From 54ecd7a40fa58c26b17bd43c240c7d3b013ee220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Tue, 20 Apr 2021 09:46:52 +0200 Subject: [PATCH 4/7] Run image builder as JPMS application --- substratevm/mx.substratevm/suite.py | 3 +++ .../src/com/oracle/svm/driver/MacroOptionHandler.java | 2 ++ .../src/com/oracle/svm/driver/NativeImage.java | 9 ++++++++- .../hosted/AbstractNativeImageClassLoaderSupport.java | 8 ++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index a149e9e6e0d5..da30d8c20be9 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1037,6 +1037,9 @@ "java.desktop", "java.security.sasl", "java.smartcardio", + "java.net.http", + "jdk.sctp", + "jdk.scripting.nashorn", ], "uses" : [ "org.graalvm.nativeimage.Platform", diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java index b648b224aa32..c8fe9e42af55 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/MacroOptionHandler.java @@ -98,6 +98,8 @@ private void applyEnabled(MacroOption.EnabledOption enabledOption, String argume NativeImage.getJars(imageJarsDirectory).forEach(nativeImage::addImageClasspath); } + enabledOption.forEachPropertyValue(config, "ImageModulePath", entry -> nativeImage.addImageModulePath(ClasspathUtils.stringToClasspath(entry)), PATH_SEPARATOR_REGEX); + String imageName = enabledOption.getProperty(config, "ImageName"); if (imageName != null) { nativeImage.addPlainImageBuilderArg(nativeImage.oHName + imageName); diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index d3752492347b..77c528a448de 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -93,6 +93,7 @@ import com.oracle.svm.hosted.AbstractNativeImageClassLoaderSupport; import com.oracle.svm.hosted.NativeImageGeneratorRunner; import com.oracle.svm.hosted.NativeImageSystemClassLoader; +import com.oracle.svm.util.ModuleSupport; public class NativeImage { @@ -100,6 +101,8 @@ public class NativeImage { static final boolean USE_NI_JPMS = System.getenv().getOrDefault("USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM", "false").toLowerCase().equals("true"); private static final String DEFAULT_GENERATOR_CLASS_NAME = NativeImageGeneratorRunner.class.getName(); + private static final String DEFAULT_GENERATOR_MODULE_NAME = ModuleSupport.getModuleName(NativeImageGeneratorRunner.class); + private static final String DEFAULT_GENERATOR_9PLUS_SUFFIX = "$JDK9Plus"; private static final String CUSTOM_SYSTEM_CLASS_LOADER = NativeImageSystemClassLoader.class.getCanonicalName(); @@ -1470,7 +1473,11 @@ protected int buildImage(List javaArgs, LinkedHashSet bcp, LinkedH if (!cp.isEmpty()) { command.addAll(Arrays.asList("-cp", cp.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator)))); } - command.add(USE_NI_JPMS ? DEFAULT_GENERATOR_CLASS_NAME : config.getGeneratorMainClass()); + if (USE_NI_JPMS) { + command.addAll(Arrays.asList("--module", DEFAULT_GENERATOR_MODULE_NAME + "/" + DEFAULT_GENERATOR_CLASS_NAME)); + } else { + command.add(config.getGeneratorMainClass()); + } if (IS_AOT && OS.getCurrent().hasProcFS) { /* * GR-8254: Ensure image-building VM shuts down even if native-image dies unexpected diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java index dc709c08d17e..2eb0076e366c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java @@ -79,8 +79,12 @@ protected AbstractNativeImageClassLoaderSupport(ClassLoader defaultSystemClassLo classPathClassLoader = new URLClassLoader(Util.verifyClassPathAndConvertToURLs(classpath), defaultSystemClassLoader); imagecp = Collections.unmodifiableList(Arrays.stream(classPathClassLoader.getURLs()).map(Util::urlToPath).collect(Collectors.toList())); - buildcp = Collections.unmodifiableList(Arrays.stream(System.getProperty("java.class.path") - .split(File.pathSeparator)) + String builderClassPathString = System.getProperty("java.class.path"); + if (".".equals(builderClassPathString)) { + VMError.shouldNotReachHere("Only ever run " + NativeImageGeneratorRunner.class.getName() + " with explicit --module-path and --module argument."); + } + String[] builderClassPathEntries = builderClassPathString.isEmpty() ? new String[0] : builderClassPathString.split(File.pathSeparator); + buildcp = Collections.unmodifiableList(Arrays.stream(builderClassPathEntries) .map(Paths::get).map(Path::toAbsolutePath) .collect(Collectors.toList())); } From 09020c1d9c0f489bd49a46fd25cf366b6e5592c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Wed, 21 Apr 2021 11:09:37 +0200 Subject: [PATCH 5/7] Only require jdk.scripting.nashorn for versions of JDK that have it --- substratevm/mx.substratevm/suite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index da30d8c20be9..89515fbc041a 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -1039,7 +1039,7 @@ "java.smartcardio", "java.net.http", "jdk.sctp", - "jdk.scripting.nashorn", + "jdk.scripting.nashorn@11..14", ], "uses" : [ "org.graalvm.nativeimage.Platform", From fe9f91bf2ba5831c2a587aa97db67df05d375058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Thu, 22 Apr 2021 12:23:55 +0200 Subject: [PATCH 6/7] Extend mx hellomodule test --- substratevm/mx.substratevm/mx_substratevm.py | 2 +- .../hello.app/src/main/java/hello/Main.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index e172845102b3..4e84c03376fc 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1179,7 +1179,7 @@ def hellomodule(args): # Build module into native image mx.log('Building image from java modules: ' + str(module_path)) module_path_sep = ';' if mx.is_windows() else ':' - built_image = native_image(['--verbose', '-H:Path=' + build_dir, '-p', module_path_sep.join(module_path), '-m', 'moduletests.hello.app']) + built_image = native_image(['--verbose', '-ea', '-H:Path=' + build_dir, '-p', module_path_sep.join(module_path), '-m', 'moduletests.hello.app']) mx.log('Running image ' + built_image + ' built from module:') mx.run([built_image]) diff --git a/substratevm/src/native-image-module-tests/hello.app/src/main/java/hello/Main.java b/substratevm/src/native-image-module-tests/hello.app/src/main/java/hello/Main.java index c83ca7dff082..2a718c1c714f 100644 --- a/substratevm/src/native-image-module-tests/hello.app/src/main/java/hello/Main.java +++ b/substratevm/src/native-image-module-tests/hello.app/src/main/java/hello/Main.java @@ -28,6 +28,18 @@ public class Main { public static void main(String[] args) { + Module helloAppModule = Main.class.getModule(); + assert helloAppModule.getName().equals("moduletests.hello.app"); + assert helloAppModule.isExported("hello"); + + Module helloLibModule = Greeter.class.getModule(); + assert helloLibModule.getName().equals("moduletests.hello.lib"); + assert helloLibModule.isExported("hello.lib"); + + assert helloAppModule.canRead(helloLibModule); + // assert !helloLibModule.canRead(helloAppModule); GR-30957 + + System.out.println("Basic Module test involving " + helloAppModule + " and " + helloLibModule); Greeter.greet(); } } From a0732d1b5b3a983e7e14391d4f8d998b534ba55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20W=C3=B6gerer?= Date: Thu, 22 Apr 2021 13:11:14 +0200 Subject: [PATCH 7/7] Check all builderClassPathEntries for "." --- .../svm/hosted/AbstractNativeImageClassLoaderSupport.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java index 2eb0076e366c..03eb016d6457 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/AbstractNativeImageClassLoaderSupport.java @@ -80,10 +80,12 @@ protected AbstractNativeImageClassLoaderSupport(ClassLoader defaultSystemClassLo imagecp = Collections.unmodifiableList(Arrays.stream(classPathClassLoader.getURLs()).map(Util::urlToPath).collect(Collectors.toList())); String builderClassPathString = System.getProperty("java.class.path"); - if (".".equals(builderClassPathString)) { - VMError.shouldNotReachHere("Only ever run " + NativeImageGeneratorRunner.class.getName() + " with explicit --module-path and --module argument."); - } String[] builderClassPathEntries = builderClassPathString.isEmpty() ? new String[0] : builderClassPathString.split(File.pathSeparator); + if (Arrays.asList(builderClassPathEntries).contains(".")) { + VMError.shouldNotReachHere("The classpath of " + NativeImageGeneratorRunner.class.getName() + + " must not contain \".\". This can happen implicitly if the builder runs exclusively on the --module-path" + + " but specifies the " + NativeImageGeneratorRunner.class.getName() + " main class without --module."); + } buildcp = Collections.unmodifiableList(Arrays.stream(builderClassPathEntries) .map(Paths::get).map(Path::toAbsolutePath) .collect(Collectors.toList()));