RFR: 8291065: Creating a VarHandle for a static field triggers class initialization [v5]
Paul Sandoz
psandoz at openjdk.org
Fri Jun 2 18:46:10 UTC 2023
On Fri, 2 Jun 2023 17:16:09 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> > I think we only need to initialize Parent without initializing Child in this case.
>
> The bytecode behavior to access the field via `lookup.findStaticVarHandle(Child.class, "value", int[].class)` is `Child.value;`. The class or interface that declared the resolved field is initialized per JVMS `getStatic` and `putStatic`. So I think `Parent` is initialized but not `Child`. @PaulSandoz can confirm.
Yes, confirmed (verified both with explicit field access, `Child.value`, and access using a direct method handle).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13821#issuecomment-1574162809
More information about the core-libs-dev
mailing list