Example usage for org.objectweb.asm Opcodes RETURN

List of usage examples for org.objectweb.asm Opcodes RETURN

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes RETURN.

Prototype

int RETURN

To view the source code for org.objectweb.asm Opcodes RETURN.

Click Source Link

Usage

From source file:org.jacoco.core.internal.flow.MethodSanitizerTest.java

License:Open Source License

@Test
public void testLocalVariablePositive() {
    Label l1 = new Label();
    Label l2 = new Label();
    sanitizer.visitCode();/*from  w  ww  .  j a v a 2 s.c o m*/
    sanitizer.visitLabel(l1);
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitLabel(l2);
    sanitizer.visitLocalVariable("x", "I", null, l1, l2, 0);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    Label m1 = new Label();
    Label m2 = new Label();
    expected.visitLabel(m1);
    expected.visitInsn(Opcodes.RETURN);
    expected.visitLabel(m2);
    expected.visitLocalVariable("x", "I", null, m1, m2, 0);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
}

From source file:org.jacoco.core.internal.flow.MethodSanitizerTest.java

License:Open Source License

@Test
public void testLocalVariableNegative1() {
    Label l1 = new Label();
    Label l2 = new Label();
    sanitizer.visitCode();//from w  w w .  ja  v a2  s .  com
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitLabel(l2);
    sanitizer.visitLocalVariable("x", "I", null, l1, l2, 0);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    Label m2 = new Label();
    expected.visitInsn(Opcodes.RETURN);
    expected.visitLabel(m2);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
}

From source file:org.jacoco.core.internal.flow.MethodSanitizerTest.java

License:Open Source License

@Test
public void testLocalVariableNegative2() {
    Label l1 = new Label();
    Label l2 = new Label();
    sanitizer.visitCode();/*from   ww w.ja va2 s  . c om*/
    sanitizer.visitLabel(l1);
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitLocalVariable("x", "I", null, l1, l2, 0);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    Label m1 = new Label();
    expected.visitLabel(m1);
    expected.visitInsn(Opcodes.RETURN);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
}

From source file:org.jacoco.core.internal.flow.MethodSanitizerTest.java

License:Open Source License

@Test
public void testLineNumberPositive() {
    Label l1 = new Label();
    sanitizer.visitCode();//from  w  w w  . j a v a  2s .  com
    sanitizer.visitLabel(l1);
    sanitizer.visitLineNumber(15, l1);
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    Label m1 = new Label();
    expected.visitLabel(m1);
    expected.visitLineNumber(15, m1);
    expected.visitInsn(Opcodes.RETURN);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
}

From source file:org.jacoco.core.internal.flow.MethodSanitizerTest.java

License:Open Source License

@Test
public void testLineNumberNegative() {
    Label l1 = new Label();
    sanitizer.visitCode();/*  w  w  w  . j ava2 s  . c  om*/
    sanitizer.visitLineNumber(15, l1);
    sanitizer.visitInsn(Opcodes.RETURN);
    sanitizer.visitMaxs(0, 0);
    sanitizer.visitEnd();

    expected.visitInsn(Opcodes.RETURN);
    expected.visitMaxs(0, 0);
    expected.visitEnd();

    assertOutput();
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    final Object t1, t2, t3, t4;
    switch (opcode) {
    case Opcodes.NOP:
    case Opcodes.RETURN:
        break;/*from   w ww .  j a va 2  s .co m*/
    case Opcodes.ARETURN:
    case Opcodes.ATHROW:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        pop(1);
        break;
    case Opcodes.DRETURN:
    case Opcodes.LRETURN:
    case Opcodes.POP2:
        pop(2);
        break;
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.FASTORE:
    case Opcodes.IASTORE:
    case Opcodes.SASTORE:
        pop(3);
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        pop(4);
        break;
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
        push(Opcodes.INTEGER);
        break;
    case Opcodes.ARRAYLENGTH:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.INEG:
        pop(1);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.D2I:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.IADD:
    case Opcodes.IALOAD:
    case Opcodes.IAND:
    case Opcodes.IDIV:
    case Opcodes.IMUL:
    case Opcodes.IOR:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.ISUB:
    case Opcodes.IUSHR:
    case Opcodes.IXOR:
    case Opcodes.L2I:
    case Opcodes.SALOAD:
        pop(2);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.LCMP:
        pop(4);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        push(Opcodes.FLOAT);
        break;
    case Opcodes.FNEG:
    case Opcodes.I2F:
        pop(1);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.D2F:
    case Opcodes.FADD:
    case Opcodes.FALOAD:
    case Opcodes.FDIV:
    case Opcodes.FMUL:
    case Opcodes.FREM:
    case Opcodes.FSUB:
    case Opcodes.L2F:
        pop(2);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2L:
    case Opcodes.I2L:
        pop(1);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.D2L:
    case Opcodes.LALOAD:
    case Opcodes.LNEG:
        pop(2);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        pop(3);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LDIV:
    case Opcodes.LMUL:
    case Opcodes.LOR:
    case Opcodes.LREM:
    case Opcodes.LSUB:
    case Opcodes.LXOR:
        pop(4);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2D:
    case Opcodes.I2D:
        pop(1);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DALOAD:
    case Opcodes.DNEG:
    case Opcodes.L2D:
        pop(2);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DADD:
    case Opcodes.DDIV:
    case Opcodes.DMUL:
    case Opcodes.DREM:
    case Opcodes.DSUB:
        pop(4);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.ACONST_NULL:
        push(Opcodes.NULL);
        break;
    case Opcodes.AALOAD:
        pop(1);
        t1 = pop();
        push(Type.getType(((String) t1).substring(1)));
        break;
    case Opcodes.DUP:
        t1 = pop();
        push(t1);
        push(t1);
        break;
    case Opcodes.DUP_X1:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2:
        t1 = pop();
        t2 = pop();
        push(t2);
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X1:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t2);
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        t4 = pop();
        push(t2);
        push(t1);
        push(t4);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.SWAP:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitInsn(opcode);
}

From source file:org.jacoco.core.internal.instr.InterfaceFieldProbeArrayStrategy.java

License:Open Source License

private void createClinitMethod(final ClassVisitor cv, final int probeCount) {
    final MethodVisitor mv = cv.visitMethod(InstrSupport.CLINIT_ACC, InstrSupport.CLINIT_NAME,
            InstrSupport.CLINIT_DESC, null, null);
    mv.visitCode();/*  ww w .  j ava  2 s .  c  om*/

    final int maxStack = accessorGenerator.generateDataAccessor(classId, className, probeCount, mv);

    // Stack[0]: [Z

    mv.visitFieldInsn(Opcodes.PUTSTATIC, className, InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC);

    mv.visitInsn(Opcodes.RETURN);

    mv.visitMaxs(maxStack, 0);
    mv.visitEnd();
}

From source file:org.jacoco.core.internal.instr.MethodInstrumenterTest.java

License:Open Source License

@Test
public void testVisitInsnWithProbe() {
    instrumenter.visitInsnWithProbe(Opcodes.RETURN, 3);

    expectedVisitor.visitLdcInsn("Probe 3");
    expectedVisitor.visitInsn(Opcodes.RETURN);

    assertEquals(expected, actual);//from  w ww .  j a va 2  s  . c om
}

From source file:org.jacoco.core.internal.instr.ProbeArrayStrategyFactoryTest.java

License:Open Source License

private IProbeArrayStrategy test(int version, int access, boolean clinit, boolean method,
        boolean abstractMethod) {
    final ClassWriter writer = new ClassWriter(0);
    writer.visit(version, access, "Foo", "java/lang/Object", null, null);
    if (clinit) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V",
                null, null);/*from ww  w .  j a  va  2s.co m*/
        mv.visitCode();
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (method) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "doit", "()V",
                null, null);
        mv.visitCode();
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
    }
    if (abstractMethod) {
        final MethodVisitor mv = writer.visitMethod(Opcodes.ACC_ABSTRACT, "foo", "()V", null, null);
        mv.visitEnd();
    }
    writer.visitEnd();

    final IProbeArrayStrategy strategy = ProbeArrayStrategyFactory.createFor(0,
            new ClassReader(writer.toByteArray()), generator);

    strategy.addMembers(cv, 123);
    return strategy;
}

From source file:org.jacoco.core.runtime.ExecutionDataAccessTest.java

License:Open Source License

@Test
public void testGenerateArgumentArray() throws Exception {
    final ClassWriter writer = new ClassWriter(0);
    writer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Sample", null, "java/lang/Object",
            new String[] { Type.getInternalName(Callable.class) });

    // Constructor
    MethodVisitor mv = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
    mv.visitCode();//from www  .  j a v  a2  s.co  m
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();

    // call()
    mv = writer.visitMethod(Opcodes.ACC_PUBLIC, "call", "()Ljava/lang/Object;", null, new String[0]);
    mv.visitCode();
    ExecutionDataAccess.generateArgumentArray(1000, "Sample", 15, mv);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(5, 1);
    mv.visitEnd();

    writer.visitEnd();
    final TargetLoader loader = new TargetLoader("Sample", writer.toByteArray());
    Callable<?> callable = (Callable<?>) loader.newTargetInstance();
    final Object[] args = (Object[]) callable.call();
    assertEquals(3, args.length, 0.0);
    assertEquals(Long.valueOf(1000), args[0]);
    assertEquals("Sample", args[1]);
    assertEquals(Integer.valueOf(15), args[2]);
}