Example usage for org.objectweb.asm Opcodes ICONST_0

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

Introduction

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

Prototype

int ICONST_0

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

Click Source Link

Usage

From source file:org.jacoco.core.internal.analysis.filter.LombokGeneratedFilterTest.java

License:Open Source License

@Test
public void testOtherAnnotation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Lother/Annotation;", false);

    m.visitInsn(Opcodes.ICONST_0);
    m.visitInsn(Opcodes.IRETURN);//from  w ww  .  j a v  a2s  . c o m

    filter.filter("Foo", "java/lang/Object", m, this);

    assertNull(fromInclusive);
    assertNull(toInclusive);
}

From source file:org.jacoco.core.internal.analysis.filter.LombokGeneratedFilterTest.java

License:Open Source License

@Test
public void testLombokGeneratedAnnotation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Llombok/Generated;", false);

    m.visitInsn(Opcodes.ICONST_0);
    m.visitInsn(Opcodes.IRETURN);/*from   w  w  w  . j  a va2 s  .co m*/

    filter.filter("Foo", "java/lang/Object", m, this);

    assertEquals(m.instructions.getFirst(), fromInclusive);
    assertEquals(m.instructions.getLast(), toInclusive);
}

From source file:org.jacoco.core.internal.analysis.filter.StringSwitchJavacFilterTest.java

License:Open Source License

private void createFirstSwitch() {
    final Label h1 = new Label();
    final Label h1_2 = new Label();
    final Label h2 = new Label();
    final Label secondSwitch = new Label();

    m.visitInsn(Opcodes.ICONST_M1);//from www  .ja  v a2  s  .  c  o  m
    m.visitVarInsn(Opcodes.ISTORE, 2);

    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    m.visitLookupSwitchInsn(secondSwitch, new int[] { 97, 98 }, new Label[] { h1, h2 });
    expectedFromInclusive = m.instructions.getLast();

    m.visitLabel(h1);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "a", then goto next comparison
    m.visitJumpInsn(Opcodes.IFEQ, h1_2);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h1_2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("\0a");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "\0a", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_1);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    // goto secondSwitch
    m.visitJumpInsn(Opcodes.GOTO, secondSwitch);

    m.visitLabel(h2);
    m.visitVarInsn(Opcodes.ALOAD, 1);
    m.visitLdcInsn("b");
    m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
    // if not equal "b", then goto second switch
    m.visitJumpInsn(Opcodes.IFEQ, secondSwitch);
    m.visitInsn(Opcodes.ICONST_2);
    m.visitVarInsn(Opcodes.ISTORE, 2);

    m.visitLabel(secondSwitch);
    expectedToInclusive = m.instructions.getLast();
    m.visitVarInsn(Opcodes.ILOAD, 2);
}

From source file:org.jacoco.core.internal.analysis.MethodAnalyzerTest.java

License:Open Source License

private void createTableSwitch() {
    method.visitLineNumber(1001, new Label());
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l1 = new Label();
    Label l2 = new Label();
    Label l3 = new Label();
    method.visitTableSwitchInsn(1, 3, l3, new Label[] { l1, l2, l1 });
    method.visitLabel(l1);/*from   w  w w .  j av a 2 s.co  m*/
    method.visitLineNumber(1002, l1);
    method.visitIntInsn(Opcodes.BIPUSH, 11);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1003, new Label());
    Label l5 = new Label();
    method.visitJumpInsn(Opcodes.GOTO, l5);
    method.visitLabel(l2);
    method.visitLineNumber(1004, l2);
    method.visitIntInsn(Opcodes.BIPUSH, 22);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1005, new Label());
    method.visitJumpInsn(Opcodes.GOTO, l5);
    method.visitLabel(l3);
    method.visitLineNumber(1006, l3);
    method.visitInsn(Opcodes.ICONST_0);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLabel(l5);
    method.visitLineNumber(1007, l5);
    method.visitVarInsn(Opcodes.ILOAD, 2);
    method.visitInsn(Opcodes.IRETURN);
}

From source file:org.jacoco.core.internal.analysis.MethodAnalyzerTest.java

License:Open Source License

private void createTableSwitchMerge() {
    method.visitLineNumber(1001, new Label());
    method.visitInsn(Opcodes.ICONST_0);
    method.visitVarInsn(Opcodes.ISTORE, 2);
    method.visitLineNumber(1002, new Label());
    method.visitVarInsn(Opcodes.ILOAD, 1);
    Label l2 = new Label();
    Label l3 = new Label();
    Label l4 = new Label();
    method.visitTableSwitchInsn(1, 3, l4, new Label[] { l2, l3, l2 });
    method.visitLabel(l2);/*from www  .j a  v  a2 s . c om*/
    method.visitLineNumber(1003, l2);
    method.visitIincInsn(2, 1);
    method.visitLabel(l3);
    method.visitLineNumber(1004, l3);
    method.visitIincInsn(2, 1);
    method.visitLabel(l4);
    method.visitLineNumber(1005, l4);
    method.visitVarInsn(Opcodes.ILOAD, 2);
    method.visitInsn(Opcodes.IRETURN);
}

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

License:Open Source License

@Test
public void should_capture_frame_when_frame_is_defined() {
    analyzer.visitInsn(Opcodes.FCONST_0);
    analyzer.visitVarInsn(Opcodes.FSTORE, 1);
    analyzer.visitInsn(Opcodes.ICONST_0);
    frame = FrameSnapshot.create(analyzer, 0);

    expectedVisitor.visitFrame(Opcodes.F_FULL, 2, arr("Foo", Opcodes.FLOAT), 1, arr(Opcodes.INTEGER));
}

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

License:Open Source License

@Test
public void should_combine_slots_when_doube_or_long_types_are_given() {
    analyzer.visitInsn(Opcodes.DCONST_0);
    analyzer.visitVarInsn(Opcodes.DSTORE, 1);
    analyzer.visitInsn(Opcodes.FCONST_0);
    analyzer.visitVarInsn(Opcodes.FSTORE, 3);

    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.LCONST_0);
    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.DCONST_0);
    frame = FrameSnapshot.create(analyzer, 0);

    final Object[] vars = arr("Foo", Opcodes.DOUBLE, Opcodes.FLOAT);
    final Object[] stack = arr(Opcodes.INTEGER, Opcodes.LONG, Opcodes.INTEGER, Opcodes.DOUBLE);
    expectedVisitor.visitFrame(Opcodes.F_FULL, 3, vars, 4, stack);
}

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

License:Open Source License

@Test
public void should_decrease_stack_when_popCount_is_given() {
    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.LCONST_0);
    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.ICONST_0);
    frame = FrameSnapshot.create(analyzer, 2);

    final Object[] stack = arr(Opcodes.INTEGER, Opcodes.LONG);
    expectedVisitor.visitFrame(Opcodes.F_FULL, 1, arr("Foo"), 2, stack);
}

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

License:Open Source License

/**
 * Test of <a href="https://gitlab.ow2.org/asm/asm/issues/317793">ASM
 * bug</a>: according to <a href=
 * "https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.10.1.9.aaload">JVMS
 * "4.10.1.9 Type Checking Instructions, AALOAD"</a> resulting type on the
 * operand stack should be null if the input array is null.
 *//*from  w w  w  .ja v  a2  s .c  o  m*/
@Test
public void after_aaload_stack_should_contain_null_when_input_array_is_null() {
    analyzer.visitInsn(Opcodes.ACONST_NULL);
    analyzer.visitInsn(Opcodes.ICONST_0);
    analyzer.visitInsn(Opcodes.AALOAD);
    frame = FrameSnapshot.create(analyzer, 0);

    final Object[] stack = arr(Opcodes.NULL);
    expectedVisitor.visitFrame(Opcodes.F_FULL, 1, arr("Foo"), 1, stack);
}

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  www.  j  a  v  a2  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);
}