Example usage for org.objectweb.asm Opcodes POP2

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

Introduction

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

Prototype

int POP2

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

Click Source Link

Usage

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

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    T t = null;//from w  w w. j ava2  s  .c  o  m
    int iValue = Integer.MIN_VALUE;
    Object oValue = null;

    switch (opcode) {
    case Opcodes.NOP:
        // nothing to do, ignore
        break;
    /*******
     * ADD *
     *******/
    case Opcodes.DADD:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FADD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IADD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LADD:
        if (t == null) {
            t = T.LONG;
        }
        add(new ADD(this.ops.size(), opcode, this.line, t));
        break;
    /*********
     * ALOAD *
     *********/
    case Opcodes.AALOAD:
        t = T.REF;
        // fall through
    case Opcodes.BALOAD:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CALOAD:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DALOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FALOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IALOAD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LALOAD:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SALOAD:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ALOAD(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * AND *
     *******/
    case Opcodes.IAND:
        t = T.AINT;
        // fall through
    case Opcodes.LAND:
        if (t == null) {
            t = T.LONG;
        }
        add(new AND(this.ops.size(), opcode, this.line, t));
        break;
    /***************
     * ARRAYLENGTH *
     ***************/
    case Opcodes.ARRAYLENGTH:
        add(new ARRAYLENGTH(this.ops.size(), opcode, this.line));
        break;
    /**********
     * ASTORE *
     **********/
    case Opcodes.AASTORE:
        t = T.REF;
        // fall through
    case Opcodes.BASTORE:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CASTORE:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DASTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FASTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IASTORE:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LASTORE:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SASTORE:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ASTORE(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * CAST *
     ********/
    case Opcodes.D2F:
        t = T.DOUBLE;
        oValue = T.FLOAT;
        // fall through
    case Opcodes.D2I:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.D2L:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.F2D:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.F2I:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.F2L:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2B:
        if (t == null) {
            t = T.INT;
            oValue = T.BYTE;
        }
        // fall through
    case Opcodes.I2C:
        if (t == null) {
            t = T.INT;
            oValue = T.CHAR;
        }
        // fall through
    case Opcodes.I2D:
        if (t == null) {
            t = T.INT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.I2F:
        if (t == null) {
            t = T.INT;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.I2L:
        if (t == null) {
            t = T.INT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2S:
        if (t == null) {
            t = T.INT;
            oValue = T.SHORT;
        }
        // fall through
    case Opcodes.L2D:
        if (t == null) {
            t = T.LONG;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.L2F:
        if (t == null) {
            t = T.LONG;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.L2I:
        if (t == null) {
            t = T.LONG;
            oValue = T.INT;
        }
        assert oValue instanceof T;
        add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue));
        break;
    /*******
     * CMP *
     *******/
    case Opcodes.DCMPG:
        t = T.DOUBLE;
        iValue = CMP.T_G;
        // fall through
    case Opcodes.DCMPL:
        if (t == null) {
            t = T.DOUBLE;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.FCMPG:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_G;
        }
        // fall through
    case Opcodes.FCMPL:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.LCMP:
        if (t == null) {
            t = T.LONG;
            iValue = CMP.T_0;
        }
        add(new CMP(this.ops.size(), opcode, this.line, t, iValue));
        break;
    /*******
     * DIV *
     *******/
    case Opcodes.DDIV:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FDIV:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IDIV:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LDIV:
        if (t == null) {
            t = T.LONG;
        }
        add(new DIV(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * DUP *
     *******/
    case Opcodes.DUP:
        oValue = DUP.Kind.DUP;
        // fall through
    case Opcodes.DUP_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X1;
        }
        // fall through
    case Opcodes.DUP_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X2;
        }
        // fall through
    case Opcodes.DUP2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2;
        }
        // fall through
    case Opcodes.DUP2_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X1;
        }
        // fall through
    case Opcodes.DUP2_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X2;
        }
        add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue));
        break;
    /***********
     * MONITOR *
     ***********/
    case Opcodes.MONITORENTER:
        oValue = MONITOR.Kind.ENTER;
        // fall through
    case Opcodes.MONITOREXIT:
        if (oValue == null) {
            oValue = MONITOR.Kind.EXIT;
        }
        add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue));
        break;
    /*******
     * MUL *
     *******/
    case Opcodes.DMUL:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FMUL:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IMUL:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LMUL:
        if (t == null) {
            t = T.LONG;
        }
        add(new MUL(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * NEG *
     *******/
    case Opcodes.DNEG:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FNEG:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.INEG:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LNEG:
        if (t == null) {
            t = T.LONG;
        }
        add(new NEG(this.ops.size(), opcode, this.line, t));
        break;
    /******
     * OR *
     ******/
    case Opcodes.IOR:
        t = T.AINT;
        // fall through
    case Opcodes.LOR:
        if (t == null) {
            t = T.LONG;
        }
        add(new OR(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * POP *
     *******/
    case Opcodes.POP:
        oValue = POP.Kind.POP;
        // fall through
    case Opcodes.POP2:
        if (oValue == null) {
            oValue = POP.Kind.POP2;
        }
        add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue));
        break;
    /********
     * PUSH *
     ********/
    case Opcodes.ACONST_NULL:
        t = T.REF;
        // fall through
    case Opcodes.DCONST_0:
        if (t == null) {
            oValue = 0D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_0:
        if (t == null) {
            oValue = 0F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_0:
        if (t == null) {
            oValue = 0;
            t = T.getJvmIntT(0);
        }
        // fall through
    case Opcodes.LCONST_0:
        if (t == null) {
            oValue = 0L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.DCONST_1:
        if (t == null) {
            oValue = 1D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_1:
        if (t == null) {
            oValue = 1F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_1:
        if (t == null) {
            oValue = 1;
            t = T.getJvmIntT(1);
        }
        // fall through
    case Opcodes.LCONST_1:
        if (t == null) {
            oValue = 1L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.FCONST_2:
        if (t == null) {
            oValue = 2F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_2:
        if (t == null) {
            oValue = 2;
            t = T.getJvmIntT(2);
        }
        // fall through
    case Opcodes.ICONST_3:
        if (t == null) {
            oValue = 3;
            t = T.getJvmIntT(3);
        }
        // fall through
    case Opcodes.ICONST_4:
        if (t == null) {
            oValue = 4;
            t = T.getJvmIntT(4);
        }
        // fall through
    case Opcodes.ICONST_5:
        if (t == null) {
            oValue = 5;
            t = T.getJvmIntT(5);
        }
        // fall through
    case Opcodes.ICONST_M1:
        if (t == null) {
            oValue = -1;
            t = T.getJvmIntT(-1);
        }
        add(new PUSH(this.ops.size(), opcode, this.line, t, oValue));
        break;
    /*******
     * REM *
     *******/
    case Opcodes.DREM:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FREM:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IREM:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LREM:
        if (t == null) {
            t = T.LONG;
        }
        add(new REM(this.ops.size(), opcode, this.line, t));
        break;
    /**********
     * RETURN *
     **********/
    case Opcodes.ARETURN:
        t = T.REF;
        // fall through
    case Opcodes.DRETURN:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FRETURN:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IRETURN:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LRETURN:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.RETURN:
        if (t == null) {
            t = T.VOID;
        }
        add(new RETURN(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * SHL *
     *******/
    case Opcodes.ISHL:
        t = T.INT;
        // fall through
    case Opcodes.LSHL:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHL(this.ops.size(), opcode, this.line, t, T.INT));
        break;
    /*******
     * SHR *
     *******/
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
        t = T.INT;
        // fall through
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHR(this.ops.size(), opcode, this.line, t, T.INT,
                opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR));
        break;
    /*******
     * SUB *
     *******/
    case Opcodes.DSUB:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FSUB:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISUB:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LSUB:
        if (t == null) {
            t = T.LONG;
        }
        add(new SUB(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * SWAP *
     ********/
    case Opcodes.SWAP:
        add(new SWAP(this.ops.size(), opcode, this.line));
        break;
    /*********
     * THROW *
     *********/
    case Opcodes.ATHROW:
        add(new THROW(this.ops.size(), opcode, this.line));
        break;
    /*******
     * XOR *
     *******/
    case Opcodes.IXOR:
        t = T.AINT;
        // fall through
    case Opcodes.LXOR: {
        if (t == null) {
            t = T.LONG;
        }
        add(new XOR(this.ops.size(), opcode, this.line, t));
        break;
    }
    default:
        log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!");
    }
}

From source file:org.elasticsearch.plan.a.External.java

License:Apache License

private void method(final ParserRuleContext source, final String name, final List<ExpressionContext> arguments,
        final boolean last) {
    final Struct struct = current.struct;

    Type[] types;/*from   w ww  . ja  v  a  2s . c  o  m*/
    Segment segment0;
    Segment segment1 = null;

    if (current.dimensions > 0) {
        throw new IllegalArgumentException(error(source) + "Unexpected call [" + name + "] on an array.");
    } else if (last && write != null) {
        throw new IllegalArgumentException(error(source) + "Cannot assign a value to a call [" + name + "].");
    } else if (statik && "makearray".equals(name)) {
        if (!read) {
            throw new IllegalArgumentException(error(source) + "A newly created array must be assigned.");
        }

        types = new Type[arguments.size()];
        Arrays.fill(types, standard.intType);
        segment0 = new MakeSegment(source, current, arguments.size());
        current = getTypeWithArrayDimensions(struct, arguments.size());
    } else {
        final Constructor constructor = statik ? struct.constructors.get(name) : null;
        final Method method = statik ? struct.functions.get(name) : struct.methods.get(name);

        if (constructor != null) {
            types = new Type[constructor.arguments.size()];
            constructor.arguments.toArray(types);

            segments.add(new NewSegment(source, constructor.owner));

            if (read) {
                segments.add(new InstructionSegment(source, Opcodes.DUP));
            } else {
                current = standard.voidType;
                statement = true;
            }

            segment0 = new ConstructorSegment(source, constructor);
        } else if (method != null) {
            types = new Type[method.arguments.size()];
            method.arguments.toArray(types);

            if (!read) {
                final int size = method.rtn.metadata.size;

                if (size == 1) {
                    segment1 = new InstructionSegment(source, Opcodes.POP);
                } else if (size == 2) {
                    segment1 = new InstructionSegment(source, Opcodes.POP2);
                } else if (size != 0) {
                    throw new IllegalStateException(error(source) + "Unexpected type size.");
                }

                current = standard.voidType;
                statement = true;
            } else {
                current = method.rtn;
            }

            segment0 = new MethodSegment(source, method);
        } else {
            throw new IllegalArgumentException(
                    error(source) + "Unknown call [" + name + "] on type [" + struct.name + "].");
        }
    }

    if (arguments.size() != types.length) {
        throw new IllegalArgumentException();
    }

    for (int argument = 0; argument < arguments.size(); ++argument) {
        final ExpressionContext exprctx = adapter.getExpressionContext(arguments.get(argument));
        final ExpressionMetadata expremd = adapter.createExpressionMetadata(exprctx);
        expremd.to = types[argument];
        analyzer.visit(exprctx);

        segments.add(new NodeSegment(exprctx));
    }

    segments.add(segment0);

    if (segment1 != null) {
        segments.add(segment1);
    }
}

From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // If non-static, add a null check

    if (opcode == Opcodes.GETFIELD) {
        mv.visitInsn(Opcodes.DUP);//  w ww .ja v a  2s .c  o m
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");

    } else if (opcode == Opcodes.PUTFIELD && !methodName.equals("<init>")) {
        if (Type.getType(desc).getSize() == 2) {
            // 2 words
            // v1 v2 v3
            mv.visitInsn(Opcodes.DUP2_X1);
            // v2 v3 v1 v2 v3

            mv.visitInsn(Opcodes.POP2);
            // v2 v3 v1

            mv.visitInsn(Opcodes.DUP_X2);
            // v1 v2 v3 v1

        } else {
            // 1 word
            mv.visitInsn(Opcodes.DUP2);
            //mv.visitInsn(Opcodes.SWAP);
            mv.visitInsn(Opcodes.POP);
        }
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");
    }
}

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

License:Open Source License

/** {@inheritDoc} */
@Override//from   ww w.ja  v a2  s  .  c  o m
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction,
        Frame frame) {

    List<Mutation> mutations = new LinkedList<Mutation>();

    MethodInsnNode node = (MethodInsnNode) instruction.getASMNode();
    Type returnType = Type.getReturnType(node.desc);

    // insert mutation into bytecode with conditional
    InsnList mutation = new InsnList();
    logger.info("Mutation deletestatement for statement " + node.name + node.desc);
    for (Type argType : Type.getArgumentTypes(node.desc)) {
        if (argType.getSize() == 0)
            logger.info("Ignoring parameter of type " + argType);
        else if (argType.getSize() == 2) {
            mutation.insert(new InsnNode(Opcodes.POP2));
            logger.debug("Deleting parameter of 2 type " + argType);
        } else {
            logger.debug("Deleting parameter of 1 type " + argType);
            mutation.insert(new InsnNode(Opcodes.POP));
        }
    }
    if (node.getOpcode() == Opcodes.INVOKEVIRTUAL) {
        logger.debug("Deleting callee of type " + node.owner);
        mutation.add(new InsnNode(Opcodes.POP));
    } else if (node.getOpcode() == Opcodes.INVOKEINTERFACE) {
        boolean isStatic = false;
        try {
            Class<?> clazz = Class.forName(node.owner.replace('/', '.'), false,
                    DeleteStatement.class.getClassLoader());
            for (java.lang.reflect.Method method : clazz.getMethods()) {
                if (method.getName().equals(node.name)) {
                    if (Type.getMethodDescriptor(method).equals(node.desc)) {
                        if (Modifier.isStatic(method.getModifiers()))
                            isStatic = true;
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            logger.warn("Could not find class: " + node.owner + ", this is likely a severe problem");
        }
        if (!isStatic) {
            logger.info("Deleting callee of type " + node.owner);
            mutation.add(new InsnNode(Opcodes.POP));
        }
    }
    mutation.add(getDefault(returnType));

    // insert mutation into pool
    Mutation mutationObject = MutationPool.addMutation(className, methodName,
            NAME + " " + node.name + node.desc, instruction, mutation, Mutation.getDefaultInfectionDistance());

    mutations.add(mutationObject);
    return mutations;
}

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

License:Open Source License

/** {@inheritDoc} */
@Override/*from ww w  .j  a  v a 2 s.  c  om*/
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction,
        Frame frame) {
    JumpInsnNode node = (JumpInsnNode) instruction.getASMNode();
    List<Mutation> mutations = new LinkedList<Mutation>();
    LabelNode target = node.label;

    boolean isBoolean = frame.getStack(frame.getStackSize() - 1) == BooleanValueInterpreter.BOOLEAN_VALUE;

    for (Integer op : getOperators(node.getOpcode(), isBoolean)) {
        logger.debug("Adding replacement " + op);
        if (op >= 0) {
            // insert mutation into bytecode with conditional
            JumpInsnNode mutation = new JumpInsnNode(op, target);
            // insert mutation into pool
            Mutation mutationObject = MutationPool.addMutation(className, methodName,
                    NAME + " " + getOp(node.getOpcode()) + " -> " + getOp(op), instruction, mutation,
                    getInfectionDistance(node.getOpcode(), op));
            mutations.add(mutationObject);
        } else {
            // Replace relational operator with TRUE/FALSE

            InsnList mutation = new InsnList();
            if (opcodesInt.contains(node.getOpcode()))
                mutation.add(new InsnNode(Opcodes.POP));
            else
                mutation.add(new InsnNode(Opcodes.POP2));
            if (op == TRUE) {
                mutation.add(new LdcInsnNode(1));
            } else {
                mutation.add(new LdcInsnNode(0));
            }
            mutation.add(new JumpInsnNode(Opcodes.IFNE, target));
            Mutation mutationObject = MutationPool.addMutation(className, methodName,
                    NAME + " " + getOp(node.getOpcode()) + " -> " + op, instruction, mutation,
                    getInfectionDistance(node.getOpcode(), op));
            mutations.add(mutationObject);
        }
    }

    return mutations;
}

From source file:org.evosuite.instrumentation.RemoveFinalMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w ww  .jav a 2s.  co m
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    if ((opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) && owner.equals(className)) {

        if (!finalFields.contains(name)) {
            //System.out.println("Keeping non-final field " + name + " in class "
            //        + owner);
            super.visitFieldInsn(opcode, owner, name, desc);
        } else {
            //System.out.println("Omitting final field " + name + " in class " + owner);
            Type type = Type.getType(desc);
            if (type.getSize() == 1)
                super.visitInsn(Opcodes.POP);
            else if (type.getSize() == 2)
                super.visitInsn(Opcodes.POP2);
            if (opcode == Opcodes.PUTFIELD)
                super.visitInsn(Opcodes.POP);
        }
    } else {
        //if (!owner.equals(className))
        //   System.out.println("Mismatch: " + className + " / " + owner);
        super.visitFieldInsn(opcode, owner, name, desc);
    }
}

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

License:Open Source License

/**
 * Calls to cobertura methods are removed to avoid that code coverage
 * data is deleted//w w w .  ja  v  a2s .  c o  m
 */
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
    if (opcode == Opcodes.INVOKESTATIC && name.startsWith("__cobertura")) {
        for (Type parameterType : Type.getArgumentTypes(desc)) {
            if (parameterType.getSize() == 1) {
                super.visitInsn(Opcodes.POP);
            } else if (parameterType.getSize() == 2) {
                super.visitInsn(Opcodes.POP2);
            }
        }
    } else {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
    }
}

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

License:Open Source License

private void instrumentGETXXXFieldAccesses(final ClassNode cn, final String internalClassName,
        final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;

    AbstractInsnNode ins = null;//w w w .j  a v  a2  s  .  c  o m
    FieldInsnNode fieldIns = null;

    for (int i = 0; i < instructions.size(); i++) {
        ins = instructions.get(i);
        if (ins instanceof FieldInsnNode) {
            fieldIns = (FieldInsnNode) ins;

            /*
             * Is field referencing outermost instance? if yes, ignore it
             * http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
             */
            if (fieldIns.name.endsWith("$0")) {
                continue;
            }

            final int opcode = ins.getOpcode();
            if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
                final InsnList il = new InsnList();

                if (opcode == Opcodes.GETFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        il.add(new InsnNode(Opcodes.SWAP));
                    } else if (fieldType.getSize() == 2) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        // v
                        // GETFIELD
                        // v, w
                        il.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        il.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        // -> Call
                        // w
                    }
                } else
                    il.add(new InsnNode(Opcodes.ACONST_NULL));

                il.add(new LdcInsnNode(this.captureId));
                il.add(new LdcInsnNode(fieldIns.owner));
                il.add(new LdcInsnNode(fieldIns.name));
                il.add(new LdcInsnNode(fieldIns.desc));

                il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                        PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.FieldRegistry.class),
                        "notifyReadAccess",
                        "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));

                i += il.size();

                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}

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

License:Open Source License

private void instrumentPUTXXXFieldAccesses(final ClassNode cn, final String internalClassName,
        final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;

    AbstractInsnNode ins = null;//from  w w w .jav a  2 s .  c o  m
    FieldInsnNode fieldIns = null;

    // needed get right receiver var in case of PUTFIELD

    for (int i = 0; i < instructions.size(); i++) {
        ins = instructions.get(i);
        if (ins instanceof FieldInsnNode) {
            fieldIns = (FieldInsnNode) ins;

            /*
             * Is field referencing outermost instance? if yes, ignore it
             * http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
             */
            if (fieldIns.name.endsWith("$0")) {
                continue;
            }

            final int opcode = ins.getOpcode();
            if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
                // construction of  
                //   Capturer.capture(final Object receiver, final String methodName, final Object[] methodParams)
                // call
                final InsnList il = new InsnList();

                if (opcode == Opcodes.PUTFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP2));
                        il.add(new InsnNode(Opcodes.POP));
                    } else if (fieldType.getSize() == 2) {
                        InsnList uglyList = new InsnList();
                        // v, w
                        uglyList.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        uglyList.add(new InsnNode(Opcodes.DUP));
                        // w, v, v
                        uglyList.add(new InsnNode(Opcodes.DUP2_X2));
                        // v, v, w, v, v
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // v, v, w
                        instructions.insertBefore(fieldIns, uglyList);
                        // PUTFIELD
                        // v
                    }
                } else
                    il.add(new InsnNode(Opcodes.ACONST_NULL));

                il.add(new LdcInsnNode(this.captureId));
                il.add(new LdcInsnNode(fieldIns.owner));
                il.add(new LdcInsnNode(fieldIns.name));
                il.add(new LdcInsnNode(fieldIns.desc));

                il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                        PackageInfo.getNameWithSlash(FieldRegistry.class), "notifyModification",
                        "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));

                // PUTFIELDRegistry.notifyModification also adds corresponding GETFIELD capture instructions
                this.captureId++;
                i += il.size();

                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}

From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompilerForDoubles_Base.java

License:Open Source License

@Override
protected void compilePop() {
    mv().visitInsn(Opcodes.POP2);
}