RFR: 8291065: Creating a VarHandle for a static field triggers class initialization [v5]

Paul Sandoz psandoz at openjdk.org
Thu Jun 8 00:15:51 UTC 2023


On Wed, 7 Jun 2023 22:38:29 GMT, Chen Liang <liach at openjdk.org> wrote:

> > Change only the static field var handle implementations to call `target()`, since it is unnecessary on the others.
> 
> Unfortunately, I don't think there is a convenient way for VH implementations to easily unwrap the correct VH; a `target()` call is more convenient than an extra instanceof check and cast and get.
> 

We don't need to update *all* VH implementations to call target. We only need to update the static field VH implementations which we know may be passed an instance of `LazyInitializingVarHandle` or its concrete instance.


> > I am wondering if the simplest approach in `initialize` is to set the `methodHandleTable` to null?
> 
> I update the entries in the table because they are already created and potentially live on the heap or stack. Those entries should benefit from the post-initialization performance benefits as well.

Ok, yes, it's less likely now but possible a MH has been explicitly obtained before the defining class has been intialized. In this case I still think we can clear the table out after processing any existing entries, since subsequent requests for MHs after initialization will defer to the target's method handle table.

We will need some tests covering this edge case.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13821#issuecomment-1581684274


More information about the core-libs-dev mailing list