RFC [GR-57608] Support --enable-native-access hosted option in native image #10076
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for the
--enable-native-access
hosted option in the context of JEP 472: Prepare to Restrict the Use of JNI. The modules specified by this flags will be allowed to perform native access at run time. Note that similar to Hotspot, this flag only applied to the boot layer.This change aligns the native access checks in native image to those in the JDK as outline in JEP 472.
Implementation Notes
To allow constant folding of native access checks at build time, the following optimizations are needed:
DynamicHub#module
with@Stable
. This now matches theClass@module
definition.Module.EnableNativeAccess#isNativeAccessEnabled
constant folds ifModule#enableNativeAccess
field istrue
. This "reimplements" the@Stable
field optimization forModule#enablenativeAccess
, which does not trigger because the field is only accessed viaUnsafe
.