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

Jorn Vernee jvernee at openjdk.org
Mon Dec 8 17:54:02 UTC 2025


On Mon, 8 Dec 2025 02:08:37 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Since access descriptor is created for each VH operation site, we can optimistically cache the adapted method handle in a site if the site operates on a constant VH.  Used a C2 IR test to verify such a setup through an inexact VarHandle invocation can be constant folded through (previously, it was blocked by `asType`)
>
> Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 15 additional commits since the last revision:
> 
>  - Bugs and verify loader leak
>  - Try to avoid loader leak
>  - Merge branch 'master' of https://github.com/openjdk/jdk into fix/vh-adapt-cache
>  - Revert void special case removal due to C2 shortage causing TestZGCBarrierElision::testAtomicThenAtomicAnotherField failure
>  - Test from Jorn
>  - Copyright years
>  - Fix problem identified by Jorn
>  - Rollback getAndAdd for now
>  - Redundant change
>  - Merge branch 'master' of https://github.com/openjdk/jdk into fix/vh-adapt-cache
>  - ... and 5 more: https://git.openjdk.org/jdk/compare/513d3327...eebb8ff7

src/java.base/share/classes/java/lang/invoke/IndirectVarHandle.java line 114:

> 112:         // but checking the signature type of MH mostly works
> 113:         return MethodHandle.isReachableFrom(vform.getMethodType(0), cl)
> 114:                 && target.isReachableFrom(cl);

Right... one of the filters may also keep a class loader alive. But to check them, we'd have to eagerly instantiate all of them as well.

FWIW, I don't think this is an issue we can just ignore. If a filter keeps a class loader alive, we'd still have a problem.

Maybe it's possible to collect all the types involved from the filter when creating an IndirectVarHandle instead, and save those in a separate list for this check.

src/java.base/share/classes/java/lang/invoke/MethodHandle.java line 983:

> 981:     }
> 982: 
> 983:     static boolean isBuiltinLoader(ClassLoader loader) {

I think this can still be private?

src/java.base/share/classes/java/lang/invoke/VarHandle.java line 2018:

> 2016:         // Call MethodHandle.isReachableFrom for the used classes
> 2017:         return true;
> 2018:     }

Can you make this `abstract`?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28585#discussion_r2599553053
PR Review Comment: https://git.openjdk.org/jdk/pull/28585#discussion_r2599496891
PR Review Comment: https://git.openjdk.org/jdk/pull/28585#discussion_r2599488329


More information about the core-libs-dev mailing list