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-60088] Add jdk.graal.nativeimage module. #10380

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Dec 23, 2024

This PR adds the jdk.graal.nativeimage module. This provides a stable API for use by libgraal that is an extension to the standard Native Image API (i.e., the org.graalvm.nativeimage** packages here). Using this extended API, LibGraalFeature.java has been moved into compiler/, out of substratevm/. It no longer depends on Native Image internals, allowing any GraalVM binary that supports jdk.graal.nativeimage to be used as a tool for building libgraal. This is a step towards Project Galahad.

Over time, some or all of jdk.graal.nativeimage may be moved into org.graalvm.nativeimage. This is a discussion to be had in follow-up PRs.

The API changes can most easily been seen here:

A large part of the code changes comes from the fact that LibGraalFeature itself is now loaded in the LibGraalClassLoader which is separate from the Native Image class loader. This means the use of method handles to communicate between the "hosted" parts of libgraal (those loaded by the Native Image class loader) and the "guest" parts of libgraal has been removed. This is a large code reduction and makes the logic much easier to follow. It also means no more need for @NativeImageReinitialize as the Graal classes loaded for compiling into libgraal are different from those loaded to do the compilation and thus no longer need re-initializing.

Other changes of note:

  • The output of -Djdk.graal.ShowConfiguration=info has changed (and improved) slightly to also show the SVM GC algorithm used in libgraal.
    Before: Using "Graal Enterprise compiler with Truffle extensions" loaded from a PGO optimized Native Image shared library
    After: Using "Graal Enterprise compiler with Truffle extensions" loaded from a Native Image shared library (PGO optimized, gc=Serial GC)
  • Using jargraal on the --upgrade-module-path to accelerate Truffle now needs 2 extra jars: graal-nativeimage.jar and nativebridge.jar. This will be made clearer when pom.xml for the graal-js Maven demo is subsequently updated by @tzezula .
  • The ugly and confusing FoldNodePlugin class will be deleted once [GR-60866] Use plugin class name to filter fold plugin application #10447 is merged. Ignore it.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 23, 2024
@graalvmbot graalvmbot force-pushed the ds/GR-60088 branch 13 times, most recently from a229752 to aeed0d5 Compare December 29, 2024 15:12
@graalvmbot graalvmbot force-pushed the ds/GR-60088 branch 4 times, most recently from 52e529a to 2f4508a Compare January 7, 2025 14:14
@AutomaticallyRegisteredImageSingleton({VMRuntimeSupport.class, RuntimeSupport.class, LibGraalRuntimeSupport.class})
public final class RuntimeSupport implements VMRuntimeSupport, LibGraalRuntimeSupport {

@Override
Copy link
Member

Choose a reason for hiding this comment

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

I think you should move all these new methods to a separate libgraal-specific image singleton that implements LibGraalRuntimeSupport (for a normal native image, it does not make sense to use any of these methods).

Copy link
Member

Choose a reason for hiding this comment

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

Ok. Where would you suggest to put LibGraalRuntimeSupportImpl? In substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/libgraal/LibGraalRuntimeSupportImpl.java?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Member

Choose a reason for hiding this comment

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

Will do.

* RuntimeSystemProperties.register(NATIVE_IMAGE_SETTING_KEY_PREFIX + "gc", "serial");
* </pre>
*/
public static final String NATIVE_IMAGE_SETTING_KEY_PREFIX = "org.graalvm.nativeimage.setting.";
Copy link
Member

Choose a reason for hiding this comment

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

jdk.graal.compiler exports everything (*) to org.graalvm.nativeimage... which makes of course sense for hosted graal usage.

If I understand correctly, LibGraalFeature is guest graal only. I.e., org.graalvm.nativeimage... should not depend on it, or even have access to it, right? Otherwise, we might introduce dependencies from native image to a specific version of LibGraalFeature without noticing it.

Currently, we only access NATIVE_IMAGE_SETTING_KEY_PREFIX so not a problem. Still, would it make sense to separate it out LibGraalFeature to avoid problems?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds reasonable. Where would you suggest moving it to?

synchronized (LibGraalFeature.class) {
GraalError.guarantee(singleton == null, "only a single %s instance should be created", LibGraalFeature.class.getName());
singleton = this;
}
Copy link
Member

@zapster zapster Jan 10, 2025

Choose a reason for hiding this comment

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

could we move the singleton initialization into the static initializer of a private static inner class? that way we don't need to do a manual synchronize and the JVM guarantees us that there is only one initialization.

Copy link
Member

Choose a reason for hiding this comment

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

Can a feature be created and registered by some other means (e.g. search for static field or factory method) instead of by calling the default constructor? Based on my reading of com.oracle.svm.hosted.FeatureHandler#registerFeature I think the answer is no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants