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-30957] Implement Module/ModuleLayer substitutions #3445

Merged
merged 8 commits into from
Aug 26, 2021
Merged

[GR-30957] Implement Module/ModuleLayer substitutions #3445

merged 8 commits into from
Aug 26, 2021

Conversation

ivan-ristovic
Copy link
Contributor

@ivan-ristovic ivan-ristovic commented Jun 2, 2021

This PR implements basic methods of the Module class and synthesizes the runtime boot module layer.

Change list:

  • Removed substitutions for methods such as canRead(), canUse() etc. because the JDK implementation can be reused
  • Removed @Delete annotation from ReflectionData, because it is used from now on
  • Redefine the value of the ReflectionData.uses field, otherwise it will contain classes that were not nececarily discovered by analysis
  • Added an alias for java.lang.WeakHashMap, in order to redefine the ReflectionData.uses field
  • Added a feature which synthesizes the boot module layer
  • Substituted ModuleLayer.boot() method to return the synthesized layer
  • Enhanced mx hellomodule
  • Added a GitHub CI gate for mx hellomodule
  • Added substitutions for native methods in the Module class

Boot layer module set comparison (for a simple modular application similar to mx hellomodule)

Hotspot:

[module main.app, module jdk.zipfs, module java.management, module jdk.charsets, module jdk.naming.rmi, module java.rmi, module java.management.rmi, module jdk.jartool, module java.security.jgss, module jdk.security.jgss, module jdk.javadoc, module java.logging, module java.smartcardio, module java.base, module jdk.jlink, module jdk.management.jfr, module jdk.management, module jdk.crypto.cryptoki, module jdk.internal.opt, module core.app, module jdk.jfr, module java.desktop, module java.prefs, module jdk.unsupported.desktop, module jdk.crypto.ec, module java.xml.crypto, module jdk.compiler, module java.compiler, module java.datatransfer, module java.security.sasl, module jdk.naming.dns, module jdk.jdeps, module java.naming, module jdk.security.auth, module java.xml, module jdk.localedata]

SVM (before this PR):

[module jdk.security.jgss, module jdk.naming.dns, module java.xml, module jdk.javadoc, module java.management, module jdk.compiler, module java.security.jgss, module java.rmi, module jdk.internal.vm.ci, module com.oracle.svm.shadowed.org.bytedeco.llvm.linux.x86_64, module jdk.jlink, module jdk.scripting.nashorn, module jdk.internal.vm.compiler.management, module org.graalvm.nativeimage.pointsto, module jdk.security.auth, module java.security.sasl, module java.scripting, module org.graalvm.nativeimage.builder, module java.transaction.xa, module java.smartcardio, module org.graalvm.nativeimage.objectfile, module java.datatransfer, module java.net.http, module org.graalvm.truffle, module jdk.jdeps, module com.oracle.svm.shadowed.org.bytedeco.llvm, module jdk.internal.opt, module java.instrument, module jdk.jfr, module jdk.unsupported.desktop, module java.logging, module com.oracle.svm.shadowed.org.bytedeco.javacpp, module java.xml.crypto, module java.sql, module jdk.sctp, module jdk.crypto.ec, module jdk.internal.vm.compiler, module jdk.management, module org.graalvm.sdk, module jdk.charsets, module jdk.localedata, module org.graalvm.nativeimage.llvm, module org.graalvm.locator, module jdk.jartool, module jdk.crypto.cryptoki, module jdk.unsupported, module jdk.naming.rmi, module jdk.management.jfr, module java.naming, module java.base, module java.desktop, module java.compiler, module java.prefs, module jdk.dynalink, module java.management.rmi, module jdk.internal.vm.compiler.truffle.jfr, module jdk.zipfs]

SVM (with changes introduced by this PR):

[module jdk.management, module jdk.internal.vm.compiler, module org.graalvm.sdk, module main.app, module jdk.internal.vm.ci, module jdk.unsupported, module jdk.zipfs, module java.management, module org.graalvm.nativeimage.builder, module jdk.localedata, module java.base, module core.app, module java.logging]

Note that it is trivial to filter the set in order to hide modules we do not wish to expose, currently all non-synthesized reachable modules are included. A module is reachable when a class within it is reachable.

@olpaw olpaw requested review from cstancu and olpaw June 2, 2021 11:24
@olpaw olpaw self-assigned this Jun 2, 2021
@olpaw
Copy link
Member

olpaw commented Jun 2, 2021

@ivan-ristovic please provide a before-after comparison based on a simple hello-world module-build sample so that it is clear how the runtime-representation of module info is changed by this PR.

@ivan-ristovic
Copy link
Contributor Author

@ivan-ristovic please provide a before-after comparison based on a simple hello-world module-build sample so that it is clear how the runtime-representation of module info is changed by this PR.

I added a simple hello-module sample output to the PR description

@olpaw
Copy link
Member

olpaw commented Jun 17, 2021

Hi @ivan-ristovic

@olpaw
Copy link
Member

olpaw commented Jun 17, 2021

Running your PR on top of #3446 breaks mx hellomodule:

...
[moduletests.hello.app:74056]     (inline):     976.14 ms,  1.77 GB
[moduletests.hello.app:74056]    (compile):   4,475.44 ms,  3.29 GB
[moduletests.hello.app:74056]      compile:   6,686.27 ms,  3.29 GB
[moduletests.hello.app:74056]        image:   1,714.78 ms,  3.29 GB
[moduletests.hello.app:74056]        write:     166.64 ms,  3.29 GB
[moduletests.hello.app:74056]      [total]:  22,307.03 ms,  3.29 GB
# Printing build artifacts to: /home/pwoegere/OLabs/issues/GR-31840/graal/substratevm/svmbuild/hellomodule/moduletests.hello.app.build_artifacts.txt
Running image /home/pwoegere/OLabs/issues/GR-31840/graal/substratevm/svmbuild/hellomodule/moduletests.hello.app built from module:
Basic Module test involving module moduletests.hello.app and module moduletests.hello.lib
Hello Module World!
Now accessing package that is not exported in module moduletests.hello.lib
Seeing this requires --add-exports
Now accessing private method from not exported package in module moduletests.hello.lib
Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make private static void hello.privateLib2.PrivateGreeter.greet() accessible: module moduletests.hello.lib does not "opens hello.privateLib2" to module moduletests.hello.app
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
	at java.lang.reflect.Method.checkCanSetAccessible(Method.java:198)
	at java.lang.reflect.Method.setAccessible(Method.java:192)
	at hello.Main.main(Main.java:53)

When setting module runtime-state you must honor --add-exports and --add-opens that have been passed to native-image.
https://github.com/olpaw/graal/blob/e044094cfb358a8b63399262aff461b08375145c/substratevm/mx.substratevm/mx_substratevm.py#L1095

@olpaw
Copy link
Member

olpaw commented Jun 17, 2021

When setting module runtime-state you must honor --add-exports and --add-opens that have been passed to native-image.
https://github.com/olpaw/graal/blob/e044094cfb358a8b63399262aff461b08375145c/substratevm/mx.substratevm/mx_substratevm.py#L1095

Update. Forget what I just said. Your changes actually fixe the hellomodule test now correctly requiring --add-opens where previously only --add-exports was already sufficient. Also now the commented-out assert can be enabled in the test. 😄

I.e. you should apply the following patch to your branch:

diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py
index 0ecb3c4ed7f..ed577488c50 100644
--- a/substratevm/mx.substratevm/mx_substratevm.py
+++ b/substratevm/mx.substratevm/mx_substratevm.py
@@ -1095,7 +1095,7 @@ def hellomodule(args):
         built_image = native_image([
             '--verbose', '-ea', '-H:Path=' + build_dir,
             '--add-exports=moduletests.hello.lib/hello.privateLib=moduletests.hello.app',
-            '--add-exports=moduletests.hello.lib/hello.privateLib2=moduletests.hello.app',
+            '--add-opens=moduletests.hello.lib/hello.privateLib2=moduletests.hello.app',
             '-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 be8b8025354..5c1a61a8967 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
@@ -40,7 +40,7 @@ public class Main {
         assert helloLibModule.isExported("hello.lib");
 
         assert helloAppModule.canRead(helloLibModule);
-        // assert !helloLibModule.canRead(helloAppModule); GR-30957
+        assert !helloLibModule.canRead(helloAppModule);
 
         System.out.println("Basic Module test involving " + helloAppModule + " and " + helloLibModule);
         Greeter.greet();

@olpaw olpaw self-requested a review June 17, 2021 13:27
Copy link
Member

@olpaw olpaw left a comment

Choose a reason for hiding this comment

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

@ivan-ristovic
Copy link
Contributor Author

See comments #3445 (comment) #3445 (comment)

Done.

@olpaw
Copy link
Member

olpaw commented Jun 29, 2021

Hi @ivan-ristovic
https://ol-bitbucket.us.oracle.com/projects/G/repos/graal/pull-requests/9053 is finally on master.
Please rebase your PR so that we can get into merging your changes to master as well. Thanks!

@ivan-ristovic
Copy link
Contributor Author

Hi @ivan-ristovic
https://ol-bitbucket.us.oracle.com/projects/G/repos/graal/pull-requests/9053 is finally on master.
Please rebase your PR so that we can get into merging your changes to master as well. Thanks!

Done.

Copy link
Member

@olpaw olpaw left a comment

Choose a reason for hiding this comment

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

@olpaw olpaw changed the title Implement Module/ModuleLayer substitutions [GR-30957] Implement Module/ModuleLayer substitutions Jul 14, 2021
@ivan-ristovic
Copy link
Contributor Author

@olpaw About the module/package bookkeeping/lookup: at this point, it is nececary to check if the module with a given name has already been defined:

definedModule = ModuleUtil.getDefinedModule(module.getName());

I was hoping that also the package lookup could also be more efficient as well (if the loader has already defined a package with a given name).

@olpaw
Copy link
Member

olpaw commented Aug 11, 2021

@olpaw About the module/package bookkeeping/lookup: at this point, it is nececary to check if the module with a given name has already been defined:

definedModule = ModuleUtil.getDefinedModule(module.getName());

I was hoping that also the package lookup could also be more efficient as well (if the loader has already defined a package with a given name).

You can iterate the modules in the bootLayer at runtime and access for each Module module.getDescriptor().packages().

Copy link
Member

@olpaw olpaw left a comment

Choose a reason for hiding this comment

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

Looks good overall. Time to merge the PR after final cleanup.
I'm running your PR in our CI now to see if anything shows up on EE side.

Please rebase the PR to master and squash the commits where it makes sense.

@olpaw
Copy link
Member

olpaw commented Aug 12, 2021

I'm running your PR in our CI now to see if anything shows up on EE side.

@ivan-ristovic your PR breaks Java 8 compatibility.

If you use JAVA_HOME with Java 8 and EXTRA_JAVA_HOMES with Java 11 you will see errors like:

Error: Class initialization of com.oracle.svm.core.hub.DynamicHub failed. Use the option --initialize-at-run-time=com.oracle.svm.core.hub.DynamicHub to explicitly request delayed initialization of this class.
com.oracle.svm.core.util.UserError$UserException: Class initialization of com.oracle.svm.core.hub.DynamicHub failed. Use the option --initialize-at-run-time=com.oracle.svm.core.hub.DynamicHub to explicitly request delayed initialization of this class.
	at com.oracle.svm.core.util.UserError.abort(UserError.java:82)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.reportInitializationError(ConfigurableClassInitialization.java:213)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.ensureClassInitialized(ConfigurableClassInitialization.java:194)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.forceInitializeHosted(ConfigurableClassInitialization.java:497)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:297)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:266)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:941)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:873)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:531)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:492)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:400)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:566)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
[js:9655]      [total]:   4,740.02 ms,  1.79 GB
Caused by: java.lang.BootstrapMethodError: java.lang.UnsupportedClassVersionError: com/oracle/svm/core/jdk/Target_java_lang_Module has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at com.oracle.svm.core.hub.DynamicHub.<clinit>(DynamicHub.java:348)
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.ensureClassInitialized(GraalUnsafeAccess.java:77)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.ensureClassInitialized(ConfigurableClassInitialization.java:178)
	... 10 more
Caused by: java.lang.UnsupportedClassVersionError: com/oracle/svm/core/jdk/Target_java_lang_Module has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 14 more

Maybe a side effect of removing the trySetObjectField substitution.

Also Target_java_lang_Module and Target_java_lang_module_ModuleReference should be in com.oracle.svm.core.jdk11 so that they are not seen when running on 8.

@ivan-ristovic
Copy link
Contributor Author

@ivan-ristovic your PR breaks Java 8 compatibility.
If you use JAVA_HOME with Java 8 and EXTRA_JAVA_HOMES with Java 11 you will see errors like:

Unfortunately, I do not have EE access yet. CE built locally with mx --java-home <JDK8> --extra-java-homes <JDK11> build passes without errors. I do not have the exact example as you do to test the launcher, however I can successfully build and run images of a few simple non-modular examples. This looks like overlay problem.

Maybe a side effect of removing the trySetObjectField substitution.

trySetObjectField was annotated with @OnlyWith(JDK11.class) anyway, it should not be substituted on Java 8. As I understand, it was substituted due to JDK using Unsafe.objectFieldOffset which was not implemented on our side, however now it is so it looks like we can reuse the JDK implementation. We need trySetObjectField because ModuleLayer.bindToLoader() will transitively call this.

Also Target_java_lang_Module and Target_java_lang_module_ModuleReference should be in com.oracle.svm.core.jdk11 so that they are not seen when running on 8.

I agree, however that will cause problems as several other classes use these types (that is why I kept the overlays) for example:

public static final LazyFinalReference<Target_java_lang_Module> singleModuleReference = new LazyFinalReference<>(Target_java_lang_Module::new);

I am not sure what is the best approach here, maybe you have some ideas?

On a side note, PR is rebased and commits are squashed. I have also added checks for already defined modules/packages.

@olpaw
Copy link
Member

olpaw commented Aug 12, 2021

I agree, however that will cause problems as several other classes use these types (that is why I kept the overlays) for example:

That just means singleModuleReference and module specific substitutions like e.g. com.oracle.svm.core.jdk.Target_java_lang_ClassLoader#getUnnamedModule() need to be moved to com.oracle.svm.core.jdk11 as well.

@olpaw
Copy link
Member

olpaw commented Aug 13, 2021

Unfortunately, I do not have EE access yet. CE built locally with mx --java-home --extra-java-homes build passes without errors. I do not have the exact example as you do to test the launcher, however I can successfully build and run images of a few simple non-modular examples.

@ivan-ristovic the issue described in #3445 (comment) can also easily be reproduced on your side with.

  1. export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false
  2. export JAVA_HOME=/path/to/jdk-8
    export EXTRA_JAVA_HOMES=/path/to/jdk-11
  3. export DYNAMIC_IMPORTS=/graal-js
  4. // From graal/substratevm ...
    pushd ../..
    git clone https://github.com/oracle/graaljs.git
    popd
  5. mx clean && mx build
  6. mx native-image --macro:js-launcher -H:+ReportExceptionStackTraces

results in

[js:19332]    classlist:   1,664.54 ms,  1.60 GB
[js:19332]        setup:     364.64 ms,  2.23 GB
Error: Class initialization of com.oracle.svm.core.hub.DynamicHub failed. Use the option --initialize-at-run-time=com.oracle.svm.core.hub.DynamicHub to explicitly request delayed initialization of this class.
com.oracle.svm.core.util.UserError$UserException: Class initialization of com.oracle.svm.core.hub.DynamicHub failed. Use the option --initialize-at-run-time=com.oracle.svm.core.hub.DynamicHub to explicitly request delayed initialization of this class.
	at com.oracle.svm.core.util.UserError.abort(UserError.java:82)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.reportInitializationError(ConfigurableClassInitialization.java:213)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.ensureClassInitialized(ConfigurableClassInitialization.java:194)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.forceInitializeHosted(ConfigurableClassInitialization.java:497)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:297)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:266)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:941)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:873)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:531)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:492)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:400)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:566)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
Caused by: java.lang.BootstrapMethodError: java.lang.UnsupportedClassVersionError: com/oracle/svm/core/jdk/Target_java_lang_Module has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at com.oracle.svm.core.hub.DynamicHub.<clinit>(DynamicHub.java:348)
	at sun.misc.Unsafe.ensureClassInitialized(Native Method)
	at org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.ensureClassInitialized(GraalUnsafeAccess.java:77)
	at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.ensureClassInitialized(ConfigurableClassInitialization.java:178)
	... 10 more
Caused by: java.lang.UnsupportedClassVersionError: com/oracle/svm/core/jdk/Target_java_lang_Module has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 14 more
[js:19332]      [total]:   2,089.44 ms,  2.23 GB

@ivan-ristovic
Copy link
Contributor Author

Locally this now passes, hope there are no issues on EE as well.

@olpaw
Copy link
Member

olpaw commented Aug 16, 2021

@ivan-ristovic , rerunning in our CI now ...

@olpaw
Copy link
Member

olpaw commented Aug 16, 2021

@ivan-ristovic CI results look better now but I see failing JDK16 gates. E.g.

[libpolyglot:26726]    classlist:   7,958.01 ms,  1.20 GB
[libpolyglot:26726]        setup:     977.05 ms,  1.20 GB
Error: Could not find target method: private static void com.oracle.svm.core.jdk11.Target_java_lang_Module_JDK11OrLater.defineModule0(java.lang.Module,boolean,java.lang.String,java.lang.String,java.lang.String[])
com.oracle.svm.core.util.UserError$UserException: Could not find target method: private static void com.oracle.svm.core.jdk11.Target_java_lang_Module_JDK11OrLater.defineModule0(java.lang.Module,boolean,java.lang.String,java.lang.String,java.lang.String[])
	at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findOriginalMethod(AnnotationSubstitutionProcessor.java:736)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleMethodInAliasClass(AnnotationSubstitutionProcessor.java:368)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleAliasClass(AnnotationSubstitutionProcessor.java:340)
[libpolyglot:26726]      [total]:   9,025.46 ms,  1.20 GB
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:310)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:266)
	at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:944)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:873)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:531)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:492)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:400)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:566)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:596)
# Printing build artifacts to: /b/b/e/graal/sdk/mxbuild/linux-amd64/libpolyglot.so.image/libpolyglot.build_artifacts.txt

You should be able to reproduce that easily by setting JAVA_HOME to a JDK-16 and trying to build e.g. libpolyglot (use mx native-image --macro:polyglot-library in substratevm).

@olpaw
Copy link
Member

olpaw commented Aug 17, 2021

@ivan-ristovic, to get rid of the Fatal error:com.oracle.svm.util.ReflectionUtil$ReflectionUtilError: java.lang.NoSuchFieldException: classLoaderValueMap errors I suggest adding

===================================================================
diff --git a/substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/ModuleLayerFeature.java b/substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/ModuleLayerFeature.java
--- a/substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/ModuleLayerFeature.java	(revision Staged)
+++ b/substratevm/src/com.oracle.svm.hosted.jdk11/src/com/oracle/svm/hosted/ModuleLayerFeature.java	(date 1629218976138)
@@ -95,7 +95,7 @@
 
     @Override
     public boolean isInConfiguration(IsInConfigurationAccess access) {
-        return new JDK11OrLater().getAsBoolean();
+        return new JDK11OrLater().getAsBoolean() && ModuleLayer.boot().findModule("org.graalvm.nativeimage.builder").isPresent();
     }
 
     @Override

so that the code in ModuleLayerFeature#beforeAnalysis that is problematic for JDK16 will never get run if we are not running the image builder on the module-path.

@ivan-ristovic
Copy link
Contributor Author

Excellent idea, added!

@olpaw
Copy link
Member

olpaw commented Aug 25, 2021

After @ivan-ristovic and @gradinac found another case of a missing registerAsInHeap we are switching to a different approach:

  • Start analysis with prototype bootlayer then switch to real runtime-bootlayer after analysis.

ivan-ristovic added 6 commits August 25, 2021 10:12
Add hellomodule gate

Restrict access to Module$ReflectionData

Remove unnececary overlay for BootModuleLayerSupport

Synthesize boot layer in a safer way
Substitute native methods of the Module class

Fix boot layer configuration resolving

Expand `mx hellomodule` with more boot layer tests
Implement checks inside Module native methods

Calculate boot layer once after analysis

Implement module/package checks in runtime for `defineModule0`
Update overlays related to module system

Specific `defineModule0` implementation for JDK16

Add dependency to `com.oracle.svm.core.jdk11` from `com.oracle.svm.core.jdk15`
@olpaw
Copy link
Member

olpaw commented Aug 25, 2021

... running in internal CI now. @ivan-ristovic @gradinac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants