-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use new RuntimeResourceSupport public API with GraalVM >= 22.3 #27728
Conversation
The minimum supported GraalVM version is 21.3
Reduces the complexity of the NativeImageFeatureStep by invoking the equivalent helper method.
Drops dependency in GraalVM internal API
ae5f452
to
85da3b5
Compare
static final String LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.localization.LocalizationFeature"; | ||
static final String RUNTIME_RESOURCE_SUPPORT = "org.graalvm.nativeimage.impl.RuntimeResourceSupport"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zakkak I thought the public API is org.graalvm.nativeimage.hosted.RuntimeResourceAccess
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my understanding they are both public APIs that will be shipped in graal-sdk.
org.graalvm.nativeimage.hosted.RuntimeResourceAccess
is part of the org.graalvm.nativeimage.hosted
package and org.graalvm.nativeimage.impl.RuntimeResourceSupport
is part of the org.graalvm.nativeimage
package which are both included in graal-sdk.
The reason I went with RuntimeResourceSupport
instead of RuntimeResourceAccess
is that the former doesn't require to specify a module for the resources, and in Quarkus we are not using modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. When I see impl
in an API class it raises a red flag to me. While it's true RuntimeResourceSupport
doesn't require a module, we should get away with ClassLoader.getSystemClassLoader().getUnnamedModule()
and use the RuntimeResourceAccess
. In fact, RuntimeResourceAccess
uses RuntimeResourceSupport
which supports the idea that using the former will be a more robust solution. Also, you don't need to do the ImageSingleton
handling yourself and it's in line with what we do in #27690. Your mileage may vary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tough part is not about getting the unnamed module but getting the named module for JDK classes, e.g.
quarkus/core/deployment/src/main/java/io/quarkus/deployment/steps/ResourceBundleStep.java
Line 15 in 1f87a53
return new NativeImageResourceBundleBuildItem("sun.security.util.Resources"); |
Suggestions are welcome :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sun.security.util.Resources
is part of java.base
so how about? int.class.getModule()
The correct way is to use Foo.class.getModule()
of course, but you might have a chicken/egg problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an example, there are more such cases and while getting the module might not be that hard what makes it hard is the fact that we need to get the module in the generated native-image Feature
. So to make use of the RuntimeResourceAccess
we need to:
- Extend
NativeImageResourceBundleBuildItem
to contain information about the module - Generate the necessary code, using
gizmo
, to programmatically get that module and pass it toRuntimeResourceAccess
in the generated native-imageFeature
.
Since RuntimeResourceSupport
appears to be public API I don't see the need to do the above which will make the corresponding code even more complex.
As an alternative I believe that if we really don't want to use RuntimeResourceSupport
we should suggest the augmentation of RuntimeResourceAccess
to support registering resources without the module name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, I was wrong. org.graalvm.nativeimage.impl
is indeed not supposed to be public API. But we already open it in
quarkus/core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageFeatureStep.java
Lines 130 to 132 in 92fba0a
// required in order to access org.graalvm.nativeimage.impl.RuntimeSerializationSupport and org.graalvm.nativeimage.impl.ConfigurationCondition | |
features.produce( | |
new JPMSExportBuildItem("org.graalvm.sdk", "org.graalvm.nativeimage.impl", GraalVM.Version.VERSION_22_1_0)); |
I will need to prepare a follow up fix for this. Thanks for questioning this and making have another look @jerboaa!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zakkak Thanks for coming back to this! I was meaning to come back to this discussion, but it dropped on the floor (for me). Yes, we should revisit this. IMHO, there might be latent bugs by not passing in Modules resources belong to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP PR taking care of the above: #28093
Also:
Relates to #25943