Example usage for org.objectweb.asm Opcodes ICONST_1

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

Introduction

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

Prototype

int ICONST_1

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

Click Source Link

Usage

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 w  w.ja v  a  2  s  . c  o  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.ProbeInserter.java

License:Open Source License

public void insertProbe(final int id) {

    // For a probe we set the corresponding position in the boolean[] array
    // to true./* ww w  .j  a  v  a  2s . c o m*/

    mv.visitVarInsn(Opcodes.ALOAD, variable);

    // Stack[0]: [Z

    InstrSupport.push(mv, id);

    // Stack[1]: I
    // Stack[0]: [Z

    mv.visitInsn(Opcodes.ICONST_1);

    // Stack[2]: I
    // Stack[1]: I
    // Stack[0]: [Z

    mv.visitInsn(Opcodes.BASTORE);
}

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

License:Open Source License

@Test
public void testVariableStatic() {
    ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "()V", actualVisitor, arrayStrategy);
    pi.insertProbe(0);/*from  www. j  a  v a2  s.  co m*/

    expectedVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    expectedVisitor.visitInsn(Opcodes.ICONST_0);
    expectedVisitor.visitInsn(Opcodes.ICONST_1);
    expectedVisitor.visitInsn(Opcodes.BASTORE);
}

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

License:Open Source License

@Test
public void testVariableNonStatic() {
    ProbeInserter pi = new ProbeInserter(0, "()V", actualVisitor, arrayStrategy);
    pi.insertProbe(0);/*from   w w  w .  j a  v a 2s  .c  o  m*/

    expectedVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    expectedVisitor.visitInsn(Opcodes.ICONST_0);
    expectedVisitor.visitInsn(Opcodes.ICONST_1);
    expectedVisitor.visitInsn(Opcodes.BASTORE);
}

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

License:Open Source License

@Test
public void testVariableNonStatic_IZObject() {
    ProbeInserter pi = new ProbeInserter(0, "(IZLjava/lang/Object;)V", actualVisitor, arrayStrategy);
    pi.insertProbe(0);//from   ww w .  j av  a 2  s  .c om

    expectedVisitor.visitVarInsn(Opcodes.ALOAD, 4);
    expectedVisitor.visitInsn(Opcodes.ICONST_0);
    expectedVisitor.visitInsn(Opcodes.ICONST_1);
    expectedVisitor.visitInsn(Opcodes.BASTORE);
}

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

License:Open Source License

@Test
public void testVariableNonStatic_JD() {
    ProbeInserter pi = new ProbeInserter(0, "(JD)V", actualVisitor, arrayStrategy);
    pi.insertProbe(0);/* www. j av  a  2 s . c  o m*/

    expectedVisitor.visitVarInsn(Opcodes.ALOAD, 5);
    expectedVisitor.visitInsn(Opcodes.ICONST_0);
    expectedVisitor.visitInsn(Opcodes.ICONST_1);
    expectedVisitor.visitInsn(Opcodes.BASTORE);
}

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

License:Open Source License

/**
 * Generates code that creates the argument array for the
 * {@link #getProbes(Object[])} method. The array instance is left on the
 * operand stack. The generated code requires a stack size of 5.
 * // w w w . ja v  a 2  s.c o  m
 * @param classid
 *            class identifier
 * @param classname
 *            VM class name
 * @param probecount
 *            probe count for this class
 * @param mv
 *            visitor to emit generated code
 */
public static void generateArgumentArray(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {
    mv.visitInsn(Opcodes.ICONST_3);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");

    // Class Id:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLdcInsn(Long.valueOf(classid));
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
    mv.visitInsn(Opcodes.AASTORE);

    // Class Name:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitLdcInsn(classname);
    mv.visitInsn(Opcodes.AASTORE);

    // Probe Count:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_2);
    InstrSupport.push(mv, probecount);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
    mv.visitInsn(Opcodes.AASTORE);
}

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

License:Open Source License

/**
 * Generates code that creates the argument array for the
 * <code>getExecutionData()</code> method. The array instance is left on the
 * operand stack. The generated code requires a stack size of 5.
 * //  ww  w. j  av  a2s.  com
 * @param classid
 *            class identifier
 * @param classname
 *            VM class name
 * @param probecount
 *            probe count for this class
 * @param mv
 *            visitor to emit generated code
 */
public static void generateArgumentArray(final long classid, final String classname, final int probecount,
        final MethodVisitor mv) {
    mv.visitInsn(Opcodes.ICONST_3);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");

    // Class Id:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitLdcInsn(Long.valueOf(classid));
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
    mv.visitInsn(Opcodes.AASTORE);

    // Class Name:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitLdcInsn(classname);
    mv.visitInsn(Opcodes.AASTORE);

    // Probe Count:
    mv.visitInsn(Opcodes.DUP);
    mv.visitInsn(Opcodes.ICONST_2);
    InstrSupport.push(mv, probecount);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
    mv.visitInsn(Opcodes.AASTORE);
}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates the instructions to compute the bitwise negation of the top
 * stack value.
 */
public void not() {
    visitInsn(Opcodes.ICONST_1);
    visitInsn(Opcodes.IXOR);
}

From source file:org.jboss.byteman.rule.expression.NotExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Expression oper = getOperand(0);
    Type operType = oper.getType();

    int currentStack = compileContext.getStackCount();
    int expected = 1;

    // compile code to execute the operand -- adds 1
    oper.compile(mv, compileContext);/*from w  w  w. ja va2 s  .  co m*/
    compileTypeConversion(operType, type, mv, compileContext);

    // the boolean expression will leave 0 or 1 on the stack so we can negate negate this to get
    // 0 or -1 and then add 1 to get 1 or 0

    mv.visitInsn(Opcodes.INEG);
    // adds 1
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IADD);

    // check stack height
    if (compileContext.getStackCount() != currentStack + expected) {
        throw new CompileException("NotExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + currentStack + expected);
    }
}