On Thu, 27 Nov 2025 16:16:05 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.

This pull request has now been integrated.

Changeset: 3220c4cb
Author:    Chen Liang <[email protected]>
URL:       
https://git.openjdk.org/jdk/commit/3220c4cb431a2c4eb8bb2d60f0d5046e40af69bd
Stats:     168 lines in 13 files changed: 154 ins; 13 del; 1 mod

8372696: Allow boot classes to explicitly opt-in for final field trusting

Reviewed-by: jvernee, jrose, alanb

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

PR: https://git.openjdk.org/jdk/pull/28540

Reply via email to