-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8372696: Allow boot classes to explicitly opt-in for final field trusting #28540
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back liach! A progress list of the required criteria for merging this PR into |
|
@liach This change is no longer ready for integration - check the PR body for details. |
Webrevs
|
|
/cc hotspot-compiler hotspot-runtime This uses another one of the 16-bit instanceKlassFlags, which requires runtime engineers to agree. Need compiler review to check if such IR tests are the best way to ensure constant folding for core library classes. |
|
@liach The |
JornVernee
left a comment
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.
/reviewers 2
|
@JornVernee |
src/java.base/share/classes/jdk/internal/vm/annotation/TrustFinalFields.java
Outdated
Show resolved
Hide resolved
|
I really like this one! I wonder if we could enable the new annotation Is there a better way to do it? |
The VM doesn't read/parse the package-info class. They are only read by APIs that want to get annotations. In any case, the long term goal needs to be to remove all special handling. |
src/java.base/share/classes/jdk/internal/vm/annotation/TrustFinalFields.java
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,128 @@ | |||
| Constant Folding in the Hotspot Compiler | |||
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.
I assume any write-up of HotSpot constant folding should move into src/hotspot tree, maybe a block comment in one of the source files?
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.
I intend this to be a user-oriented guide on constant folding. I should just call it constant folding.
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.
I intend this to be a user-oriented guide on constant folding. I should just call it constant folding.
| `ciField`, so an inherited field in a subclass or subinterface shares the | ||
| `trustedFinal` setting. | ||
|
|
||
| ### Make Final Mean Final |
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.
I think you can drop this section for now. It's okay to reference JEP 500 but it will be annoying to have to maintain this text as there are many steps to follow this one.
coleenp
left a comment
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.
With one small change, the runtime part of this change looks good.
src/hotspot/share/ci/ciField.cpp
Outdated
| if (holder == nullptr) | ||
| return false; | ||
| // Explicit opt-in from system classes | ||
| if (holder->trust_final_fields()) |
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 missing { } so not sure where it ends, especially that it encloses an if statement, and other code.
|
A bit of meta-question about this PR and JEP 500: does this trust need to be rescinded if the user explicitly adds |
|
This PR currently does not interact with JEP 500. However, as specified in In addition, @DanHeidinga I made the same fault as you when I first saw |
Currently, the hotspot compiler (as in ciField) trusts final fields in hidden classes, record classes, and selected jdk packages. Some classes in the JDK wish to be trusted, but they cannot apply package-wide opt-in due to other legacy classes in the package, such as java.util.
They currently can use
@Stableas a workaround, but this is fragile because a stable final field may hold a trusted null, zero, or false value, which is currently treated as non-constant by ciField.We should add an annotation to opt-in for a whole class, mainly for legacy packages. This would benefit greatly some of our classes already using a lot of Stable, such as java.util.Optional, whose empty instance is now constant-foldable, as demonstrated in a new IR test.
Paging @minborg who requested Optional folding for review.
I think we can remove redundant Stable in a few other java.util classes after this patch is integrated. I plan to do that in subsequent patches.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28540/head:pull/28540$ git checkout pull/28540Update a local copy of the PR:
$ git checkout pull/28540$ git pull https://git.openjdk.org/jdk.git pull/28540/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28540View PR using the GUI difftool:
$ git pr show -t 28540Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28540.diff
Using Webrev
Link to Webrev Comment