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

Jaikiran Pai jpai at openjdk.org
Fri Nov 28 13:38:47 UTC 2025


On Fri, 28 Nov 2025 13:30:33 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

>> For this PR then you could just change the last sentence to say that the annotation is only effective for classes defined by the boot class loader or platform class loader. A follow-up PR could propose changes to the other annotation descriptions.
>> 
>> As regards background then one of the significant changes in JDK 9 was that java.* modules could be mapped to the platform class loader without give them "all permission" in the security manager execution mode. If you see JBS issues or comments speaking of "de-privileging" then it's likely related to changes that "moved" modules that were originally mapped to the boot class loader to the platform class loader. Now that the security manager execution mode is gone then we don't have to deal with all these issues now.
>
> Hello Chen, should this annotation also mention what happens if a class annotated with `@TrustFinalFields` has any of its `final` fields updated? For example, `@Stable` has this to say about such unexpected updates:
> 
> 
> ...It is in general a bad idea to reset such
> * variables to any other value, since compiled code might have folded
> * an earlier stored value, and will never detect the reset value.
> 
> 
> Are there any unexpected consequences of marking a class as `@TrustFinalFields` and having a `@Stable` on any of the final fields (for example an array):
> 
> 
> @TrustedFinalFields
> class JDKFooBar {
>     private final String reallyFinal;
> 
>     @Stable
>     private final int reallyFinalButAlsoStable;
> 
>     @Stable
>     private final long[] finalAndStableArray;
> 
> }
> 
> Finally, would it still be recommended that a class annotated with `@TrustFinalFields` also have a final array field annoted with `@Stable` if that array field elements are initialized to a non-default value only once?

One another question - if a class/interface is annotated with `@TargetFinalFields`, is that annotation only applicable to that specific class or would it also be applicable for any (final fields in) subclasses of that class or implementations of that interface (does the VM ignore this annotation on an interface, should it)?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28540#discussion_r2571717831


More information about the hotspot-dev mailing list