Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/mx.sdk/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,12 +1174,12 @@ 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))
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])

Expand Down
3 changes: 3 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,9 @@
"java.desktop",
"java.security.sasl",
"java.smartcardio",
"java.net.http",
"jdk.sctp",
"[email protected]",
],
"uses" : [
"org.graalvm.nativeimage.Platform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@
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 {

/* Used to enable native-image JPMS support (WIP) - will become default once completed */
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();

Expand Down Expand Up @@ -1470,7 +1473,11 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ 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()));
String builderClassPathString = System.getProperty("java.class.path");
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()));
}

List<Path> classpath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivan-ristovic please have a look why we fail this assert at image runtime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adressed by #3397


System.out.println("Basic Module test involving " + helloAppModule + " and " + helloLibModule);
Greeter.greet();
}
}