RFR: 8291065: Creating a VarHandle for a static field triggers class initialization [v5]
Paul Sandoz
psandoz at openjdk.org
Tue Jun 6 21:32:59 UTC 2023
On Fri, 2 Jun 2023 19:09:49 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> > I wonder if it is possible to transition from an lazy (indirect) VH to a direct VH once initialized i.e., `checkAccessModeThenIsDirect` returns the value of `initialized`.
>
> Sounds a good idea. Once the class is initialized, the lazy VH becomes a direct VH that may help the performance. In that case, the VarHandleGuards would need to ensure it links with the direct VH not the lazy VH.
I believe instead of changing the guards we can change the implementation of the static methods on the concrete static VHs to call `asDirect()` (lets also add `@ForceInline` on `asDirect`), since `linkToStatic` will pass the args to the static method described by the member name (since the lazy and direct VH handles share the same var form).
That has the nice effect of pushing the complexity closer to where it is needed. Its subtle but i think can be explained. Thereby we can reduce the memory footprint for subsequent access modes. Perhaps we can even "zero" out the MH cache on initialization?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13821#issuecomment-1579476316
More information about the core-libs-dev
mailing list