RFR: 8160821: VarHandle accesses are penalized when argument conversion is required [v3]
Chen Liang
liach at openjdk.org
Mon Dec 8 02:08:37 UTC 2025
On Wed, 3 Dec 2025 13:34:40 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> 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.
This issue should have been fixed, and there's a unit test to verify.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28585#discussion_r2596829589
More information about the hotspot-compiler-dev
mailing list