Example usage for org.objectweb.asm Opcodes NOP

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

Introduction

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

Prototype

int NOP

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

Click Source Link

Usage

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**
 * Gets the op-code to widen a value of a given type to a value of another type.
 * @param typeToWiden the type to widen.
 * @param valueType the type to which the typeToWiden should be widened.
 * @return int the widening op code, as defined in org.objectweb.asm.Opcodes. Opcodes.NOP us used for the no-op.     
 *//*w w  w .j  a  v a 2 s .co  m*/
private static int getWideningOpCode(JavaTypeName typeToWiden, JavaTypeName valueType) {

    if (typeToWiden.equals(valueType)) {
        return Opcodes.NOP;
    }

    // Widen from int-type values -> float, long, double
    if (isInternalIntType(typeToWiden)) {

        switch (valueType.getTag()) {
        case JavaTypeName.BYTE_TAG:
        case JavaTypeName.SHORT_TAG:
        case JavaTypeName.CHAR_TAG:
        case JavaTypeName.INT_TAG:
            return Opcodes.NOP;

        case JavaTypeName.LONG_TAG:
            return Opcodes.I2L;

        case JavaTypeName.DOUBLE_TAG:
            return Opcodes.I2D;

        case JavaTypeName.FLOAT_TAG:
            return Opcodes.I2F;

        default:
            throw new IllegalArgumentException("Invalid widening conversion.");
        }

        // Widen from long -> float, double
    } else if (typeToWiden.equals(JavaTypeName.LONG)) {

        switch (valueType.getTag()) {

        case JavaTypeName.DOUBLE_TAG:
            return Opcodes.L2D;

        case JavaTypeName.FLOAT_TAG:
            return Opcodes.L2F;

        default:
            throw new IllegalArgumentException("Invalid widening conversion.");
        }

        // Widen from float -> double
    } else if (typeToWiden.equals(JavaTypeName.FLOAT)) {

        if (valueType.equals(JavaTypeName.DOUBLE)) {
            return Opcodes.F2D;
        }

        throw new IllegalArgumentException("Invalid widening conversion.");
    }

    //throw new IllegalArgumentException("Invalid widening conversion.");
    return Opcodes.NOP;
}

From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveIncrementsMutator.java

License:Apache License

@Override
public void visitIincInsn(final int var, final int increment) {
    final MutationIdentifier newId = this.context.registerMutation(this.factory,
            "Removed increment " + increment);
    if (this.context.shouldMutate(newId)) {
        this.mv.visitInsn(Opcodes.NOP);
    } else {/*from  w  w w .j a  v a  2 s. c om*/
        this.mv.visitIincInsn(var, increment);
    }
}

From source file:org.sonar.java.bytecode.cfg.InstructionTest.java

License:Open Source License

@Test
public void test_instruction_equals() throws Exception {
    Instruction nop1 = new Instruction(Opcodes.NOP);
    Instruction nop2 = new Instruction(Opcodes.NOP);
    Instruction.MultiANewArrayInsn mana = new Instruction.MultiANewArrayInsn("java/lang/Object", 1);

    assertThat(nop1.equals(nop1)).isTrue();
    assertThat(nop1.equals(nop2)).isTrue();
    assertThat(nop1.equals(null)).isFalse();
    assertThat(nop1.equals(mana)).isFalse();
    assertThat(nop1.hashCode()).isEqualTo(nop2.hashCode());

    Instruction aload0 = new Instruction(Opcodes.ALOAD, 0);
    assertThat(aload0).isNotEqualTo(nop1);

    Instruction aload1 = new Instruction(Opcodes.ALOAD, 1);
    assertThat(aload0).isNotEqualTo(aload1);
}

From source file:org.sonar.java.bytecode.cfg.InstructionTest.java

License:Open Source License

@Test
public void test_multianewarray() throws Exception {
    Instruction.MultiANewArrayInsn mana1 = new Instruction.MultiANewArrayInsn("java/lang/Object", 1);
    Instruction.MultiANewArrayInsn mana2 = new Instruction.MultiANewArrayInsn("java/lang/Object", 1);
    Instruction.MultiANewArrayInsn mana3 = new Instruction.MultiANewArrayInsn("java/lang/Object", 2);
    Instruction.MultiANewArrayInsn mana4 = new Instruction.MultiANewArrayInsn("java/lang/String", 2);
    assertThat(mana1.equals(mana1)).isTrue();
    assertThat(mana1.equals(mana2)).isTrue();
    assertThat(mana1.hashCode()).isEqualTo(mana2.hashCode());

    assertThat(mana1.equals(new Instruction(Opcodes.NOP))).isFalse();
    assertThat(mana1.equals(null)).isFalse();
    assertThat(mana1.equals(mana3)).isFalse();
    assertThat(mana1.equals(mana4)).isFalse();
}

From source file:org.sonar.java.bytecode.cfg.InstructionTest.java

License:Open Source License

@Test
public void test_invoke_dynamic_equals() throws Exception {
    Instruction.InvokeDynamicInsn indy1 = new Instruction.InvokeDynamicInsn("()V");
    assertThat(indy1.equals(indy1)).isTrue();
    assertThat(indy1.equals(null)).isFalse();
    assertThat(indy1.equals(new Instruction(Opcodes.NOP))).isFalse();

    Instruction.InvokeDynamicInsn indy2 = new Instruction.InvokeDynamicInsn("()V");
    assertThat(indy1).isEqualTo(indy2);/*w  w w  .j  a v a  2s  . c o  m*/
    assertThat(indy1.hashCode()).isEqualTo(indy2.hashCode());

    Instruction.InvokeDynamicInsn indy3 = new Instruction.InvokeDynamicInsn("()Ljava/util/function/Consumer;");
    assertThat(indy2).isNotEqualTo(indy3);
}

From source file:org.sonar.java.bytecode.cfg.InstructionTest.java

License:Open Source License

@Test
public void test_ldc_equals() throws Exception {
    Instruction nop = new Instruction(Opcodes.NOP);
    Instruction.LdcInsn ldc1 = new Instruction.LdcInsn("a");
    Instruction.LdcInsn ldc2 = new Instruction.LdcInsn("a");
    Instruction.LdcInsn ldc3 = new Instruction.LdcInsn(1L);
    assertThat(ldc1.equals(ldc1)).isTrue();
    assertThat(ldc1.equals(null)).isFalse();
    assertThat(ldc1.equals(nop)).isFalse();
    assertThat(ldc1.equals(ldc2)).isTrue();
    assertThat(ldc1.equals(ldc3)).isFalse();
    assertThat(ldc1.hashCode()).isEqualTo(ldc2.hashCode());
}

From source file:org.sonar.java.bytecode.cfg.InstructionTest.java

License:Open Source License

@Test
public void test_instruction_tostring() throws Exception {
    Instruction nop = new Instruction(Opcodes.NOP);
    assertThat(nop).hasToString("NOP");
}

From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java

License:Open Source License

@Test
public void test_nop() throws Exception {
    ProgramState programState = execute(new Instruction(Opcodes.NOP));
    assertThat(programState).isEqualTo(ProgramState.EMPTY_STATE);
}

From source file:org.sonar.java.se.ProgramPointTest.java

License:Open Source License

@Test
public void test_program_point_on_bytecode_cfg() throws Exception {
    ProgramPoint pp = new ProgramPoint(new Instructions().visitInsn(Opcodes.NOP).cfg().entry());
    assertThat(pp.toString()).isEqualTo("B1.0  ");
    assertThat(pp.syntaxTree()).isNull();
    assertThat(pp.equals("")).isFalse();
}

From source file:serianalyzer.JVMImpl.java

License:Open Source License

/**
 * @param opcode//from  w w  w  .  ja  v  a2 s.c o m
 * @param s
 */
static void handleJVMInsn(int opcode, JVMStackState s) {
    BaseType o1;
    BaseType o2;
    BaseType o3;
    List<BaseType> l1;
    List<BaseType> l2;
    switch (opcode) {
    case Opcodes.NOP:
        break;

    case Opcodes.ARRAYLENGTH:
        o1 = s.pop();
        s.push(new BasicConstant(Type.INT_TYPE, 0, !(o1 != null && !o1.isTainted())));
        break;
    case Opcodes.ACONST_NULL:
        s.push(new BasicConstant(Type.VOID_TYPE, "<null>")); //$NON-NLS-1$
        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:
        s.push(new BasicConstant(Type.INT_TYPE, opcode - 3));
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        s.push(new BasicConstant(Type.LONG_TYPE, opcode - 9L));
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        s.push(new BasicConstant(Type.FLOAT_TYPE, opcode - 11f));
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        s.push(new BasicConstant(Type.DOUBLE_TYPE, opcode - 14d));
        break;
    case Opcodes.IALOAD:
    case Opcodes.LALOAD:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.SALOAD:
        o1 = s.pop();
        o2 = s.pop();
        s.push(new BasicVariable(toType(opcode), "primitive array elem", //$NON-NLS-1$
                (o1 == null || o1.isTainted()) | (o2 == null || o2.isTainted())));
        break;

    case Opcodes.AALOAD:
        o1 = s.pop();
        o2 = s.pop();
        if (o1 != null && o2 instanceof SimpleType && ((SimpleType) o2).getType().toString().startsWith("[")) { //$NON-NLS-1$
            Type atype = Type.getType(((SimpleType) o2).getType().toString().substring(1));
            if (o2.getAlternativeTypes() != null && !o2.getAlternativeTypes().isEmpty()) {
                s.clear();
                break;
            }
            s.push(new BasicVariable(atype, "array elem " + atype, o1.isTainted() | o2.isTainted())); //$NON-NLS-1$
        } else {
            s.clear();
        }
        break;

    case Opcodes.IASTORE:
    case Opcodes.LASTORE:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
        s.pop(3);
        break;

    case Opcodes.POP2:
        s.pop();
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        s.pop();
        break;

    case Opcodes.DUP:
        if (!s.isEmpty()) {
            o1 = s.pop();
            s.push(o1);
            s.push(o1);
        }
        break;
    case Opcodes.DUP_X1:
        o1 = s.pop();
        o2 = s.pop();
        s.push(o1);
        s.push(o2);
        s.push(o1);
        break;
    case Opcodes.DUP_X2:
        o1 = s.pop();
        o2 = s.pop();
        o3 = s.pop();
        s.push(o1);
        s.push(o3);
        s.push(o2);
        s.push(o1);
        break;
    case Opcodes.DUP2:
        l1 = s.popWord();
        if (l1.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.pushWord(l1);
        }
        break;
    case Opcodes.DUP2_X1:
        l1 = s.popWord();
        o1 = s.pop();
        if (l1.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.push(o1);
            s.pushWord(l1);
        }
        break;
    case Opcodes.DUP2_X2:
        l1 = s.popWord();
        l2 = s.popWord();
        if (l1.isEmpty() || l2.isEmpty()) {
            log.trace("DUP2 with unknown operand"); //$NON-NLS-1$
            s.clear();
        } else {
            s.pushWord(l1);
            s.pushWord(l2);
            s.pushWord(l1);
        }
        break;

    case Opcodes.SWAP:
        o1 = s.pop();
        o2 = s.pop();
        s.push(o1);
        s.push(o2);
        break;

    case Opcodes.IADD:
    case Opcodes.LADD:
    case Opcodes.FADD:
    case Opcodes.DADD:
    case Opcodes.ISUB:
    case Opcodes.LSUB:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
    case Opcodes.IMUL:
    case Opcodes.LMUL:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
    case Opcodes.IDIV:
    case Opcodes.LDIV:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
    case Opcodes.IREM:
    case Opcodes.LREM:
    case Opcodes.FREM:
    case Opcodes.DREM:
    case Opcodes.IAND:
    case Opcodes.LAND:
    case Opcodes.IOR:
    case Opcodes.LOR:
    case Opcodes.IXOR:
    case Opcodes.LXOR:
    case Opcodes.LCMP:
    case Opcodes.FCMPL:
    case Opcodes.FCMPG:
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        s.merge(2);
        break;

    case Opcodes.ISHL:
    case Opcodes.LSHL:
    case Opcodes.ISHR:
    case Opcodes.LSHR:
    case Opcodes.IUSHR:
    case Opcodes.LUSHR:
        s.pop(); // amount
        // ignore value
        break;

    case Opcodes.INEG:
    case Opcodes.F2I:
    case Opcodes.D2I:
    case Opcodes.L2I:
        s.push(cast(s.pop(), Type.INT_TYPE));
        break;

    case Opcodes.LNEG:
    case Opcodes.I2L:
    case Opcodes.F2L:
    case Opcodes.D2L:
        s.push(cast(s.pop(), Type.LONG_TYPE));
        break;

    case Opcodes.FNEG:
    case Opcodes.I2F:
    case Opcodes.L2F:
    case Opcodes.D2F:
        s.push(cast(s.pop(), Type.FLOAT_TYPE));

    case Opcodes.DNEG:
    case Opcodes.I2D:
    case Opcodes.L2D:
    case Opcodes.F2D:
        s.push(cast(s.pop(), Type.DOUBLE_TYPE));

    case Opcodes.I2B:
        s.push(cast(s.pop(), Type.BYTE_TYPE));
        break;
    case Opcodes.I2C:
        s.push(cast(s.pop(), Type.CHAR_TYPE));
        break;
    case Opcodes.I2S:
        s.push(cast(s.pop(), Type.SHORT_TYPE));
        break;

    case Opcodes.ARETURN:
        s.clear();
        break;

    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.RETURN:
        if (log.isTraceEnabled()) {
            log.trace("Found return " + s.pop()); //$NON-NLS-1$
        }
        s.clear();
        break;

    case Opcodes.ATHROW:
        Object thrw = s.pop();
        log.trace("Found throw " + thrw); //$NON-NLS-1$
        s.clear();
        break;

    default:
        log.warn("Unsupported instruction code " + opcode); //$NON-NLS-1$
    }
}