RFR: 8291065: Creating a VarHandle for a static field triggers class initialization [v3]
Chen Liang
liach at openjdk.org
Thu Jun 1 21:26:27 UTC 2023
On Thu, 1 Jun 2023 19:39:27 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> As for the implementation of `LazyStaticVarHandle`, I expect that `makeFieldHandle` can always create the direct var handle (i.e. `FieldStaticReadXXX` var handle) and then wrapped by `LazyStaticVarHandle` similar to how `IndirectVarHandle` does;
Since I am not familiar with hotspot internals, I assumed that staticFieldBase and staticFieldOffset shouldn't be used until the class is initialized (rather than linked). This for certain can be done if they are ready once a class is linked, and we should probably update unsafe's comment as well. Can you confirm that they staticFieldBase/Offset are safe to be called before initialization?
If this change is safe, we can significantly reduce the initial-call overhead of the lazy VH significantly as well.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13821#issuecomment-1572801392
More information about the core-libs-dev
mailing list