MethodHandleBuilder bug?

Roland Westrelin rwestrel at redhat.com
Thu Apr 12 14:37:51 UTC 2018


I noticed that this:

    private static final MethodHandle mergeNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
        "mergeNull",
        MethodType.methodType(void.class, TestLWorld.class, boolean.class),
        CODE -> {
            CODE.
            iload_1().
            iconst_0().
            ifcmp(TypeTag.I, CondKind.EQ, "null").
            aload_0().
            getfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
            goto_("continue").
            label("null").
            aconst_null().
            label("continue").
            aload_0().
            swap().
            putfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
            return_();
        }
        );

works fine but if I swap the code in the if branches:

    private static final MethodHandle mergeNull = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
        "mergeNull",
        MethodType.methodType(void.class, TestLWorld.class, boolean.class),
        CODE -> {
            CODE.
            iload_1().
            iconst_0().
            ifcmp(TypeTag.I, CondKind.EQ, "null").
            aconst_null().
            goto_("continue").
            label("null").
            aload_0().
            getfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
            label("continue").
            aload_0().
            swap().
            putfield(TestLWorld.class, "valueField1", "Lcompiler/valhalla/valuetypes/MyValue1;").
            return_();
        }
        );

then I get:

java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:115)
        at java.base/java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.IllegalStateException: Bad type: <null>
        at java.base/jdk.experimental.bytecode.BasicTypeHelper.tag(BasicTypeHelper.java:76)
        at java.base/jdk.experimental.value.MethodHandleBuilder$IsolatedMethodBuilder$IsolatedMethodTypeHelper.tag(MethodHandleBuilder.java:196)
        at java.base/jdk.experimental.value.MethodHandleBuilder$IsolatedMethodBuilder$IsolatedMethodTypeHelper.tag(MethodHandleBuilder.java:138)
        at java.base/jdk.experimental.bytecode.CodeBuilder.writeStackMapType(CodeBuilder.java:1257)
        at java.base/jdk.experimental.bytecode.CodeBuilder.sameLocals1StackItemFrame(CodeBuilder.java:1305)
        at java.base/jdk.experimental.bytecode.TypedCodeBuilder.writeStackMapFrame(TypedCodeBuilder.java:1231)
        at java.base/jdk.experimental.bytecode.TypedCodeBuilder.emitStackMap(TypedCodeBuilder.java:1196)
        at java.base/jdk.experimental.bytecode.TypedCodeBuilder.resolveJumps(TypedCodeBuilder.java:1189)
        at java.base/jdk.experimental.bytecode.MacroCodeBuilder.label(MacroCodeBuilder.java:437)
        at compiler.valhalla.valuetypes.TestLWorld.lambda$static$3(TestLWorld.java:505)
        at java.base/jdk.experimental.bytecode.MethodBuilder.withCode(MethodBuilder.java:50)
        at java.base/jdk.experimental.value.MethodHandleBuilder.lambda$loadCode$1(MethodHandleBuilder.java:101)
        at java.base/jdk.experimental.bytecode.ClassBuilder.withMethod(ClassBuilder.java:204)
        at java.base/jdk.experimental.value.MethodHandleBuilder.loadCode(MethodHandleBuilder.java:99)
        at java.base/jdk.experimental.value.MethodHandleBuilder.loadCode(MethodHandleBuilder.java:77)
        at java.base/jdk.experimental.value.MethodHandleBuilder.loadCode(MethodHandleBuilder.java:72)
        at compiler.valhalla.valuetypes.TestLWorld.<clinit>(TestLWorld.java:492)
        ... 6 more

Roland.


More information about the valhalla-dev mailing list