Example usage for org.objectweb.asm Opcodes IFGT

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

Introduction

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

Prototype

int IFGT

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

Click Source Link

Usage

From source file:org.evosuite.TestSuiteGeneratorHelper.java

License:Open Source License

static void getBytecodeStatistics() {
    if (Properties.TRACK_BOOLEAN_BRANCHES) {
        int gradientBranchCount = ExecutionTraceImpl.gradientBranches.size() * 2;
        ClientServices.track(RuntimeVariable.Gradient_Branches, gradientBranchCount);
    }//from   w  w  w  .ja v a2s  .c o m
    if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) {
        int coveredGradientBranchCount = ExecutionTraceImpl.gradientBranchesCoveredTrue.size()
                + ExecutionTraceImpl.gradientBranchesCoveredFalse.size();
        ClientServices.track(RuntimeVariable.Gradient_Branches_Covered, coveredGradientBranchCount);
    }
    if (Properties.BRANCH_COMPARISON_TYPES) {
        int cmp_intzero = 0, cmp_intint = 0, cmp_refref = 0, cmp_refnull = 0;
        int bc_lcmp = 0, bc_fcmpl = 0, bc_fcmpg = 0, bc_dcmpl = 0, bc_dcmpg = 0;
        for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT())
                .getAllBranches()) {
            int branchOpCode = b.getInstruction().getASMNode().getOpcode();
            int previousOpcode = -2;
            if (b.getInstruction().getASMNode().getPrevious() != null) {
                previousOpcode = b.getInstruction().getASMNode().getPrevious().getOpcode();
            }
            switch (previousOpcode) {
            case Opcodes.LCMP:
                bc_lcmp++;
                break;
            case Opcodes.FCMPL:
                bc_fcmpl++;
                break;
            case Opcodes.FCMPG:
                bc_fcmpg++;
                break;
            case Opcodes.DCMPL:
                bc_dcmpl++;
                break;
            case Opcodes.DCMPG:
                bc_dcmpg++;
                break;
            }
            switch (branchOpCode) {
            // copmpare int with zero
            case Opcodes.IFEQ:
            case Opcodes.IFNE:
            case Opcodes.IFLT:
            case Opcodes.IFGE:
            case Opcodes.IFGT:
            case Opcodes.IFLE:
                cmp_intzero++;
                break;
            // copmpare int with int
            case Opcodes.IF_ICMPEQ:
            case Opcodes.IF_ICMPNE:
            case Opcodes.IF_ICMPLT:
            case Opcodes.IF_ICMPGE:
            case Opcodes.IF_ICMPGT:
            case Opcodes.IF_ICMPLE:
                cmp_intint++;
                break;
            // copmpare reference with reference
            case Opcodes.IF_ACMPEQ:
            case Opcodes.IF_ACMPNE:
                cmp_refref++;
                break;
            // compare reference with null
            case Opcodes.IFNULL:
            case Opcodes.IFNONNULL:
                cmp_refnull++;
                break;

            }
        }
        ClientServices.track(RuntimeVariable.Cmp_IntZero, cmp_intzero);
        ClientServices.track(RuntimeVariable.Cmp_IntInt, cmp_intint);
        ClientServices.track(RuntimeVariable.Cmp_RefRef, cmp_refref);
        ClientServices.track(RuntimeVariable.Cmp_RefNull, cmp_refnull);

        ClientServices.track(RuntimeVariable.BC_lcmp, bc_lcmp);
        ClientServices.track(RuntimeVariable.BC_fcmpl, bc_fcmpl);
        ClientServices.track(RuntimeVariable.BC_fcmpg, bc_fcmpg);
        ClientServices.track(RuntimeVariable.BC_dcmpl, bc_dcmpl);
        ClientServices.track(RuntimeVariable.BC_dcmpg, bc_dcmpg);

        RuntimeVariable[] bytecodeVarsCovered = new RuntimeVariable[] { RuntimeVariable.Covered_lcmp,
                RuntimeVariable.Covered_fcmpl, RuntimeVariable.Covered_fcmpg, RuntimeVariable.Covered_dcmpl,
                RuntimeVariable.Covered_dcmpg, RuntimeVariable.Covered_IntInt, RuntimeVariable.Covered_IntInt,
                RuntimeVariable.Covered_IntZero, RuntimeVariable.Covered_RefRef,
                RuntimeVariable.Covered_RefNull };

        for (RuntimeVariable bcvar : bytecodeVarsCovered) {
            ClientServices.track(bcvar,
                    getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredFalse)
                            + getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredTrue));
        }

        RuntimeVariable[] bytecodeVarsReached = new RuntimeVariable[] { RuntimeVariable.Reached_lcmp,
                RuntimeVariable.Reached_fcmpl, RuntimeVariable.Reached_fcmpg, RuntimeVariable.Reached_dcmpl,
                RuntimeVariable.Reached_dcmpg, RuntimeVariable.Reached_IntInt, RuntimeVariable.Reached_IntInt,
                RuntimeVariable.Reached_IntZero, RuntimeVariable.Reached_RefRef,
                RuntimeVariable.Reached_RefNull };

        for (RuntimeVariable bcvar : bytecodeVarsReached) {
            ClientServices.track(bcvar,
                    getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionReached) * 2);
        }

    }

}

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

License:Open Source License

private void compileMerge() throws CompilerException {
    final Label exit;
    if (mustDetectEmptiness) {
        final Label notEmpty = mv().newLabel();
        mv().visitVarInsn(Opcodes.ILOAD, indexVar);
        mv().ifZCmp(Opcodes.IFGT, notEmpty);
        expressionCompiler().compile(fold.whenEmpty());
        exit = mv().newLabel();/*  w ww .  jav  a  2  s.  co m*/
        mv().goTo(exit);
        mv().mark(notEmpty);
    } else {
        exit = null;
    }

    if (fold.isMergedExplicitly()) {
        if (mustCount) {
            letIndexVarAs(fold.countName());
        } else if (fold.isCounted()) {
            letDict().let(fold.countName(), DataType.NUMERIC, new CompilableExpressionNode(
                    new ExpressionNodeForConstantValue(staticCount, DataType.NUMERIC)));
        }
        expressionCompiler().compile(fold.merge());
    } else {
        assert 1 == accuVars.length;
        compileAccumulatorLoad(0);
    }

    if (null != exit)
        mv().mark(exit);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

private void handleBooleanOperator(Expression node, Operator op, Type type) throws ASTVisitorException {
    List<JumpInsnNode> trueList = new ArrayList<JumpInsnNode>();
    System.out.println("***** handle boolean " + op);
    if (type.equals(TypeUtils.STRING_TYPE)) {
        mn.instructions.add(new InsnNode(Opcodes.SWAP));
        JumpInsnNode jmp = null;//from  w  w  w  .  jav a2  s.  c  o  m
        mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals",
                "(Ljava/lang/Object;)Z", false));
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            break;
        default:
            ASTUtils.error(node, "Operator not supported on strings");
            break;
        }
        mn.instructions.add(jmp);
        trueList.add(jmp);
    } else if (type.equals(Type.DOUBLE_TYPE)) {

        // FIXME: add DCMPG instruction
        // FIXME: add a JumpInsnNode with null label based on the operation
        //        IFEQ, IFNE, IFGT, IFGE, IFLT, IFLE
        // FIXME: add the jmp instruction into trueList
        mn.instructions.add(new InsnNode(Opcodes.DCMPG));
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            jmp = new JumpInsnNode(Opcodes.IFGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IFLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IFLE, null);
            mn.instructions.add(jmp);
            break;
        }
        trueList.add(jmp);

    } else {
        System.out.println("here");
        JumpInsnNode jmp = null;
        switch (op) {
        case EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPEQ, null);
            mn.instructions.add(jmp);
            break;
        case NOT_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPNE, null);
            mn.instructions.add(jmp);
            break;
        case GREATER:
            System.out.println("----- greater");
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGT, null);
            mn.instructions.add(jmp);
            break;
        case GREATER_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPGE, null);
            mn.instructions.add(jmp);
            break;
        case LESS:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLT, null);
            mn.instructions.add(jmp);
            break;
        case LESS_EQUAL:
            jmp = new JumpInsnNode(Opcodes.IF_ICMPLE, null);
            mn.instructions.add(jmp);
            break;
        default:
            ASTUtils.error(node, "Operator not supported");
            break;
        }
        trueList.add(jmp);
    }
    ASTUtils.setTrueList(node, trueList);
    List<JumpInsnNode> falseList = new ArrayList<JumpInsnNode>();
    JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null);
    mn.instructions.add(jmp);
    falseList.add(jmp);
    ASTUtils.setFalseList(node, falseList);
}

From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java

private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException {
    if (op.equals(Operator.PLUS)) {

        // FIXME: IADD or DADD, etc.
        //        use type.getOpcode(Opcodes.IADD) to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD)));

    } else if (op.equals(Operator.MINUS)) {

        // FIXME: ISUB or DSUB, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB)));

    } else if (op.equals(Operator.MULTIPLY)) {

        // FIXME: IMUL or DMUL, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL)));

    } else if (op.equals(Operator.DIVISION)) {

        // FIXME: IDIV or DDIV, etc.
        //        use type.getOpcode() to avoid if-then
        mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV)));

    } else if (op.isRelational()) {
        if (type.equals(Type.DOUBLE_TYPE)) {
            mn.instructions.add(new InsnNode(Opcodes.DCMPG));
            JumpInsnNode jmp = null;//from   w ww .j ava 2  s  .  com
            switch (op) {
            case EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFEQ, null);
                mn.instructions.add(jmp);
                break;
            case NOT_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFNE, null);
                mn.instructions.add(jmp);
                break;
            case GREATER:
                jmp = new JumpInsnNode(Opcodes.IFGT, null);
                mn.instructions.add(jmp);
                break;
            case GREATER_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFGE, null);
                mn.instructions.add(jmp);
                break;
            case LESS:
                jmp = new JumpInsnNode(Opcodes.IFLT, null);
                mn.instructions.add(jmp);
                break;
            case LESS_EQUAL:
                jmp = new JumpInsnNode(Opcodes.IFLE, null);
                mn.instructions.add(jmp);
                break;
            default:
                ASTUtils.error(node, "Operator not supported");
                break;
            }
            mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
            LabelNode endLabelNode = new LabelNode();
            mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
            LabelNode trueLabelNode = new LabelNode();
            jmp.label = trueLabelNode;
            mn.instructions.add(trueLabelNode);
            mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
            mn.instructions.add(endLabelNode);
        } else if (type.equals(Type.INT_TYPE)) {
            LabelNode trueLabelNode = new LabelNode();
            switch (op) {
            case EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode));
                break;
            case NOT_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode));
                break;
            case GREATER:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode));
                break;
            case GREATER_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode));
                break;
            case LESS:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode));
                break;
            case LESS_EQUAL:
                mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode));
                break;
            default:
                break;
            }
            mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
            LabelNode endLabelNode = new LabelNode();
            mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode));
            mn.instructions.add(trueLabelNode);
            mn.instructions.add(new InsnNode(Opcodes.ICONST_1));
            mn.instructions.add(endLabelNode);
        } else {
            ASTUtils.error(node, "Cannot compare such types.");
        }
    } else {
        ASTUtils.error(node, "Operator not recognized.");
    }
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    switch (opcode) {
    case Opcodes.GOTO:
        break;//from   w  ww . ja v  a 2 s .c  o m
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        pop(1);
        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:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        pop(2);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitJumpInsn(opcode, label);
}

From source file:org.jacoco.core.internal.instr.MethodInstrumenter.java

License:Open Source License

private int getInverted(final int opcode) {
    switch (opcode) {
    case Opcodes.IFEQ:
        return Opcodes.IFNE;
    case Opcodes.IFNE:
        return Opcodes.IFEQ;
    case Opcodes.IFLT:
        return Opcodes.IFGE;
    case Opcodes.IFGE:
        return Opcodes.IFLT;
    case Opcodes.IFGT:
        return Opcodes.IFLE;
    case Opcodes.IFLE:
        return Opcodes.IFGT;
    case Opcodes.IF_ICMPEQ:
        return Opcodes.IF_ICMPNE;
    case Opcodes.IF_ICMPNE:
        return Opcodes.IF_ICMPEQ;
    case Opcodes.IF_ICMPLT:
        return Opcodes.IF_ICMPGE;
    case Opcodes.IF_ICMPGE:
        return Opcodes.IF_ICMPLT;
    case Opcodes.IF_ICMPGT:
        return Opcodes.IF_ICMPLE;
    case Opcodes.IF_ICMPLE:
        return Opcodes.IF_ICMPGT;
    case Opcodes.IF_ACMPEQ:
        return Opcodes.IF_ACMPNE;
    case Opcodes.IF_ACMPNE:
        return Opcodes.IF_ACMPEQ;
    case Opcodes.IFNULL:
        return Opcodes.IFNONNULL;
    case Opcodes.IFNONNULL:
        return Opcodes.IFNULL;
    }/*from ww w .  j  a va2s .  c o m*/
    throw new IllegalArgumentException();
}

From source file:org.jacoco.core.internal.instr.MethodInstrumenterTest.java

License:Open Source License

@Test
public void testVisitJumpInsnWithProbe_IFGT() {
    testVisitJumpInsnWithProbe(Opcodes.IFGT, Opcodes.IFLE);
}

From source file:org.jacoco.core.internal.instr.MethodInstrumenterTest.java

License:Open Source License

@Test
public void testVisitJumpInsnWithProbe_IFLE() {
    testVisitJumpInsnWithProbe(Opcodes.IFLE, Opcodes.IFGT);
}

From source file:org.jboss.byteman.agent.adapter.cfg.BBlock.java

License:Open Source License

/**
 * write a string represenattion of this block to the buffer
 * @param buf the buffer to be written to
 * @return/*from  w w w  .j a va  2 s  .co m*/
 */
void printTo(StringBuffer buf) {
    int blockIdx = this.getBlockIdx();
    buf.append(this.getLabel().getOffset());
    buf.append(": BB ");
    buf.append(blockIdx);
    buf.append("\n");
    FanOut containsFanOut = cfg.getContains(this);
    Iterator<Label> containsIter;
    Label containedLabel;
    int containedPosition;
    if (containsFanOut != null) {
        containsIter = containsFanOut.iterator();
        if (containsIter.hasNext()) {
            containedLabel = containsIter.next();
            containedPosition = cfg.getBlockInstructionIdx(containedLabel);
        } else {
            containedLabel = null;
            containedPosition = -1;
        }
    } else {
        containsIter = null;
        containedLabel = null;
        containedPosition = -1;
    }

    int instructionCount = this.getInstructionCount();
    for (int i = 0; i < instructionCount; i++) {
        // we will never enter this if containedPosition is -1 which safeguards us when containsIter
        // is null or containedLabel is null
        while (containedPosition == i) {
            buf.append(containedLabel.getOffset());
            buf.append(": ");
            buf.append(containedLabel);
            buf.append(" +");
            buf.append(containedPosition);
            if (cfg.tryCatchStart(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchStartDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    Label handlerLabel = details.getHandler();
                    CodeLocation handlerLocation = cfg.getLocation(handlerLabel);
                    buf.append(" try ");
                    buf.append(details.getType());
                    buf.append(" ");
                    if (handlerLocation != null) {
                        buf.append(handlerLabel.getOffset());
                    } else {
                        buf.append("??");
                    }
                    buf.append(" ");
                    buf.append(handlerLabel);
                }
            }
            if (cfg.tryCatchEnd(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchEndDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    Label handlerLabel = details.getHandler();
                    CodeLocation handlerLocation = cfg.getLocation(handlerLabel);
                    buf.append(" catch ");
                    buf.append(details.getType());
                    buf.append(" ");
                    if (handlerLocation != null) {
                        buf.append(handlerLabel.getOffset());
                    } else {
                        buf.append("??");
                    }
                    buf.append(" ");
                    buf.append(handlerLabel);
                }
            }
            if (cfg.tryCatchHandlerStart(containedLabel)) {
                List<TryCatchDetails> detailsList = cfg.tryCatchHandlerStartDetails(containedLabel);
                int detailsCount = detailsList.size();
                for (int j = 0; j < detailsCount; j++) {
                    TryCatchDetails details = detailsList.get(j);
                    buf.append(" handle ");
                    buf.append(details.getType());
                    buf.append(" ");
                    buf.append(details.getStart().getOffset());
                    buf.append(" ");
                    buf.append(details.getEnd().getOffset());
                }
            }
            if (cfg.triggerStart(containedLabel)) {
                buf.append(" trigger start");
                TriggerDetails details = cfg.triggerStartDetails(containedLabel);
            }
            if (cfg.triggerEnd(containedLabel)) {
                buf.append(" trigger end");
            }
            buf.append("\n");
            List<CodeLocation> openEnters = cfg.getOpenMonitorEnters(containedLabel);
            if (openEnters != null) {
                int openCount = openEnters.size();
                if (openCount > 0) {
                    buf.append("open monitors: ");
                    for (int j = 0; j < openCount; j++) {
                        CodeLocation l = openEnters.get(j);
                        buf.append(" BB");
                        buf.append(l.getBlock().getBlockIdx());
                        buf.append(".");
                        buf.append(l.getInstructionIdx());
                    }
                    buf.append('\n');
                }
            }
            containedLabel = (containsIter.hasNext() ? containsIter.next() : null);
            containedPosition = (containedLabel != null ? cfg.getBlockInstructionIdx(containedLabel) : -1);
        }
        // buf.append("   ");
        buf.append(blockIdx);
        buf.append(".");
        buf.append(i);
        buf.append(": ");
        int opcode = this.getInstruction(i);
        switch (OpcodesHelper.insnType(opcode)) {
        case OpcodesHelper.INSN_NONE: {
            // print the instruction name
            buf.append(OpcodesHelper.insnName(opcode));
            if (opcode == Opcodes.MONITOREXIT) {
                CodeLocation exit = new CodeLocation(this, i);
                CodeLocation enter = cfg.getPairedEnter(exit);
                // print the corresponding open instruction
                buf.append(" (enter: ");
                buf.append(enter);
                buf.append(")");
            }
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_INT: {
            // just print the instruction name and one integer argument
            int intValue = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(intValue);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_LDC: {
            // print the instruction and one constant argument
            int nameIdx = this.getInstructionArg(i, 0);
            String name = cfg.getName(nameIdx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_VAR: {
            // print the instruction and the var idx
            int varIdx = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(varIdx);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_IINC: {
            // print the instruction and the var idx
            int increment = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(increment);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_JUMP: {
            // note that we may not have generated the code for the jump target yet
            Label targetLabel = this.firstOut();
            CodeLocation targetLocation = cfg.getLocation(targetLabel);
            int targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            switch (opcode) {
            case Opcodes.IFEQ:
                buf.append("IFEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNE:
                buf.append("IFNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFLT:
                buf.append("IFLT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFGE:
                buf.append("IFGE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFGT:
                buf.append("IFGT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFLE:
                buf.append("IFLE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPEQ:
                buf.append("IF_ICMPEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPNE:
                buf.append("IF_ICMPNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPLT:
                buf.append("IF_ICMPLT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPGE:
                buf.append("IF_ICMPGE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPGT:
                buf.append("IF_ICMPGT ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ICMPLE:
                buf.append("IF_ICMPLE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ACMPEQ:
                buf.append("IF_ACMPEQ ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IF_ACMPNE:
                buf.append("IF_ACMPNE ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.GOTO:
                buf.append("GOTO ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.JSR:
                buf.append("JSR ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNULL:
                buf.append("IFNULL ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            case Opcodes.IFNONNULL:
                buf.append("IFNONNULL ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
                buf.append("\n");
                break;
            }
        }
            break;
        case OpcodesHelper.INSN_TSWITCH: {
            Label targetLabel;
            CodeLocation targetLocation;
            int targetPos;
            // print the instruction followed by the jump table discriminant min and max and then
            // the jump labels
            int min = this.getInstructionArg(i, 0);
            int max = this.getInstructionArg(i, 1);
            int count = (max + 1 - min);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(min);
            buf.append(" ");
            buf.append(max);
            buf.append("\n");
            for (int j = 1; j <= count; j++) {
                // note that we may not have generated the code for the jump target yet
                targetLabel = this.nthOut(j);
                targetLocation = cfg.getLocation(targetLabel);
                targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
                buf.append("    ");
                buf.append(min + j);
                buf.append(" : ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
            }
            targetLabel = this.firstOut();
            targetLocation = cfg.getLocation(targetLabel);
            targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            buf.append("    dflt : ");
            if (targetPos >= 0) {
                buf.append(targetPos);
                buf.append(" BB ");
                buf.append(targetLocation.getBlock().getBlockIdx());
                buf.append(" ");
                buf.append(targetLabel);
            } else {
                buf.append("??  ");
                buf.append(targetLabel);
            }
        }
            break;
        case OpcodesHelper.INSN_LOOKUP: {
            Label targetLabel;
            CodeLocation targetLocation;
            int targetPos;
            // print the instruction followed by each jump table discriminant and label
            int count = this.getInstructionArg(i, 0);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append("\n");
            for (int j = 1; j <= count; j++) {
                // note that we may not have generated the code for the jump target yet
                targetLabel = this.nthOut(j);
                targetLocation = cfg.getLocation(targetLabel);
                targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
                buf.append("    ");
                buf.append(this.getInstructionArg(i, j));
                buf.append(" : ");
                if (targetPos >= 0) {
                    buf.append(targetPos);
                    buf.append(" BB ");
                    buf.append(targetLocation.getBlock().getBlockIdx());
                    buf.append(" ");
                    buf.append(targetLabel);
                } else {
                    buf.append("??  ");
                    buf.append(targetLabel);
                }
            }
            targetLabel = this.firstOut();
            targetLocation = cfg.getLocation(targetLabel);
            targetPos = (targetLocation != null ? targetLabel.getOffset() : -1);
            buf.append("    dflt : ");
            if (targetPos >= 0) {
                buf.append(targetPos);
                buf.append(" BB ");
                buf.append(targetLocation.getBlock().getBlockIdx());
                buf.append(" ");
                buf.append(targetLabel);
            } else {
                buf.append("??  ");
                buf.append(targetLabel);
            }
        }
            break;
        case OpcodesHelper.INSN_FIELD:
        case OpcodesHelper.INSN_METHOD: {
            // print the instruction with the owner, name and descriptor
            int idx1 = this.getInstructionArg(i, 0);
            int idx2 = this.getInstructionArg(i, 1);
            int idx3 = this.getInstructionArg(i, 2);
            String owner = cfg.getName(idx1);
            String name = cfg.getName(idx2);
            String desc = cfg.getName(idx3);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(owner);
            buf.append(" ");
            buf.append(name);
            buf.append(" ");
            buf.append(desc);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_TYPE: {
            // print the instruction with the type name
            int idx = this.getInstructionArg(i, 0);
            String name = cfg.getName(idx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_MULTIANEWARRAY: {
            // print the instruction with the typename and the dimension count
            int idx = this.getInstructionArg(i, 0);
            int dims = this.getInstructionArg(i, 1);
            String name = cfg.getName(idx);
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append(" ");
            buf.append(name);
            buf.append(" ");
            buf.append(dims);
            buf.append("\n");
        }
            break;
        case OpcodesHelper.INSN_UNUSED: {
            // print the instruction
            buf.append(OpcodesHelper.insnName(opcode));
            buf.append("!!!\n");
        }
            break;
        }
    }
    // print the active starts for this block
    if (activeTryStarts != null) {
        Iterator<TryCatchDetails> activeStartsIter = activeTryStarts.iterator();
        while (activeStartsIter.hasNext()) {
            TryCatchDetails details = activeStartsIter.next();
            Label label = details.getStart();
            BBlock block = cfg.getBlock(label);
            buf.append("try: ");
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" catch: ");
            label = details.getEnd();
            block = cfg.getBlock(label);
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" handle: ");
            label = details.getHandler();
            block = cfg.getBlock(label);
            if (block != null) {
                buf.append(label.getOffset());
                buf.append(" ");
                buf.append(block.getBlockIdx());
                buf.append(".");
                buf.append(cfg.getBlockInstructionIdx(label));
            } else {
                buf.append(label);
            }
            buf.append(" ");
            buf.append(details.getType());
            buf.append("\n");
        }
    }
}

From source file:org.jboss.byteman.agent.adapter.RuleTriggerMethodAdapter.java

License:Open Source License

@Override
public void visitJumpInsn(int opcode, Label label) {
    super.visitJumpInsn(opcode, label);
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE: {
        // create a new current block and add the label supplied in the call as the
        // first out of the old current block and the label of the new current block as
        // the second out
        cfg.add(opcode);//w  w  w  . ja  v  a  2 s .  com
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    case Opcodes.GOTO: {
        // create a new current block and  add the label supplied in the call as the
        // first out of the old current block
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label);
        visitLabel(newStart);
    }
        break;
    case Opcodes.JSR: {
        // create a new current block and add the label supplied in the call as the first out
        // of the current block -- the new current block is a potential return point from the
        // JSR but we cannot represent that statically
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL: {
        // create a new current block and add the label supplied in the call as the
        // first out of the old current block and the label of the new current block as
        // the second out
        cfg.add(opcode);
        Label newStart = super.newLabel();
        // must call split before visiting the label
        cfg.split(newStart, label, newStart);
        visitLabel(newStart);
    }
        break;
    }
}