Example usage for org.objectweb.asm Opcodes IF_ICMPEQ

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

Introduction

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

Prototype

int IF_ICMPEQ

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

Click Source Link

Usage

From source file:lucee.transformer.bytecode.statement.tag.TagHelper.java

License:Open Source License

/**
 * writes out the tag/*from  w  w  w  .  j  av a 2  s.  c o m*/
 * @param tag
 * @param bc
 * @param doReuse
 * @throws BytecodeException
 */
public static void writeOut(Tag tag, BytecodeContext bc, boolean doReuse, final FlowControlFinal fcf)
        throws BytecodeException {
    final GeneratorAdapter adapter = bc.getAdapter();
    final TagLibTag tlt = tag.getTagLibTag();
    final Type currType = getTagType(tag);

    final int currLocal = adapter.newLocal(currType);
    Label tagBegin = new Label();
    Label tagEnd = new Label();
    ExpressionUtil.visitLine(bc, tag.getStart());
    // TODO adapter.visitLocalVariable("tag", "L"+currType.getInternalName()+";", null, tagBegin, tagEnd, currLocal);

    adapter.visitLabel(tagBegin);

    // tag=pc.use(str);
    adapter.loadArg(0);
    adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    adapter.push(tlt.getTagClassName());
    adapter.push(tlt.getFullName());
    adapter.push(tlt.getAttributeType());
    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, USE3);
    adapter.checkCast(currType);
    adapter.storeLocal(currLocal);

    TryFinallyVisitor outerTcfv = new TryFinallyVisitor(new OnFinally() {
        public void _writeOut(BytecodeContext bc) {

            adapter.loadArg(0);
            adapter.loadLocal(currLocal);
            adapter.invokeVirtual(Types.PAGE_CONTEXT, RE_USE);
        }
    }, null);
    if (doReuse)
        outerTcfv.visitTryBegin(bc);

    // appendix
    if (tlt.hasAppendix()) {
        adapter.loadLocal(currLocal);
        adapter.push(tag.getAppendix());
        adapter.invokeVirtual(currType, SET_APPENDIX);
    }

    // hasBody
    boolean hasBody = tag.getBody() != null;
    if (tlt.isBodyFree() && tlt.hasBodyMethodExists()) {
        adapter.loadLocal(currLocal);
        adapter.push(hasBody);
        adapter.invokeVirtual(currType, HAS_BODY);
    }

    // default attributes (get overwritten by attributeCollection because of that set before)
    setAttributes(bc, tag, currLocal, currType, true);

    // attributeCollection
    Attribute attrColl = tag.getAttribute("attributecollection");
    if (attrColl != null) {
        int attrType = tag.getTagLibTag().getAttributeType();
        if (TagLibTag.ATTRIBUTE_TYPE_NONAME != attrType) {
            tag.removeAttribute("attributecollection");
            // TagUtil.setAttributeCollection(Tag, Struct)
            adapter.loadArg(0);
            adapter.loadLocal(currLocal);
            adapter.cast(currType, TAG);

            ///
            TagLibTagAttr[] missings = tag.getMissingAttributes();
            if (!ArrayUtil.isEmpty(missings)) {
                ArrayVisitor av = new ArrayVisitor();
                av.visitBegin(adapter, MISSING_ATTRIBUTE, missings.length);
                int count = 0;
                TagLibTagAttr miss;
                for (int i = 0; i < missings.length; i++) {
                    miss = missings[i];
                    av.visitBeginItem(adapter, count++);
                    Variable.registerKey(bc, LitString.toExprString(miss.getName()));
                    adapter.push(miss.getType());
                    if (ArrayUtil.isEmpty(miss.getAlias()))
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX2);
                    else {
                        new LiteralStringArray(miss.getAlias()).writeOut(bc, Expression.MODE_REF);
                        adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX3);
                    }
                    av.visitEndItem(bc.getAdapter());
                }
                av.visitEnd();
            } else {
                ASMConstants.NULL(adapter);
            }
            ///
            attrColl.getValue().writeOut(bc, Expression.MODE_REF);

            adapter.push(attrType);
            adapter.invokeStatic(TAG_UTIL, SET_ATTRIBUTE_COLLECTION);
        }
    }

    // metadata
    Attribute attr;
    Map<String, Attribute> metadata = tag.getMetaData();
    if (metadata != null) {
        Iterator<Attribute> it = metadata.values().iterator();
        while (it.hasNext()) {
            attr = it.next();
            adapter.loadLocal(currLocal);
            adapter.push(attr.getName());
            attr.getValue().writeOut(bc, Expression.MODE_REF);
            adapter.invokeVirtual(currType, SET_META_DATA);
        }
    }

    // set attributes
    setAttributes(bc, tag, currLocal, currType, false);

    // Body
    if (hasBody) {
        final int state = adapter.newLocal(Types.INT_VALUE);

        // int state=tag.doStartTag();
        adapter.loadLocal(currLocal);
        adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.storeLocal(state);

        // if (state!=Tag.SKIP_BODY)
        Label endBody = new Label();
        adapter.loadLocal(state);
        adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_BODY);
        adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endBody);
        // pc.initBody(tag, state);
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.loadLocal(state);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, INIT_BODY);

        OnFinally onFinally = new OnFinally() {

            public void _writeOut(BytecodeContext bc) {
                Label endIf = new Label();
                /*if(tlt.handleException() && fcf!=null && fcf.getAfterFinalGOTOLabel()!=null){
                   ASMUtil.visitLabel(adapter, fcf.getFinalEntryLabel());
                }*/
                adapter.loadLocal(state);
                adapter.push(javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE);
                adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endIf);
                // ... pc.popBody();
                adapter.loadArg(0);
                adapter.invokeVirtual(Types.PAGE_CONTEXT, POP_BODY);
                adapter.pop();
                adapter.visitLabel(endIf);

                // tag.doFinally();
                if (tlt.handleException()) {
                    adapter.loadLocal(currLocal);
                    adapter.invokeVirtual(currType, DO_FINALLY);
                }
                // GOTO after execution body, used when a continue/break was called before
                /*if(fcf!=null) {
                   Label l = fcf.getAfterFinalGOTOLabel();
                   if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
                }*/

            }
        };

        if (tlt.handleException()) {
            TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(onFinally, fcf);
            tcfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType);
            int t = tcfv.visitTryEndCatchBeging(bc);
            // tag.doCatch(t);
            adapter.loadLocal(currLocal);
            adapter.loadLocal(t);
            //adapter.visitVarInsn(Opcodes.ALOAD,t);
            adapter.invokeVirtual(currType, DO_CATCH);
            tcfv.visitCatchEnd(bc);
        } else {
            TryFinallyVisitor tfv = new TryFinallyVisitor(onFinally, fcf);
            tfv.visitTryBegin(bc);
            doTry(bc, adapter, tag, currLocal, currType);
            tfv.visitTryEnd(bc);
        }

        adapter.visitLabel(endBody);

    } else {
        //tag.doStartTag();
        adapter.loadLocal(currLocal);
        adapter.invokeVirtual(currType, DO_START_TAG);
        adapter.pop();
    }

    // if (tag.doEndTag()==Tag.SKIP_PAGE) throw new Abort(0<!-- SCOPE_PAGE -->);
    Label endDoEndTag = new Label();
    adapter.loadLocal(currLocal);
    adapter.invokeVirtual(currType, DO_END_TAG);
    adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_PAGE);
    adapter.visitJumpInsn(Opcodes.IF_ICMPNE, endDoEndTag);
    adapter.push(Abort.SCOPE_PAGE);
    adapter.invokeStatic(ABORT, NEW_INSTANCE);
    adapter.throwException();
    adapter.visitLabel(endDoEndTag);

    if (doReuse) {
        // } finally{pc.reuse(tag);}
        outerTcfv.visitTryEnd(bc);
    }

    adapter.visitLabel(tagEnd);
    ExpressionUtil.visitLine(bc, tag.getEnd());
}

From source file:lucee.transformer.bytecode.statement.tag.TagHelper.java

License:Open Source License

private static void doTry(BytecodeContext bc, GeneratorAdapter adapter, Tag tag, int currLocal, Type currType)
        throws BytecodeException {
    Label beginDoWhile = new Label();
    adapter.visitLabel(beginDoWhile);//from   w w  w  .  ja v a 2s  . c om
    bc.setCurrentTag(currLocal);
    tag.getBody().writeOut(bc);

    // while (tag.doAfterBody()==BodyTag.EVAL_BODY_AGAIN);
    adapter.loadLocal(currLocal);
    adapter.invokeVirtual(currType, DO_AFTER_BODY);
    adapter.push(IterationTag.EVAL_BODY_AGAIN);
    adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, beginDoWhile);
}

From source file:name.martingeisse.minimal.compiler.Compiler.java

License:Open Source License

/**
 * Compiles a {@link MethodNode} to MCode.
 * //from   ww  w.  j  av  a  2  s.c o m
 * @param methodNode the method node to compile
 * @return the compiled code
 */
public ImmutableList<MCodeEntry> compile(final MethodNode methodNode) {
    for (int i = 0; i < methodNode.instructions.size(); i++) {
        final AbstractInsnNode instruction = methodNode.instructions.get(i);
        if (instruction instanceof LineNumberNode) {
            // ignored
        } else if (instruction instanceof FrameNode) {
            // this could be useful in the future
        } else if (instruction instanceof LabelNode) {
            label(((LabelNode) instruction).getLabel());
        } else if (instruction instanceof InsnNode) {
            switch (instruction.getOpcode()) {

            case Opcodes.ICONST_M1:
                iconst(-1);
                break;

            case Opcodes.ICONST_0:
                iconst(0);
                break;

            case Opcodes.ICONST_1:
                iconst(1);
                break;

            case Opcodes.ICONST_2:
                iconst(2);
                break;

            case Opcodes.ICONST_3:
                iconst(3);
                break;

            case Opcodes.ICONST_4:
                iconst(4);
                break;

            case Opcodes.ICONST_5:
                iconst(5);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof VarInsnNode) {
            final VarInsnNode varInsnNode = (VarInsnNode) instruction;
            switch (varInsnNode.getOpcode()) {

            case Opcodes.ILOAD:
                iload(varInsnNode.var);
                break;

            case Opcodes.ISTORE:
                istore(varInsnNode.var);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IincInsnNode) {
            final IincInsnNode iincInsnNode = (IincInsnNode) instruction;
            iinc(iincInsnNode.var, iincInsnNode.incr);
        } else if (instruction instanceof JumpInsnNode) {
            final JumpInsnNode jumpInsnNode = (JumpInsnNode) instruction;
            switch (jumpInsnNode.getOpcode()) {

            case Opcodes.IFEQ:
            case Opcodes.IFNE:
            case Opcodes.IFLT:
            case Opcodes.IFGE:
            case Opcodes.IFGT:
            case Opcodes.IFLE:
                branch1(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IF_ICMPEQ:
            case Opcodes.IF_ICMPNE:
            case Opcodes.IF_ICMPLT:
            case Opcodes.IF_ICMPGE:
            case Opcodes.IF_ICMPGT:
            case Opcodes.IF_ICMPLE:
                branch2(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IFNULL:
            case Opcodes.IFNONNULL:
                // unsupported: one-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.IF_ACMPEQ:
            case Opcodes.IF_ACMPNE:
                // unsupported: two-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.GOTO:
                jump(jumpInsnNode.label.getLabel());
                break;

            case Opcodes.JSR:
                jsr(jumpInsnNode.label.getLabel());
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IntInsnNode) {
            final IntInsnNode intInsnNode = (IntInsnNode) instruction;
            if (instruction.getOpcode() == Opcodes.BIPUSH || instruction.getOpcode() == Opcodes.SIPUSH) {
                iconst(intInsnNode.operand);
            } else {
                // NEWARRAY
                unsupported(instruction);
            }
        } else if (instruction instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
            if (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) {
                if (methodInsnNode.owner.replace('/', '.').equals(Native.class.getName())) {
                    nativeCall(methodInsnNode.name, methodInsnNode.desc);
                } else {
                    unsupported(instruction);
                }
            } else {
                unsupported(instruction);
            }
        } else {
            unsupported(instruction);
        }
    }
    return builder.build();
}

From source file:name.martingeisse.minimal.compiler.Compiler.java

License:Open Source License

private MBinaryIntegerOperator mapOperator(final int jvmOpcode) {
    switch (jvmOpcode) {

    case Opcodes.IFEQ:
    case Opcodes.IF_ICMPEQ:
        return MBinaryIntegerOperator.EQUAL;

    case Opcodes.IFNE:
    case Opcodes.IF_ICMPNE:
        return MBinaryIntegerOperator.NOT_EQUAL;

    case Opcodes.IFLT:
    case Opcodes.IF_ICMPLT:
        return MBinaryIntegerOperator.LESS_THAN;

    case Opcodes.IFLE:
    case Opcodes.IF_ICMPLE:
        return MBinaryIntegerOperator.LESS_THAN_OR_EQUAL;

    case Opcodes.IFGT:
    case Opcodes.IF_ICMPGT:
        return MBinaryIntegerOperator.GREATER_THAN;

    case Opcodes.IFGE:
    case Opcodes.IF_ICMPGE:
        return MBinaryIntegerOperator.GREATER_THAN_OR_EQUAL;

    default:/*w ww  . ja  v  a2  s. c om*/
        throw new IllegalArgumentException("cannot map comparison operator for JVM opcode: " + jvmOpcode);

    }
}

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

License:Open Source License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    T t = null;/*w  w w . ja  v  a  2s.co m*/
    Object oValue = null;

    final int targetPc = getPc(label);

    switch (opcode) {
    /********
     * GOTO *
     ********/
    case Opcodes.GOTO: {
        final GOTO op = new GOTO(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    /********
     * JCMP *
     ********/
    case Opcodes.IF_ACMPEQ:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IF_ACMPNE:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IF_ICMPEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IF_ICMPGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IF_ICMPGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IF_ICMPLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IF_ICMPLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IF_ICMPNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /********
     * JCND *
     ********/
    case Opcodes.IFNULL:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IFNONNULL:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IFEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IFGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IFGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IFLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IFLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IFNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /*******
     * JSR *
     *******/
    case Opcodes.JSR: {
        final JSR op = new JSR(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    default:
        log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!");
    }
}

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//from w w  w .j av a 2 s. co  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.coverage.BranchInstrumentation.java

License:Open Source License

/**
 * <p>//from   w  ww.jav a 2s.  co m
 * getInstrumentation
 * </p>
 *
 * @param instruction
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
protected InsnList getInstrumentation(BytecodeInstruction instruction) {
    if (instruction == null)
        throw new IllegalArgumentException("null given");
    if (!instruction.isActualBranch())
        throw new IllegalArgumentException("branch instruction expected");
    if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction))
        throw new IllegalArgumentException(
                "expect given instruction to be known by the BranchPool as a normal branch instruction");

    int opcode = instruction.getASMNode().getOpcode();
    int instructionId = instruction.getInstructionId();
    int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction);
    if (branchId < 0)
        throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions");

    InsnList instrumentation = new InsnList();

    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
        logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id="
                + instructionId);

        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
        break;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;Ljava/lang/Object;III)V", false));
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;III)V", false));
        break;
    }
    return instrumentation;
}

From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java

License:Open Source License

/**
 * For each actual case <key>: of a switch this method adds instrumentation
 * for the Branch corresponding to that case to the given instruction list.
 *
 * @param v/*w w w  .j  av a  2 s  . c  o  m*/
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @param className
 *            a {@link java.lang.String} object.
 * @param methodName
 *            a {@link java.lang.String} object.
 */
protected void addInstrumentationForSwitchCases(BytecodeInstruction v, InsnList instrumentation,
        String className, String methodName) {

    if (!v.isSwitch())
        throw new IllegalArgumentException("switch instruction expected");

    List<Branch> caseBranches = BranchPool.getInstance(classLoader).getCaseBranchesForSwitch(v);

    if (caseBranches == null || caseBranches.isEmpty())
        throw new IllegalStateException(
                "expect BranchPool to know at least one Branch for each switch instruction");

    for (Branch targetCaseBranch : caseBranches) {
        if (targetCaseBranch.isDefaultCase())
            continue; // handled elsewhere

        Integer targetCaseValue = targetCaseBranch.getTargetCaseValue();
        Integer targetCaseBranchId = targetCaseBranch.getActualBranchId();

        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(targetCaseValue));
        instrumentation.add(new LdcInsnNode(Opcodes.IF_ICMPEQ));
        instrumentation.add(new LdcInsnNode(targetCaseBranchId));
        instrumentation.add(new LdcInsnNode(v.getInstructionId()));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
    }
}

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

License:Open Source License

private String getOp(int opcode) {
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ICMPEQ:
        return "==";
    case Opcodes.IFNE:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPNE:
        return "!=";
    case Opcodes.IFLT:
    case Opcodes.IF_ICMPLT:
        return "<";
    case Opcodes.IFLE:
    case Opcodes.IF_ICMPLE:
        return "<=";
    case Opcodes.IFGT:
    case Opcodes.IF_ICMPGT:
        return ">";
    case Opcodes.IFGE:
    case Opcodes.IF_ICMPGE:
        return ">=";
    case Opcodes.IFNULL:
        return "= null";
    case Opcodes.IFNONNULL:
        return "!= null";
    }/*w w w  . j av a2s. c  o  m*/
    throw new RuntimeException("Unknown opcode: " + opcode);
}

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

License:Open Source License

/**
 * <p>getInfectionDistance</p>
 *
 * @param opcodeOrig a int./*  ww  w.  ja  v a  2  s .  c om*/
 * @param opcodeNew a int.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) {
    InsnList distance = new InsnList();
    switch (opcodeOrig) {
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
        distance.add(new InsnNode(Opcodes.DUP2));
        distance.add(new LdcInsnNode(opcodeOrig));
        distance.add(new LdcInsnNode(opcodeNew));
        distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance",
                "(IIII)D", false));
        break;

    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
        distance.add(new InsnNode(Opcodes.DUP));
        distance.add(new LdcInsnNode(opcodeOrig));
        distance.add(new LdcInsnNode(opcodeNew));
        distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(III)D",
                false));
        break;

    default:
        distance.add(new LdcInsnNode(0.0));
    }

    return distance;
}