RFR: 8291065: Creating a VarHandle for a static field triggers class initialization [v7]
Chen Liang
liach at openjdk.org
Sat Jun 3 03:50:13 UTC 2023
On Sat, 3 Jun 2023 02:25:59 GMT, ExE Boss <duke at openjdk.org> wrote:
>> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Remove lazy init of MH, for all invocation of the Lazy VH needs this MH
>
> src/java.base/share/classes/java/lang/invoke/LazyInitializingVarHandle.java line 106:
>
>> 104: UNSAFE.ensureClassInitialized(refc);
>> 105: this.initialized = true;
>> 106: }
>
> This should probably have a fast‑path when `this.initialized` is `true`, so that it can be better constant folded by the **JIT**:
> Suggestion:
>
> private void ensureInitialized() {
> if (this.initialized) {
> return;
> }
> UNSAFE.ensureClassInitialized(refc);
> this.initialized = true;
> }
I think I should probably update the MH lambda form as well, to skip the ensure call entirely if JVM has not constant-fold the inefficient form yet.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13821#discussion_r1215184529
More information about the core-libs-dev
mailing list