RFR: 8160821: VarHandle accesses are penalized when argument conversion is required [v3]

Jorn Vernee jvernee at openjdk.org
Wed Dec 3 13:37:54 UTC 2025


On Wed, 3 Dec 2025 13:23:18 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>>> any captured adaptation is valid/compatible
>> 
>> Yes, if `vh` is a constant, any captured adaptation from `vh.getMethodHandle(mode).asType(symbolicMethodTypeInvoker)` is valid/compatible.
>> 
>> For thread safety, MethodHandle supports safe publication, so I think we are fine publishing this way.
>
> Looking at this, I'm not sure we can assume that we only see one mode and type when the VH is constant. There seems to be a lot of non-local reasoning involved.
> 
> For example, you could have a var handle invoker created with `MethodHandless::varHandleInvoker`, which is cached, so the `AccessDescriptor` can be shared among many different use sites. For an individual use-site, the receiver VH may well be a constant, but that doesn't mean that the cache isn't polluted by the var handle from another use site, as far as I can tell.
> 
> The thread safety issue comes from a C2 thread racing to read the `lastAdaption` cache vs another Java thread writing to the cache. AFAICS, this race is still possible even when `vh` is a compile time constant.

I think even without using an invoker, you could end up in a similar situation if you have something like:


static Object m(VarHandle vh) {
    return vh.get();
}


Which is called by several different threads. At some point this method may be inlined into one of its callees, where `vh` then becomes a constant. But at the same time, other threads are still writing to the cache.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28585#discussion_r2585142665


More information about the hotspot-compiler-dev mailing list