RFR: 8291065: Creating a VarHandle for a static field triggers class initialization
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri May 5 13:15:16 UTC 2023
On Fri, 5 May 2023 13:03:14 GMT, Chen Liang <liach at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java line 74:
>>
>>> 72: @Override
>>> 73: public boolean isAccessModeSupported(AccessMode accessMode) {
>>> 74: var directTarget = this.directTarget;
>>
>> Why is this not defined in the superclass, and then use `asDirect` (as done in other cases) ?
>
> I aim to avoid eager evaluation of directTarget (which is lazy in LazyStaticVarHandle, computing it requires initializing the holder class). This code path checks a stable field, so it should allow constant-folding when the direct target is available.
I see - so, since this is just a "query" you would like to avoid initialization just for this.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13821#discussion_r1186079374
More information about the core-libs-dev
mailing list