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

Quan Anh Mai qamai at openjdk.org
Thu Dec 18 16:49:25 UTC 2025


On Thu, 18 Dec 2025 16:25:29 GMT, Chen Liang <liach at openjdk.org> wrote:

>> 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.
>
>> 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.
> 
> No. We currently cannot enforce such final fields to be all written before the `Object::<init>` entry, and I also don't think mainline has this safe publication fence at the beginning of `Object::<init>` either.

@liach I don't think we need such a condition, we only need to ensure that the fields are not read from and the object does not escape to memory before the termination of `<init>`.

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

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


More information about the core-libs-dev mailing list