Example usage for org.objectweb.asm Opcodes FMUL

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

Introduction

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

Prototype

int FMUL

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

Click Source Link

Usage

From source file:org.jboss.byteman.rule.expression.ArithmeticExpression.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);

    int currentStack = compileContext.getStackCount();
    int expectedStack = 0;
    Expression operand0 = getOperand(0);
    Expression operand1 = getOperand(1);
    Type type0 = operand0.getType();
    Type type1 = operand1.getType();
    // compile lhs -- it adds 1 or 2 to the stack height
    operand0.compile(mv, compileContext);
    // do any required type conversion
    compileTypeConversion(type0, type, mv, compileContext);
    // compile rhs -- it adds 1 or 2 to the stack height
    operand1.compile(mv, compileContext);
    // do any required type conversion
    compileTypeConversion(type1, type, mv, compileContext);

    try {//from www .  j  a v a  2s.  c  o  m
        // n.b. be careful with characters here
        if (type == type.B || type == type.S || type == type.C || type == type.I) {
            // TODO we should probably only respect the byte, short and char types for + and -
            // TODO also need to decide how to handle divide by zero

            expectedStack = 1;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.IMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.IDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.IADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.ISUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.IREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // now coerce back to appropriate type
            if (type == type.B) {
                mv.visitInsn(Opcodes.I2B);
            } else if (type == type.S) {
                mv.visitInsn(Opcodes.I2S);
            } else if (type == type.C) {
                mv.visitInsn(Opcodes.I2C);
            } // else if (type == type.I) { do nothing }
              // ok, we popped two bytes but added one
            compileContext.addStackCount(-1);
        } else if (type == type.J) {

            expectedStack = 2;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.LMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.LDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.LADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.LSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.LREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped four bytes but added two
            compileContext.addStackCount(-2);
        } else if (type == type.F) {

            expectedStack = 1;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.FMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.FDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.FADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.FSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.FREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped two bytes but added one
            compileContext.addStackCount(-1);
        } else if (type == type.D) {

            expectedStack = 2;

            switch (oper) {
            case MUL:
                mv.visitInsn(Opcodes.DMUL);
                break;
            case DIV:
                mv.visitInsn(Opcodes.DDIV);
                break;
            case PLUS:
                mv.visitInsn(Opcodes.DADD);
                break;
            case MINUS:
                mv.visitInsn(Opcodes.DSUB);
                break;
            case MOD:
                mv.visitInsn(Opcodes.DREM);
                break;
            default:
                // should never happen
                throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
            }
            // ok, we popped four bytes but added two
            compileContext.addStackCount(-2);
        } else {
            throw new CompileException(
                    "ArithmeticExpression.compile : unexpected result type " + type.getName());
        }
    } catch (CompileException e) {
        throw e;
    } catch (Exception e) {
        throw new CompileException("ArithmeticExpression.compile : unexpected exception for operation " + token
                + getPos() + " in rule " + rule.getName(), e);
    }

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

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

License:Open Source License

private static final int getBinaryFloatOpCode(String op) {
    switch (op.charAt(0)) {
    case '-':
        return Opcodes.FSUB;
    case '+':
        return Opcodes.FADD;
    case '*':
        return Opcodes.FMUL;
    case '/':
        return Opcodes.FDIV;
    case '%':
        return Opcodes.FREM;
    default://from w ww .j  av a  2  s .c  om
        throw new IllegalArgumentException("Invalid operand " + op);
    }
}

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

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:

    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            mv.visitInsn(Opcodes.POP);/*from ww  w  . ja va 2 s .com*/
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:

    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            mv.visitInsn(Opcodes.POP2);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

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

License:Apache License

@Override
public void visitInsn(int opcode) {
    switch (opcode) {
    case Opcodes.IADD:
    case Opcodes.ISUB:
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.INT_TYPE);
            mv.visitVarInsn(Opcodes.ISTORE, storage);
            mv.visitInsn(Opcodes.POP);/*from ww  w  .  ja v  a 2 s.c o m*/
            mv.visitVarInsn(Opcodes.ILOAD, storage);
            /*
             * Alternative : mv.visitInsn(Opcodes.SWAP);
             * mv.visitInsn(Opcodes.POP);
             * mv.visitVarInsn(Opcodes.ILOAD,storage);
             */
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.FADD:
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.FLOAT_TYPE);
            mv.visitVarInsn(Opcodes.FSTORE, storage);
            mv.visitInsn(Opcodes.POP);
            mv.visitVarInsn(Opcodes.FLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.LADD:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.LONG_TYPE);
            mv.visitVarInsn(Opcodes.LSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.LLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    case Opcodes.DADD:
    case Opcodes.DSUB:
    case Opcodes.DMUL:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) {
            int storage = this.newLocal(Type.DOUBLE_TYPE);
            mv.visitVarInsn(Opcodes.DSTORE, storage);
            mv.visitInsn(Opcodes.POP2);
            mv.visitVarInsn(Opcodes.DLOAD, storage);
        } else {
            mv.visitInsn(opcode);
        }
        break;
    default:
        mv.visitInsn(opcode);
        break;
    }
}

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

License:Open Source License

@Test
public void test_add_sub_mul_div_rem() throws Exception {
    int[] opcodes = new int[] { Opcodes.IADD, Opcodes.LADD, Opcodes.FADD, Opcodes.DADD, Opcodes.ISUB,
            Opcodes.LSUB, Opcodes.FSUB, Opcodes.DSUB, Opcodes.IMUL, Opcodes.LMUL, Opcodes.FMUL, Opcodes.DMUL,
            Opcodes.IDIV, Opcodes.LDIV, Opcodes.FDIV, Opcodes.DDIV, Opcodes.IREM, Opcodes.LREM, Opcodes.FREM,
            Opcodes.DREM, };//from   ww w . j  a v a2 s  . c  o m
    assertConsume2produceNotNull(opcodes);

    assertThrowWhenInvalidStack(opcodes, " needs 2 values on stack");
}

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

License:Open Source License

@Test
public void zeroness_check_mul() {
    int[] opCodes = { Opcodes.DMUL, Opcodes.FMUL, Opcodes.IMUL, Opcodes.LMUL };

    for (int mulOpCode : opCodes) {
        Instruction instruction = new Instruction(mulOpCode);
        ProgramState ps = execute(instruction, zeroZeroPs);
        SymbolicValue peekValue = ps.peekValue();
        assertThat(peekValue).isEqualTo(sv2);
        ConstraintsByDomain constraints = ps.getConstraints(peekValue);
        assertThat(constraints.get(ZeroConstraint.class)).isEqualTo(ZeroConstraint.ZERO);
        assertThat(constraints.get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.FALSE);

        ps = execute(instruction, zeroNonZeroPs);
        peekValue = ps.peekValue();//from   w w w  .  ja  v a 2s .c o  m
        assertThat(peekValue).isEqualTo(sv1);
        constraints = ps.getConstraints(peekValue);
        assertThat(constraints.get(ZeroConstraint.class)).isEqualTo(ZeroConstraint.ZERO);
        assertThat(constraints.get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.FALSE);

        ps = execute(instruction, nonZeroZeroPs);
        peekValue = ps.peekValue();
        assertThat(peekValue).isEqualTo(sv2);
        constraints = ps.getConstraints(peekValue);
        assertThat(constraints.get(ZeroConstraint.class)).isEqualTo(ZeroConstraint.ZERO);
        assertThat(constraints.get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.FALSE);

        ps = execute(instruction, nonZeroNonZeroPs);
        peekValue = ps.peekValue();
        assertThat(peekValue).isNotIn(sv1, sv2);
        constraints = ps.getConstraints(peekValue);
        assertThat(constraints.get(ZeroConstraint.class)).isEqualTo(ZeroConstraint.NON_ZERO);
        assertThat(constraints.get(BooleanConstraint.class)).isNull();

        ps = execute(instruction, noConstraints);
        peekValue = ps.peekValue();
        assertThat(peekValue).isNotIn(sv1, sv2);
        constraints = ps.getConstraints(peekValue);
        assertThat(constraints.get(ZeroConstraint.class)).isNull();
        assertThat(constraints.get(BooleanConstraint.class)).isNull();
    }
}

From source file:serianalyzer.JVMImpl.java

License:Open Source License

/**
 * @param opcode/*  w ww .jav  a2s  .co  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$
    }
}

From source file:v6.java.preverifier.PreverifierMethodNode.java

License:Open Source License

/**
 * Return a boolean indicating whether the specified opcode is
 * a floating point Opcodes.// w  w  w .j  a v  a 2s  .  c  o m
 * 
 * @param opcode
 * @return
 */
private boolean isFloatingPointOpcode(int opcode) {
    boolean isFloatingPointOpcode = false;

    switch (opcode) {
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.FSTORE:
    case Opcodes.DSTORE:
    case Opcodes.FALOAD:
    case Opcodes.DALOAD:
    case Opcodes.FASTORE:
    case Opcodes.DASTORE:
    case Opcodes.FADD:
    case Opcodes.DADD:
    case Opcodes.FSUB:
    case Opcodes.DSUB:
    case Opcodes.FMUL:
    case Opcodes.DMUL:
    case Opcodes.FDIV:
    case Opcodes.DDIV:
    case Opcodes.FREM:
    case Opcodes.DREM:
    case Opcodes.FNEG:
    case Opcodes.DNEG:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.I2F:
    case Opcodes.F2I:
    case Opcodes.I2D:
    case Opcodes.D2I:
    case Opcodes.L2F:
    case Opcodes.L2D:
    case Opcodes.F2L:
    case Opcodes.D2L:
    case Opcodes.F2D:
    case Opcodes.D2F:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
        isFloatingPointOpcode = true;
        break;
    }

    return isFloatingPointOpcode;
}