use of org.objectweb.asm.ConstantDynamic in project jacoco by jacoco.
the class CondyProbeArrayStrategyTest method should_store_instance_using_condy_and_checkcast.
@Test
public void should_store_instance_using_condy_and_checkcast() {
final MethodNode m = new MethodNode();
final int maxStack = strategy.storeInstance(m, false, 1);
assertEquals(1, maxStack);
final ConstantDynamic constantDynamic = (ConstantDynamic) ((LdcInsnNode) m.instructions.get(0)).cst;
assertEquals("$jacocoData", constantDynamic.getName());
assertEquals("Ljava/lang/Object;", constantDynamic.getDescriptor());
final Handle bootstrapMethod = constantDynamic.getBootstrapMethod();
assertEquals(Opcodes.H_INVOKESTATIC, bootstrapMethod.getTag());
assertEquals("ClassName", bootstrapMethod.getOwner());
assertEquals("$jacocoInit", bootstrapMethod.getName());
assertEquals("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)[Z", bootstrapMethod.getDesc());
assertTrue(bootstrapMethod.isInterface());
final TypeInsnNode castInstruction = (TypeInsnNode) m.instructions.get(1);
assertEquals(Opcodes.CHECKCAST, castInstruction.getOpcode());
assertEquals("[Z", castInstruction.desc);
final VarInsnNode storeInstruction = (VarInsnNode) m.instructions.get(2);
assertEquals(Opcodes.ASTORE, storeInstruction.getOpcode());
assertEquals(1, storeInstruction.var);
assertEquals(3, m.instructions.size());
}
use of org.objectweb.asm.ConstantDynamic in project jacoco by jacoco.
the class CondyProbeArrayStrategy method storeInstance.
public int storeInstance(final MethodVisitor mv, final boolean clinit, final int variable) {
final Handle bootstrapMethod = new Handle(Opcodes.H_INVOKESTATIC, className, InstrSupport.INITMETHOD_NAME, B_DESC, isInterface);
// As a workaround for https://bugs.openjdk.java.net/browse/JDK-8216970
// constant should have type Object
mv.visitLdcInsn(new ConstantDynamic(InstrSupport.DATAFIELD_NAME, "Ljava/lang/Object;", bootstrapMethod));
mv.visitTypeInsn(Opcodes.CHECKCAST, "[Z");
mv.visitVarInsn(Opcodes.ASTORE, variable);
return 1;
}
Aggregations