On Fri, 8 Apr 2022 12:20:32 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> A few additional enhancements aiming to improve VH performance in the >> interpreter: >> >> - Flatten `TypeAndInvokers`: adds a pointer to `VarHandle` (a small increase >> 40->48) but removes an object and an indirection on any instance actually >> used - and might avoid allocating the `MethodHandle[]` unnecessarily on some >> instances >> - Have `checkExactAccessMode` return the directness of the `VarHandle` so >> that we can avoid some `isDirect` method calls. >> >> Baseline, `-Xint` >> >> Benchmark Mode Cnt Score Error Units >> VarHandleExact.exact_exactInvocation avgt 30 478.324 ? 5.762 ns/op >> VarHandleExact.generic_exactInvocation avgt 30 392.114 ? 1.644 ns/op >> VarHandleExact.generic_genericInvocation avgt 30 822.484 ? 1.865 ns/op >> >> >> Patched, `-Xint` >> >> Benchmark Mode Cnt Score Error Units >> VarHandleExact.exact_exactInvocation avgt 30 437.704 ? 5.320 ns/op >> VarHandleExact.generic_exactInvocation avgt 30 374.512 ? 3.154 ns/op >> VarHandleExact.generic_genericInvocation avgt 30 757.054 ? 1.237 ns/op >> >> >> No significant performance difference in normal mode. > > Claes Redestad has updated the pull request incrementally with one additional > commit since the last revision: > > Simplified as suggested by @ExE-Boss How would the performance change if the `isDirect` and `checkExactAccessMode` merger was reverted? src/java.base/share/classes/java/lang/invoke/VarHandle.java line 2075: > 2073: > 2074: @DontInline > 2075: final void throwWrongMethodTypeException(VarHandle.AccessDescriptor > ad) { This can actually be `private` and `static`: Suggestion: private static final void throwWrongMethodTypeException(VarHandle.AccessDescriptor ad) { src/java.base/share/classes/java/lang/invoke/VarHandles.java line 719: > 717: // > MethodHandle.linkToStatic(<LINK_TO_STATIC_ARGS>); > 718: // } else { > 719: // MethodHandle mh = > handle.getMethodHandle(ad.mode); The `direct`‑ness check can be hoisted into an enclosing `if` statement: Suggestion: // if (direct) { // if (handle.vform.methodType_table[ad.type] == ad.symbolicMethodTypeErased) { // MethodHandle.linkToStatic(<LINK_TO_STATIC_ARGS>); // return; // } else if (handle.vform.getMethodType_V(ad.type) == ad.symbolicMethodTypeErased) { // MethodHandle.linkToStatic(<LINK_TO_STATIC_ARGS>); // return; // } // } // MethodHandle mh = handle.getMethodHandle(ad.mode); Also, any reason `GUARD_METHOD_TEMPLATE_V` uses `LINK_TO_STATIC_ARGS` instead of `LINK_TO_STATIC_ARGS_V`? ------------- PR: https://git.openjdk.java.net/jdk/pull/8160