On Tue, 16 Jun 2026 19:20:24 GMT, Jorn Vernee <[email protected]> wrote:

>> Chen Liang has updated the pull request with a new target base due to a 
>> merge or a rebase. The incremental webrev excludes the unrelated changes 
>> brought in by the merge/rebase. The pull request contains three additional 
>> commits since the last revision:
>> 
>>  - Restrict write access for IMPL_LOOKUP VH on strict final
>>  - Merge branch 'lworld' of https://github.com/openjdk/valhalla into 
>> fix/lw-strict-static-vh
>>  - Missing strict static validation for VarHandle
>
> src/java.base/share/classes/java/lang/invoke/LazyInitializingVarHandle.java 
> line 72:
> 
>> 70:     VarHandle target() {
>> 71:         ensureInitialized();
>> 72:         return target;
> 
> What about static method access? `onStaticFieldAccess` seems to be only used 
> for field access, and the regular access to the target seems to skip the 
> `ensureInitialized` check now.

`target` is completely eliminated now. `IndirectVarHandle` uses `asDirect` 
before passing a VH to the implementation MH; `LazyInitializingVarHandle` uses 
`onStaticFieldAccess` or old `target` once you are within the implementation 
MH/MemberName, so the two mechanisms were quite different and better separated. 
All other VHs don't need this class initialization barrier.

> 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());

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

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

Reply via email to