On Thu, 18 Dec 2025 00:03:10 GMT, Chen Liang <[email protected]> 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:
> 
>   Move the test to a core library purposed directory

What I mean by stronger is that trusted final fields only ensure that their 
values are unchanged after initialization. Strict fields are unchanged 
unconditionally, there is only 1 observable state for a strict field of an 
object. As a result, in addition to constant folding, we can do load hoisting, 
too. So my question is why this annotation does not try to enforce a stronger 
invariant so that we can benefit from those invariants without having to wait 
for strict fields.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/28540#issuecomment-3668379612

Reply via email to