RFR: 8372696: Allow boot classes to explicitly opt-in for final field trusting [v2]
Alan Bateman
alanb at openjdk.org
Sun Nov 30 07:51:51 UTC 2025
On Sun, 30 Nov 2025 05:24:43 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 incrementally with one additional commit since the last revision:
>
> Essay
src/java.base/share/classes/jdk/internal/vm/annotation/constant-folding.md line 1:
> 1: Constant Folding in the Hotspot Compiler
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?
src/java.base/share/classes/jdk/internal/vm/annotation/constant-folding.md line 106:
> 104: `trustedFinal` setting.
> 105:
> 106: ### Make Final Mean Final
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2573492977
PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2573493426
More information about the hotspot-dev
mailing list