Commit 0dd78422 authored by Eric Bruneton's avatar Eric Bruneton
Browse files

Merge branch 'field-handles' into 'master'

Remap invokedynamic field handles properly

Closes #317954

See merge request !327
parents cf20d046 2a70d3a5
Pipeline #15914 passed with stage
in 6 minutes and 23 seconds
...@@ -160,13 +160,15 @@ public abstract class Remapper { ...@@ -160,13 +160,15 @@ public abstract class Remapper {
} }
if (value instanceof Handle) { if (value instanceof Handle) {
Handle handle = (Handle) value; Handle handle = (Handle) value;
boolean isFieldHandle = handle.getTag() <= Opcodes.H_PUTSTATIC;
return new Handle( return new Handle(
handle.getTag(), handle.getTag(),
mapType(handle.getOwner()), mapType(handle.getOwner()),
mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()), isFieldHandle
handle.getTag() <= Opcodes.H_PUTSTATIC ? mapFieldName(handle.getOwner(), handle.getName(), handle.getDesc())
? mapDesc(handle.getDesc()) : mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()),
: mapMethodDesc(handle.getDesc()), isFieldHandle ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()),
handle.isInterface()); handle.isInterface());
} }
if (value instanceof ConstantDynamic) { if (value instanceof ConstantDynamic) {
......
...@@ -50,6 +50,7 @@ import org.objectweb.asm.Type; ...@@ -50,6 +50,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest; import org.objectweb.asm.test.AsmTest;
import org.objectweb.asm.test.ClassFile; import org.objectweb.asm.test.ClassFile;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.util.CheckMethodAdapter; import org.objectweb.asm.util.CheckMethodAdapter;
...@@ -209,6 +210,38 @@ public class ClassRemapperTest extends AsmTest { ...@@ -209,6 +210,38 @@ public class ClassRemapperTest extends AsmTest {
assertEquals("()Ljava/lang/Integer;", constantDynamic.getBootstrapMethod().getDesc()); assertEquals("()Ljava/lang/Integer;", constantDynamic.getBootstrapMethod().getDesc());
} }
@Test
public void testInvokeDynamicInsn_field() {
ClassNode classNode = new ClassNode();
ClassRemapper classRemapper =
new ClassRemapper(
/* latest api */ Opcodes.ASM9,
classNode,
new Remapper() {
@Override
public String mapFieldName(
final String owner, final String name, final String descriptor) {
if ("a".equals(name)) {
return "demo";
}
return name;
}
});
classRemapper.visit(Opcodes.V11, Opcodes.ACC_PUBLIC, "C", null, "java/lang/Object", null);
MethodVisitor methodVisitor =
classRemapper.visitMethod(Opcodes.ACC_PUBLIC, "hello", "()V", null, null);
methodVisitor.visitCode();
methodVisitor.visitInvokeDynamicInsn(
"foo",
"()Ljava/lang/String;",
new Handle(Opcodes.H_GETFIELD, "pkg/B", "a", "Ljava/lang/String;", false));
InvokeDynamicInsnNode invokeDynamic =
(InvokeDynamicInsnNode) classNode.methods.get(0).instructions.get(0);
assertEquals("demo", invokeDynamic.bsm.getName());
}
/** Tests that classes transformed with a ClassRemapper can be loaded and instantiated. */ /** Tests that classes transformed with a ClassRemapper can be loaded and instantiated. */
@ParameterizedTest @ParameterizedTest
@MethodSource(ALL_CLASSES_AND_ALL_APIS) @MethodSource(ALL_CLASSES_AND_ALL_APIS)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment