RFR: 8372696: Allow boot classes to explicitly opt-in for final field trusting [v6]
John R Rose
jrose at openjdk.org
Tue Dec 16 20:35:17 UTC 2025
On Tue, 16 Dec 2025 18:54:34 GMT, Chen Liang <liach at openjdk.org> wrote:
>> 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 `@Stable` as 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.
>
> Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 14 additional commits since the last revision:
>
> - Recommended test tweaks
> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/class-final-trusting
> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/class-final-trusting
> - Jorn review
> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/class-final-trusting
> - bracket styles
> - Doc tweaks
> - Essay
> - Spurious change
> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/class-final-trusting
> - ... and 4 more: https://git.openjdk.org/jdk/compare/384c62c9...567e8925
Excellent. It does not pay down every bit of technical debt in this area, but it is a significant installment payment.
I think `constantFold` is OK as a directory name, although maybe a bit vague (folloing Jorn’s observations).
Perhaps `constantFields` or `fieldFolding`. Or (most specifically) `trustedFinalFields`, but I think that is unnecessarily narrow.
I suggest `fieldFolding` or `foldFields` or the like. The trusting logic is one way to fold fields, and also the forthcoming `ACC_STRICT_INIT`. There are also proposals to infer strictness in the absence of `ACC_STRICT_INIT`. All of those might have test cases associated with the tests for this feature.
We could expect several tests in here eventually, validating the folding properties of various flavors of constant fields.
-------------
Marked as reviewed by jrose (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/28540#pullrequestreview-3584835561
More information about the hotspot-dev
mailing list