couple questions on method handle combinators

Paul Sandoz paul.sandoz at oracle.com
Tue Jun 13 21:37:52 UTC 2017


> On 13 Jun 2017, at 08:39, Roland Westrelin <rwestrel at redhat.com> wrote:
> 
> 
>> Below is a simple test class. Unfortunately running this crashes the VM.
> 

Thanks for fixing HS, the test works for me now.


> Thanks for putting the test together. C2 fails to inline much of
> anything...
> 
>   2131  126             GWTTest::run_Q_helper (16 bytes)
>                            @ 10   java.lang.invoke.LambdaForm$MH/499105359::invoke_MT (28 bytes)   force inline by annotation
>                              @ 9   java.lang.invoke.Invokers::checkGenericType (6 bytes)   force inline by annotation
>                                @ 2   java.lang.invoke.MethodHandle::asType (28 bytes)   inline (hot)
>                                  @ 12   java.lang.invoke.MethodHandle::asTypeCached (21 bytes)   inline (hot)
>                                  @ 24   java.lang.invoke.MethodHandle::asTypeUncached (59 bytes)   too big
>                              @ 16   java.lang.invoke.Invokers::checkCustomized (23 bytes)   force inline by annotation
>                                @ 1   java.lang.invoke.MethodHandleImpl::isCompileConstant (2 bytes)   (intrinsic)
>                                @ 19   java.lang.invoke.Invokers::maybeCustomize (28 bytes)   don't inline by annotation
>                              @ 24   java.lang.invoke.MethodHandle::invokeBasic(LLI)L (0 bytes)   receiver not constant
> 

The is due to the call to invoke, which performs an asType transformation and thus the receiver is not constant.

Same happens for L-based test, which if i change to use invokeExact (or a method sig that exactly matches the target) then inlining works:

   1174  121 %           GWTTest::run_L @ 4 (39 bytes)
                            @ 1   java.lang.invoke.MethodHandle::type (5 bytes)   accessor
                            @ 20   java.lang.invoke.LambdaForm$MH020/2053442577::invokeExact_MT000_LLLIL_L (26 bytes)   force inline by annotation
                              @ 11   java.lang.invoke.Invokers::checkExactType (17 bytes)   force inline by annotation
                                @ 1   java.lang.invoke.MethodHandle::type (5 bytes)   accessor
                              @ 15   java.lang.invoke.Invokers::checkCustomized (23 bytes)   force inline by annotation
                                @ 1   java.lang.invoke.MethodHandleImpl::isCompileConstant (2 bytes)   (intrinsic)
                              @ 22   java.lang.invoke.LambdaForm$MH021/731128490::guard001_LLLI_L (114 bytes)   force inline by annotation
                                @ 7   java.lang.invoke.MethodHandleImpl::assertSame (49 bytes)   inline (hot)
                                @ 48   java.lang.invoke.LambdaForm$MH013/372289727::invoke010_LLLI_I (18 bytes)   force inline by annotation
                                  @ 14   java.lang.invoke.DirectMethodHandle$Holder::invokeStatic (13 bytes)   force inline by annotation
                                    @ 1   java.lang.invoke.DirectMethodHandle::internalMemberName (8 bytes)   force inline by annotation
                                    @ 9   GWTTest::test (2 bytes)   inline (hot)
               !                @ 62   java.lang.invoke.MethodHandleImpl::profileBoolean (34 bytes)   (intrinsic)
                                @ 110   java.lang.invoke.DelegatingMethodHandle$Holder::delegate (21 bytes)   force inline by annotation
                                  @ 4   java.lang.invoke.MethodHandleImpl$CountingWrapper::getTarget (5 bytes)   accessor
                                  @ 17   java.lang.invoke.LambdaForm$MH017/606100753::invoke012_LLLI_L (20 bytes)   force inline by annotation
                                    @ 16   java.lang.invoke.DirectMethodHandle$Holder::invokeStatic (15 bytes)   force inline by annotation
                                      @ 1   java.lang.invoke.DirectMethodHandle::internalMemberName (8 bytes)   force inline by annotation
                                      @ 11   java.lang.invoke.MethodHandleImpl$ArrayAccessor::getElementL (4 bytes)   inline (hot)


The Q-based GWT form does not appear to show up in C2 compilation.

Furthermore, the L-based GWT code generation has an intrinsic for byte code inlining the select alternative (including annotating the method with InjectedProfile).  The Q-based code generator needs parity with such intrinsics. So even if we get to the point of getting better compilation behaviour we may run into other problems.

I’ll poke around some more...
Paul.

> with:
> 
>    static V run_Q_helper() throws Throwable {
>        V v = (V) Q_MH_GWT.invoke(Q_V1_ARRAY, Q_V2_ARRAY, 0);
>        return v;
>    }
> 
>    static int run_Q() throws Throwable {
>        int sum = 0;
>        for (int i = 0; i < 100_000; i++) {
>            V v = run_Q_helper();
>            sum += v.x;
>        }
>        return sum;
>    }
> 
> Roland.




More information about the valhalla-dev mailing list