On Tue, 16 Jun 2026 22:38:14 GMT, Chen Liang <[email protected]> wrote:

>> src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 3964:
>> 
>>> 3962:             }
>>> 3963:             return VarHandles.makeFieldHandle(getField, refc,
>>> 3964:                                               this.allowedModes == 
>>> TRUSTED);
>> 
>> Is this no longer needed? Are all trusted final fields strict init now?
>
> No, I moved this check to the beginning of `VarHandles.makeFieldHandle` so 
> IMPL_LOOKUP cannot create strict-final writing VarHandle instances:
> 
> 
> boolean noWriting = f.isFinal() && (!trusted || f.isStrictInit());

Right, but are `isStrictInit` and `isTrustedFinalField` equivalent now? The 
latter also seems to include non-strict `static final` fields for instance. 

The latter is set by the VM when resolving the member name based on the 
criteria at 
[1](https://github.com/openjdk/valhalla/blob/ce9ae1864dd19e0dd88ba2b65e8828936df01508/src/hotspot/share/runtime/fieldDescriptor.cpp#L46).

Shouldn't it be:


boolean noWriting = f.isFinal() && (!trusted || f.isStrictInit() || 
f.isTrustedFinalField());


This would exclude `IMPL_LOOKUP` from creating var handles that can write to 
trusted finals as it does now.

`MethodHandles::unreflectField` also still uses `isTrustedFinalField`.

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2550#discussion_r3428203862

Reply via email to