Treat non-lambda metafactory argument method handles specially.
They can reach MethodHandle.invokeExact calls which match exact
method signatures. Therefore, we cannot perform member rebinding
on the methods in method handles because that could (and likely
would) change the receiver type making the matching fail.
Therefore, we keep the original receiver type for all such
method handles. That also means that we need to keep those
receiver types in the output and cannot perform merging or
other operations that would make those types disappear.
R=christofferqa@google.com, sgjesse@google.com, tamaskenez@google.com
Change-Id: Ic31373f574493b6941acca176f39decf0ef12182
diff --git a/src/test/examplesAndroidO/invokecustom/TestGenerator.java b/src/test/examplesAndroidO/invokecustom/TestGenerator.java
index e42b9c9..05a6f28 100644
--- a/src/test/examplesAndroidO/invokecustom/TestGenerator.java
+++ b/src/test/examplesAndroidO/invokecustom/TestGenerator.java
@@ -57,6 +57,7 @@
generateMethodTest11(cw);
generateMethodTest12(cw);
generateMethodTest13(cw);
+ generateMethodTest14(cw);
generateMethodMain(cw);
super.visitEnd();
}
@@ -97,6 +98,8 @@
Opcodes.INVOKESTATIC, Type.getInternalName(InvokeCustom.class), "test12", "()V", false);
mv.visitMethodInsn(
Opcodes.INVOKESTATIC, Type.getInternalName(InvokeCustom.class), "test13", "()V", false);
+ mv.visitMethodInsn(
+ Opcodes.INVOKESTATIC, Type.getInternalName(InvokeCustom.class), "test14", "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
}
@@ -424,4 +427,43 @@
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(-1, -1);
}
+
+ /**
+ * Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
+ * MethodHandle of kind invoke instance taking an argument and returning a result. This should
+ * work through renaming.
+ */
+ private void generateMethodTest14(ClassVisitor cv) {
+ MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test14", "()V",
+ null, null);
+ MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
+ MethodType.class, MethodHandle.class);
+ Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
+ "bsmCreateCallSite", mt.toMethodDescriptorString(), false);
+ mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitMethodInsn(
+ Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
+ mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(ClassWithLongName.class));
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitMethodInsn(
+ Opcodes.INVOKESPECIAL,
+ Type.getInternalName(ClassWithLongName.class),
+ "<init>",
+ "()V",
+ false);
+ mv.visitInvokeDynamicInsn(
+ "targetMethodTest11",
+ "(Linvokecustom/InvokeCustom;Linvokecustom/ClassWithLongName;)"
+ + "Linvokecustom/AnotherClassWithALongName;",
+ bootstrap,
+ new Handle(
+ Opcodes.H_INVOKEVIRTUAL,
+ Type.getInternalName(InvokeCustom.class),
+ "targetMethodTest11",
+ "(Linvokecustom/ClassWithLongName;)Linvokecustom/AnotherClassWithALongName;",
+ false));
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(-1, -1);
+ }
}