-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[GR-62940] API for dynamic-access registration based on access conditions #11075
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
Open
graalvmbot
wants to merge
5
commits into
master
Choose a base branch
from
mm/GR-62940-new-API-for-metadata-registration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
caafa0a
to
21d1b60
Compare
c56713c
to
b759354
Compare
9df5a56
to
f95421a
Compare
7be6081
to
c149086
Compare
65fbdc3
to
409b6c4
Compare
9351a95
to
778f204
Compare
2d139dd
to
0a84886
Compare
a44fe0e
to
ac60b06
Compare
ac60b06
to
b88862f
Compare
3493105
to
8472517
Compare
b590846
to
faacfaf
Compare
faacfaf
to
471bfd5
Compare
471bfd5
to
e8e79ed
Compare
02f862f
to
f9e6cd4
Compare
7473039
to
55b2e97
Compare
ConfigurationCondition is divided into AccessCondition(API) and TypeReachabilityCondition(implementation). Replaced all usages of ConfigurationCondition.
55b2e97
to
ba933e2
Compare
ba933e2
to
7c78f1a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
The current API for dynamic-access registration supports conditional registrations only through reachability handlers. This means that the program semantics (i.e., if something is registered or not) depends on the results of static analysis.
Since static analysis are not deterministic (affected by the classpath, compiler optimizations, usage layers or not) and not available in regular Java execution, we want to move away from the analysis results as the driver of semantics.
In addition, the current dynamic-access registration API was built for fine-grained reflection which is unnecessarily complex. Take, for example, the code needed to register all metadata for a single type:
The revised API
This PR introduces a simplified API for metadata registration based on conditions, that has similar semantics as
reachability-metadata.json
. The key differences of the revised API are:Each method in the new API takes a
AccessCondition
as its first argument. Conditions for programmatic metadata registration are explained in the Access Condition documentation.The API should be independent of Native Image as we want to be able to use it in Crema. Therefore, it can be used only during
Feature#afterRegistration
as this phase of the Feature API is Native Image agnostic. Any attempt to register metadata afterFeature#afterRegistration
throws an error.The users acquire an instance of the revised API via getter methods on
Feature#AfterRegistrationAccess
. This guides the users to use the feature duringFeature#afterRegistration
.Similarly to
reachability-metadata.json
, the all reflection registrations of individual elements (e.g., methods and fields) also register the declaring class metadata.Naming decisions
hosted
to the newdynamicaccess
package.Access
:ReflectiveAccess
,ResourceAccess
,ForeignAccess
,JNIAccess
.AccessCondition
, as they guard access at run time.AccessCondition
isunconditional
.Examples
An example of Micronaut internal feature adapted to the new API
Deprecation of current API
The existing API (e.g,
RuntimeReflection
,RuntimeResourceAccess
,RuntimeSerialization
, etc.) for metadata registration will remain available during a transition to the revised API. Therefore we are introducing an optional flagTrackDeprecatedRegistationUsage
that emits runtime warnings when the legacy API is invoked, enabling developers to identify and remove deprecated usage.