Example usage for org.objectweb.asm Opcodes FLOAD

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

Introduction

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

Prototype

int FLOAD

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

Click Source Link

Usage

From source file:org.boretti.drools.integration.drools5.DroolsAbstractMethodVisitor.java

License:Open Source License

private void addCondition(boolean preCondition, String type, String resourceName, Type error) {
    droolsGoalExecutionLog.getLogs()//www  .jav a  2 s. co m
            .add(new DroolsGoalExecutionLog(droolsGoalExecutionLog.getFileName(),
                    droolsGoalExecutionLog.getAction(), "Method instrumentalization for "
                            + ((preCondition) ? "pre" : "post") + "-condition " + name + "/" + desc));
    visitor.setMethodChange(true);
    Type types[] = Type.getArgumentTypes(super.methodDesc);
    //runPreCondition
    this.visitVarInsn(Opcodes.ALOAD, 0);
    this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getObjectType(parent).getInternalName(), "getClass",
            "()Ljava/lang/Class;");
    if (type == null)
        type = "COMPILED";
    this.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(DroolsServiceType.class), type,
            Type.getDescriptor(DroolsServiceType.class));
    this.visitLdcInsn(resourceName);
    this.visitLdcInsn(error);
    this.visitVarInsn(Opcodes.ALOAD, 0);
    this.visitIntInsn(Opcodes.BIPUSH, types.length);
    this.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    int position = 1;
    for (int i = 0; i < types.length; i++) {
        this.visitInsn(Opcodes.DUP);
        this.visitIntInsn(Opcodes.BIPUSH, i);
        if (types[i].equals(Type.BOOLEAN_TYPE)) {
            this.visitVarInsn(Opcodes.ILOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Boolean.class), "valueOf",
                    "(Z)Ljava/lang/Boolean;");
            position += 1;
        } else if (types[i].equals(Type.BYTE_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Byte");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.ILOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Byte.class), "<init>", "(B)V");
            position += 1;
        } else if (types[i].equals(Type.CHAR_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Character");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.ILOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Character.class), "<init>",
                    "(C)V");
            position += 1;
        } else if (types[i].equals(Type.DOUBLE_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Double");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.DLOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Double.class), "<init>", "(D)V");
            position += 2;
        } else if (types[i].equals(Type.FLOAT_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Float");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.FLOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Float.class), "<init>", "(F)V");
            position += 1;
        } else if (types[i].equals(Type.INT_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Integer");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.ILOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V");
            position += 1;
        } else if (types[i].equals(Type.LONG_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Long");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.LLOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V");
            position += 2;
        } else if (types[i].equals(Type.SHORT_TYPE)) {
            this.visitTypeInsn(Opcodes.NEW, "java/lang/Short");
            this.visitInsn(Opcodes.DUP);
            this.visitVarInsn(Opcodes.ILOAD, position);
            this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Short.class), "<init>", "(S)V");
            position += 1;
        } else {
            this.visitVarInsn(Opcodes.ALOAD, position);
            position += 1;
        }
        this.visitInsn(Opcodes.AASTORE);
    }
    if (preCondition)
        this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class),
                "runPreCondition",
                "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V");
    else
        this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class),
                "runPostCondition",
                "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V");
}

From source file:org.brutusin.instrumentation.utils.TreeInstructions.java

License:Apache License

public static VarInsnNode getLoadInst(Type type, int position) {
    int opCode = -1;
    switch (type.getDescriptor().charAt(0)) {
    case 'B':
        opCode = Opcodes.ILOAD;/*from www  . j  a v  a2 s  . co  m*/
        break;
    case 'C':
        opCode = Opcodes.ILOAD;
        break;
    case 'D':
        opCode = Opcodes.DLOAD;
        break;
    case 'F':
        opCode = Opcodes.FLOAD;
        break;
    case 'I':
        opCode = Opcodes.ILOAD;
        break;
    case 'J':
        opCode = Opcodes.LLOAD;
        break;
    case 'L':
        opCode = Opcodes.ALOAD;
        break;
    case '[':
        opCode = Opcodes.ALOAD;
        break;
    case 'Z':
        opCode = Opcodes.ILOAD;
        break;
    case 'S':
        opCode = Opcodes.ILOAD;
        break;
    default:
        throw new ClassFormatError("Invalid method signature: " + type.getDescriptor());
    }
    return new VarInsnNode(opCode, position);
}

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitVarInsn(final int opcode, final int var) {
    T t = null;// ww  w.j  a  v a 2s . c om

    switch (opcode) {
    /********
     * LOAD *
     ********/
    case Opcodes.ALOAD:
        t = T.REF;
        // fall through
    case Opcodes.DLOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FLOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ILOAD:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LLOAD:
        if (t == null) {
            t = T.LONG;
        }
        add(new LOAD(this.ops.size(), opcode, this.line, t, var));
        break;
    /*********
     * STORE *
     *********/
    case Opcodes.ASTORE:
        t = T.AREF; // RET allowed too
        // fall through
    case Opcodes.DSTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FSTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISTORE:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LSTORE:
        if (t == null) {
            t = T.LONG;
        }
        add(new STORE(this.ops.size(), opcode, this.line, t, var));
        break;
    /*******
     * RET *
     *******/
    case Opcodes.RET: {
        add(new RET(this.ops.size(), opcode, this.line, var));
        break;
    }
    default:
        log.warn(getM() + ": Unknown var insn opcode '" + opcode + "'!");
    }
}

From source file:org.evosuite.graphs.cfg.ASMWrapper.java

License:Open Source License

/**
 * <p>/*from   w  w w . ja  va  2  s  . c o  m*/
 * isLocalVarUse
 * </p>
 * 
 * @return a boolean.
 */
public boolean isLocalVariableUse() {
    return asmNode.getOpcode() == Opcodes.ILOAD || asmNode.getOpcode() == Opcodes.LLOAD
            || asmNode.getOpcode() == Opcodes.FLOAD || asmNode.getOpcode() == Opcodes.DLOAD
            || asmNode.getOpcode() == Opcodes.IINC
            || (asmNode.getOpcode() == Opcodes.ALOAD && !loadsReferenceToThis());
}

From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java

License:Open Source License

/**
 * Determine how many bytes the current instruction occupies together with
 * its operands/* w  ww  .  j a  v  a2  s  .  c o  m*/
 * 
 * @return
 */
private int getBytecodeIncrement(AbstractInsnNode instructionNode) {
    int opcode = instructionNode.getOpcode();
    switch (opcode) {
    case Opcodes.ALOAD: // index
    case Opcodes.ASTORE: // index
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
        VarInsnNode varNode = (VarInsnNode) instructionNode;
        if (varNode.var > 3)
            return 1;
        else
            return 0;
    case Opcodes.BIPUSH: // byte
    case Opcodes.NEWARRAY:
    case Opcodes.RET:
        return 1;
    case Opcodes.LDC:
        LdcInsnNode ldcNode = (LdcInsnNode) instructionNode;
        if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long)
            return 2; // LDC2_W
        else
            return 1;
    case 19: //LDC_W
    case 20: //LDC2_W
        return 2;
    case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2
    case Opcodes.CHECKCAST: // indexbyte1, indexbyte2
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
    case Opcodes.GOTO:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFNE:
    case Opcodes.IFEQ:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
    case Opcodes.IINC:
    case Opcodes.INSTANCEOF:
    case Opcodes.INVOKESPECIAL:
    case Opcodes.INVOKESTATIC:
    case Opcodes.INVOKEVIRTUAL:
    case Opcodes.JSR:
    case Opcodes.NEW:
    case Opcodes.PUTFIELD:
    case Opcodes.PUTSTATIC:
    case Opcodes.SIPUSH:
        // case Opcodes.LDC_W
        // case Opcodes.LDC2_W

        return 2;
    case Opcodes.MULTIANEWARRAY:
        return 3;
    case Opcodes.INVOKEDYNAMIC:
    case Opcodes.INVOKEINTERFACE:
        return 4;

    case Opcodes.LOOKUPSWITCH:
    case Opcodes.TABLESWITCH:
        // TODO: Could be more
        return 4;
    // case Opcodes.GOTO_W 
    // case Opcodes.JSR_W
    }
    return 0;
}

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

License:Open Source License

/** {@inheritDoc} */
@Override/*from  w w  w  .j a  v a 2 s.  c o  m*/
public boolean isApplicable(BytecodeInstruction instruction) {
    AbstractInsnNode node = instruction.getASMNode();
    switch (node.getOpcode()) {
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
        return true;
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
        FieldInsnNode fieldNode = (FieldInsnNode) instruction.getASMNode();
        Type type = Type.getType(fieldNode.desc);
        if (type == Type.BYTE_TYPE || type == Type.SHORT_TYPE || type == Type.LONG_TYPE
                || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.BOOLEAN_TYPE
                || type == Type.INT_TYPE) {
            return true;
        }
    default:
        return false;
    }
}

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

License:Open Source License

private int getNegation(int opcode) {
    switch (opcode) {
    case Opcodes.ILOAD:
        return Opcodes.INEG;
    case Opcodes.LLOAD:
        return Opcodes.LNEG;
    case Opcodes.FLOAD:
        return Opcodes.FNEG;
    case Opcodes.DLOAD:
        return Opcodes.DNEG;
    default://from   w w  w  . ja  va2 s .c om
        throw new RuntimeException("Invalid opcode for negation: " + opcode);
    }
}

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

License:Open Source License

@SuppressWarnings("rawtypes")
private static int getNextIndexFromLoad(MethodNode mn) {
    Iterator it = mn.instructions.iterator();
    int index = 0;
    while (it.hasNext()) {
        AbstractInsnNode node = (AbstractInsnNode) it.next();
        if (node instanceof VarInsnNode) {
            VarInsnNode varNode = (VarInsnNode) node;
            int varIndex = varNode.var;
            switch (varNode.getOpcode()) {
            case Opcodes.ALOAD:
            case Opcodes.ILOAD:
            case Opcodes.FLOAD:
            case Opcodes.IALOAD:
            case Opcodes.BALOAD:
            case Opcodes.CALOAD:
            case Opcodes.AALOAD:
            case Opcodes.ASTORE:
            case Opcodes.ISTORE:
            case Opcodes.FSTORE:
            case Opcodes.IASTORE:
            case Opcodes.BASTORE:
            case Opcodes.CASTORE:
            case Opcodes.AASTORE:
                index = Math.max(index, varIndex + 1);
                break;
            case Opcodes.DLOAD:
            case Opcodes.DSTORE:
            case Opcodes.LLOAD:
            case Opcodes.LSTORE:
            case Opcodes.DALOAD:
            case Opcodes.DASTORE:
            case Opcodes.LALOAD:
            case Opcodes.LASTORE:
                index = Math.max(index, varIndex + 2);
                break;
            }//from  w w  w . ja v a 2 s .c om
        }
    }

    return index;
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

private void addLoadInsn(final InsnList il, final Type type, final int argLocation) {
    if (type.equals(Type.BOOLEAN_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
    } else if (type.equals(Type.CHAR_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
    } else if (type.equals(Type.BYTE_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
    } else if (type.equals(Type.SHORT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
    } else if (type.equals(Type.INT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
    } else if (type.equals(Type.FLOAT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.FLOAD, argLocation));
    } else if (type.equals(Type.LONG_TYPE)) {
        il.add(new VarInsnNode(Opcodes.LLOAD, argLocation));
    } else if (type.equals(Type.DOUBLE_TYPE)) {
        il.add(new VarInsnNode(Opcodes.DLOAD, argLocation));
    } else {//from   w ww.j  a v  a  2  s. c  om
        il.add(new VarInsnNode(Opcodes.ALOAD, argLocation));
    }
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

private void loadAndConvertToObject(final InsnList il, final Type type, final int argLocation) {
    if (type.equals(Type.BOOLEAN_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf",
                "(Z)Ljava/lang/Boolean;"));
    } else if (type.equals(Type.CHAR_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf",
                "(C)Ljava/lang/Character;"));
    } else if (type.equals(Type.BYTE_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"));
    } else if (type.equals(Type.SHORT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"));
    } else if (type.equals(Type.INT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.ILOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf",
                "(I)Ljava/lang/Integer;"));
    } else if (type.equals(Type.FLOAT_TYPE)) {
        il.add(new VarInsnNode(Opcodes.FLOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"));
    } else if (type.equals(Type.LONG_TYPE)) {
        il.add(new VarInsnNode(Opcodes.LLOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"));
    } else if (type.equals(Type.DOUBLE_TYPE)) {
        il.add(new VarInsnNode(Opcodes.DLOAD, argLocation));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf",
                "(D)Ljava/lang/Double;"));
    } else {//from   ww w.ja  va 2s  .  c o  m
        il.add(new VarInsnNode(Opcodes.ALOAD, argLocation));
    }
}