MethodHandleBuilder bug?
Paul Sandoz
paul.sandoz at oracle.com
Thu Apr 12 21:25:40 UTC 2018
Try with the patch below.
I ain’t tested this throughly.
Paul.
diff -r 4d1e8489a000 src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java
--- a/src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java Thu Apr 12 09:26:53 2018 -0400
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/BasicTypeHelper.java Thu Apr 12 14:22:51 2018 -0700
@@ -73,6 +73,9 @@
case 'V':
return TypeTag.V;
default:
+ if (s == nullType()) {
+ return TypeTag.A;
+ }
throw new IllegalStateException("Bad type: " + s);
}
}
diff -r 4d1e8489a000 src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java
--- a/src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java Thu Apr 12 09:26:53 2018 -0400
+++ b/src/java.base/share/classes/jdk/experimental/bytecode/TypedCodeBuilder.java Thu Apr 12 14:22:51 2018 -0700
@@ -238,6 +238,7 @@
State(ArrayList<T> stack, Vector<T> locals) {
this.stack = stack;
this.locals = locals;
+ this.alive = true;
}
State() {
> On Apr 12, 2018, at 1:23 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
> Thanks, i think there is a bug processing the label when merging stack state from which to generate a stack map entry. Something to do with liveness… i might be able to work it out more fully... but i am not too familiar with stack map entries.
>
> Paul.
>
>> On Apr 12, 2018, at 7:37 AM, Roland Westrelin <rwestrel at redhat.com> wrote:
>>
>>
>> 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