Example usage for org.objectweb.asm Opcodes FCONST_0

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

Introduction

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

Prototype

int FCONST_0

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

Click Source Link

Usage

From source file:org.evosuite.instrumentation.mutation.ReplaceConstant.java

License:Open Source License

private Object getValue(AbstractInsnNode constant) {
    switch (constant.getOpcode()) {
    case Opcodes.LDC:
        return ((LdcInsnNode) constant).cst;
    case Opcodes.ICONST_0:
        return 0;
    case Opcodes.ICONST_1:
        return 1;
    case Opcodes.ICONST_2:
        return 2;
    case Opcodes.ICONST_3:
        return 3;
    case Opcodes.ICONST_4:
        return 4;
    case Opcodes.ICONST_5:
        return 5;
    case Opcodes.ICONST_M1:
        return -1;
    case Opcodes.LCONST_0:
        return 0L;
    case Opcodes.LCONST_1:
        return 1L;
    case Opcodes.DCONST_0:
        return 0.0;
    case Opcodes.DCONST_1:
        return 1.0;
    case Opcodes.FCONST_0:
        return 0.0F;
    case Opcodes.FCONST_1:
        return 1.0F;
    case Opcodes.FCONST_2:
        return 2.0F;
    case Opcodes.SIPUSH:
        return ((IntInsnNode) constant).operand;
    case Opcodes.BIPUSH:
        return ((IntInsnNode) constant).operand;
    default:/*from w w  w .j  a  v  a  2  s  . c  om*/
        throw new RuntimeException("Unknown constant: " + constant.getOpcode());
    }
}

From source file:org.evosuite.runtime.instrumentation.CreateClassResetClassAdapter.java

License:Open Source License

/**
 * Creates an empty __STATIC_RESET method where no <clinit> was found.
 *//*ww w  .  ja v  a2 s. co  m*/
private void createEmptyStaticReset() {
    logger.info("Creating brand-new static initializer in class " + className);
    MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC,
            ClassResetter.STATIC_RESET, "()V", null, null);
    mv.visitCode();
    for (StaticField staticField : static_fields) {

        if (!finalFields.contains(staticField.name) && !staticField.name.startsWith("__cobertura")
                && !staticField.name.startsWith("$jacoco") && !staticField.name.startsWith("$VRc") // Old
        // Emma
        ) {

            logger.info("Adding bytecode for initializing field " + staticField.name);

            if (staticField.value != null) {
                mv.visitLdcInsn(staticField.value);
            } else {
                Type type = Type.getType(staticField.desc);
                switch (type.getSort()) {
                case Type.BOOLEAN:
                case Type.BYTE:
                case Type.CHAR:
                case Type.SHORT:
                case Type.INT:
                    mv.visitInsn(Opcodes.ICONST_0);
                    break;
                case Type.FLOAT:
                    mv.visitInsn(Opcodes.FCONST_0);
                    break;
                case Type.LONG:
                    mv.visitInsn(Opcodes.LCONST_0);
                    break;
                case Type.DOUBLE:
                    mv.visitInsn(Opcodes.DCONST_0);
                    break;
                case Type.ARRAY:
                case Type.OBJECT:
                    mv.visitInsn(Opcodes.ACONST_NULL);
                    break;
                }
            }
            mv.visitFieldInsn(Opcodes.PUTSTATIC, className, staticField.name, staticField.desc);

        }
    }
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();

}

From source file:org.evosuite.runtime.instrumentation.CreateClassResetMethodAdapter.java

License:Open Source License

@Override
public void visitCode() {
    super.visitCode();
    for (StaticField staticField : staticFields) {

        if (!finalFields.contains(staticField.name) && !staticField.name.startsWith("__cobertura")
                && !staticField.name.startsWith("$jacoco") && !staticField.name.startsWith("$VRc") // Old Emma
        ) {//from   w w w.jav  a  2s .  com

            if (staticField.value != null) {
                mv.visitLdcInsn(staticField.value);
            } else {
                Type type = Type.getType(staticField.desc);
                switch (type.getSort()) {
                case Type.BOOLEAN:
                case Type.BYTE:
                case Type.CHAR:
                case Type.SHORT:
                case Type.INT:
                    mv.visitInsn(Opcodes.ICONST_0);
                    break;
                case Type.FLOAT:
                    mv.visitInsn(Opcodes.FCONST_0);
                    break;
                case Type.LONG:
                    mv.visitInsn(Opcodes.LCONST_0);
                    break;
                case Type.DOUBLE:
                    mv.visitInsn(Opcodes.DCONST_0);
                    break;
                case Type.ARRAY:
                case Type.OBJECT:
                    mv.visitInsn(Opcodes.ACONST_NULL);
                    break;
                }
            }
            mv.visitFieldInsn(Opcodes.PUTSTATIC, className, staticField.name, staticField.desc);
        }
    }

}

From source file:org.evosuite.seeding.PrimitivePoolMethodAdapter.java

License:Open Source License

@Override
public void visitInsn(int opcode) {
    Object constant = null;/*www.j  a  v a 2 s .c  om*/
    switch (opcode) {
    case Opcodes.ICONST_0:
        constant = 0;
        break;
    case Opcodes.ICONST_1:
        constant = 1;
        break;
    case Opcodes.ICONST_2:
        constant = 2;
        break;
    case Opcodes.ICONST_3:
        constant = 3;
        break;
    case Opcodes.ICONST_4:
        constant = 4;
        break;
    case Opcodes.ICONST_5:
        constant = 5;
        break;
    case Opcodes.ICONST_M1:
        constant = -1;
        break;
    case Opcodes.LCONST_0:
        constant = 0L;
        break;
    case Opcodes.LCONST_1:
        constant = 1L;
        break;
    case Opcodes.DCONST_0:
        constant = 0.0;
        break;
    case Opcodes.DCONST_1:
        constant = 1.0;
        break;
    case Opcodes.FCONST_0:
        constant = 0f;
        break;
    case Opcodes.FCONST_1:
        constant = 1f;
        break;
    case Opcodes.FCONST_2:
        constant = 2f;
        break;
    }
    if (constant != null) {
        if (DependencyAnalysis.isTargetClassName(className)) {
            poolManager.addSUTConstant(constant);
        } else {
            poolManager.addNonSUTConstant(constant);
        }
    }
    super.visitInsn(opcode);
}

From source file:org.glassfish.pfl.tf.spi.Util.java

License:Open Source License

public void initLocal(MethodVisitor mv, LocalVariableNode var) {
    info(2, "Initializing variable " + var);
    Type type = Type.getType(var.desc);
    switch (type.getSort()) {
    case Type.BYTE:
    case Type.BOOLEAN:
    case Type.CHAR:
    case Type.SHORT:
    case Type.INT:
        mv.visitInsn(Opcodes.ICONST_0);//from www  .  j  a  va2s. c om
        mv.visitVarInsn(Opcodes.ISTORE, var.index);
        break;

    case Type.LONG:
        mv.visitInsn(Opcodes.LCONST_0);
        mv.visitVarInsn(Opcodes.LSTORE, var.index);
        break;

    case Type.FLOAT:
        mv.visitInsn(Opcodes.FCONST_0);
        mv.visitVarInsn(Opcodes.FSTORE, var.index);
        break;

    case Type.DOUBLE:
        mv.visitInsn(Opcodes.DCONST_0);
        mv.visitVarInsn(Opcodes.DSTORE, var.index);
        break;

    default:
        mv.visitInsn(Opcodes.ACONST_NULL);
        mv.visitVarInsn(Opcodes.ASTORE, var.index);
    }
}

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.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 .  ja  va 2s . 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.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates the instruction to push the given value on the stack.
 *
 * @param value the value to be pushed on the stack.
 *///  ww w . j a  va 2s .  c o  m
public void push(final float value) {
    int bits = Float.floatToIntBits(value);
    if (bits == 0L || bits == 0x3f800000 || bits == 0x40000000) { // 0..2
        visitInsn(Opcodes.FCONST_0 + (int) value);
    } else {
        visitLdcInsn(new Float(value));
    }
}

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

    if (type == Type.I) {
        int val = value.intValue();
        // compile code to stack int value
        if (val >= -1 && val <= 5) {
            // we can use an iconst instruction
            mv.visitInsn(Opcodes.ICONST_0 + val);
        } else {//from  ww  w  .  j  av  a 2  s .c om
            // we have to add an integer constant to the constants pool
            mv.visitLdcInsn(value);
        }
        // we have only added 1 to the stack height

        compileContext.addStackCount(1);
    } else { // type = type.F
        float val = value.floatValue();
        if (val == 0.0) {
            // we can use an fconst instruction
            mv.visitInsn(Opcodes.FCONST_0);
        } else if (val == 1.0) {
            // we can use an fconst instruction
            mv.visitInsn(Opcodes.FCONST_1);
        } else if (val == 2.0) {
            // we can use an fconst instruction
            mv.visitInsn(Opcodes.FCONST_2);
        } else {
            // we have to add a float constant to the constants pool
            mv.visitLdcInsn(value);
        }

        // we have only added 1 to the stack height

        compileContext.addStackCount(1);
    }
}