Search in sources :

Example 1 with TableSwitchInsnNode

use of org.objectweb.asm.tree.TableSwitchInsnNode in project evosuite by EvoSuite.

the class BranchPool method registerSwitchInstruction.

private void registerSwitchInstruction(BytecodeInstruction v) {
    if (!v.isSwitch())
        throw new IllegalArgumentException("expect a switch instruction");
    LabelNode defaultLabel = null;
    switch(v.getASMNode().getOpcode()) {
        case Opcodes.TABLESWITCH:
            TableSwitchInsnNode tableSwitchNode = (TableSwitchInsnNode) v.getASMNode();
            registerTableSwitchCases(v, tableSwitchNode);
            defaultLabel = tableSwitchNode.dflt;
            break;
        case Opcodes.LOOKUPSWITCH:
            LookupSwitchInsnNode lookupSwitchNode = (LookupSwitchInsnNode) v.getASMNode();
            registerLookupSwitchCases(v, lookupSwitchNode);
            defaultLabel = lookupSwitchNode.dflt;
            break;
        default:
            throw new IllegalStateException("expect ASMNode of a switch to either be a LOOKUP- or TABLESWITCH");
    }
    registerDefaultCase(v, defaultLabel);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 2 with TableSwitchInsnNode

use of org.objectweb.asm.tree.TableSwitchInsnNode in project evosuite by EvoSuite.

the class BranchInstrumentation method addInstrumentationForDefaultTableswitchCase.

/**
 * <p>
 * addInstrumentationForDefaultTableswitchCase
 * </p>
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 */
protected void addInstrumentationForDefaultTableswitchCase(BytecodeInstruction v, InsnList instrumentation) {
    if (!v.isTableSwitch())
        throw new IllegalArgumentException("tableswitch instruction expected");
    // setup instructions
    TableSwitchInsnNode toInstrument = (TableSwitchInsnNode) v.getASMNode();
    LabelNode caseLabel = new LabelNode();
    LabelNode defaultLabel = new LabelNode();
    LabelNode endLabel = new LabelNode();
    int keySize = (toInstrument.max - toInstrument.min) + 1;
    LabelNode[] caseLabels = new LabelNode[keySize];
    for (int i = 0; i < keySize; i++) caseLabels[i] = caseLabel;
    TableSwitchInsnNode mySwitch = new TableSwitchInsnNode(toInstrument.min, toInstrument.max, defaultLabel, caseLabels);
    // add instrumentation
    addDefaultCaseInstrumentation(v, instrumentation, mySwitch, defaultLabel, caseLabel, endLabel);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode)

Example 3 with TableSwitchInsnNode

use of org.objectweb.asm.tree.TableSwitchInsnNode in project openj9 by eclipse.

the class ClassFileCompare method compareInstructions.

private void compareInstructions(ClassNode clazz1, MethodNode method1, ClassNode clazz2, MethodNode method2) {
    if (nullCheck(method1.instructions, method2.instructions, "Instructions (" + method1.name + ")")) {
        return;
    }
    if (method1.instructions.size() != method2.instructions.size()) {
        reportDifference("Method " + method1.name + ": instructions differ: " + method1.instructions.size() + ", " + method2.instructions.size());
    } else {
        @SuppressWarnings("unchecked") Iterator<AbstractInsnNode> iter1 = method1.instructions.iterator();
        @SuppressWarnings("unchecked") Iterator<AbstractInsnNode> iter2 = method2.instructions.iterator();
        int index = 0;
        while (iter1.hasNext()) {
            AbstractInsnNode instruction1 = iter1.next();
            AbstractInsnNode instruction2 = iter2.next();
            if (instruction1.getOpcode() != instruction2.getOpcode()) {
                /* Check for J9 opcode mapping */
                compareJ9OpcodeMapping(clazz2, method2, instruction1, instruction2, index);
            } else {
                switch(instruction1.getType()) {
                    case INSN:
                        /* Do nothing */
                        break;
                    case INT_INSN:
                        compare(((IntInsnNode) instruction1).operand, ((IntInsnNode) instruction2).operand, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
                        break;
                    case VAR_INSN:
                        compare(((VarInsnNode) instruction1).var, ((VarInsnNode) instruction2).var, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
                        break;
                    case TYPE_INSN:
                        compare(((TypeInsnNode) instruction1).desc, ((TypeInsnNode) instruction2).desc, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                        break;
                    case FIELD_INSN:
                        {
                            FieldInsnNode fieldInsn1 = (FieldInsnNode) instruction1;
                            FieldInsnNode fieldInsn2 = (FieldInsnNode) instruction2;
                            compare(fieldInsn1.owner, fieldInsn2.owner, "Owning class name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            compare(fieldInsn1.name, fieldInsn2.name, "Field name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            compare(fieldInsn1.desc, fieldInsn2.desc, "Descriptor of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            break;
                        }
                    case METHOD_INSN:
                        {
                            MethodInsnNode methodInsn1 = (MethodInsnNode) instruction1;
                            MethodInsnNode methodInsn2 = (MethodInsnNode) instruction2;
                            compare(methodInsn1.owner, methodInsn2.owner, "Owning class name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            compare(methodInsn1.name, methodInsn2.name, "Method name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            compare(methodInsn1.desc, methodInsn2.desc, "Descriptor of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            break;
                        }
                    case INVOKE_DYNAMIC_INSN:
                        compareInvokeDynamic((InvokeDynamicInsnNode) instruction1, (InvokeDynamicInsnNode) instruction2, method1, index);
                        break;
                    case JUMP_INSN:
                        compare(method1, ((JumpInsnNode) instruction1).label, method2, ((JumpInsnNode) instruction2).label, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                        break;
                    case LABEL:
                        /* Do nothing */
                        break;
                    case LDC_INSN:
                        if (!((LdcInsnNode) instruction1).cst.equals(((LdcInsnNode) instruction2).cst)) {
                            reportDifference("Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") differ: " + ((LdcInsnNode) instruction1).cst + ", " + ((LdcInsnNode) instruction2).cst);
                        }
                        break;
                    case IINC_INSN:
                        {
                            IincInsnNode iincInsn1 = (IincInsnNode) instruction1;
                            IincInsnNode iincInsn2 = (IincInsnNode) instruction2;
                            compare(iincInsn1.var, iincInsn2.var, "Variable operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
                            compare(iincInsn1.incr, iincInsn2.incr, "Increment operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
                            break;
                        }
                    case TABLESWITCH_INSN:
                        {
                            TableSwitchInsnNode tableSwitchInsn1 = (TableSwitchInsnNode) instruction1;
                            TableSwitchInsnNode tableSwitchInsn2 = (TableSwitchInsnNode) instruction2;
                            compare(tableSwitchInsn1.min, tableSwitchInsn2.min, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") minimum key value", false);
                            compare(tableSwitchInsn1.max, tableSwitchInsn2.max, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") maximum key value", false);
                            compare(method1, tableSwitchInsn1.dflt, method2, tableSwitchInsn2.dflt, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") default_handler_block");
                            compareLabels(method1, tableSwitchInsn1.labels, method2, tableSwitchInsn2.labels, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") handler_blocks");
                            break;
                        }
                    case LOOKUPSWITCH_INSN:
                        {
                            LookupSwitchInsnNode lookupSwitchInsn1 = (LookupSwitchInsnNode) instruction1;
                            LookupSwitchInsnNode lookupSwitchInsn2 = (LookupSwitchInsnNode) instruction2;
                            compare(method1, lookupSwitchInsn1.dflt, method2, lookupSwitchInsn2.dflt, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") default_handler_block");
                            compare(lookupSwitchInsn1.keys, lookupSwitchInsn2.keys, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") key values");
                            compareLabels(method1, lookupSwitchInsn1.labels, method2, lookupSwitchInsn2.labels, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") handler_blocks");
                            break;
                        }
                    case MULTIANEWARRAY_INSN:
                        {
                            MultiANewArrayInsnNode arrayInsn1 = (MultiANewArrayInsnNode) instruction1;
                            MultiANewArrayInsnNode arrayInsn2 = (MultiANewArrayInsnNode) instruction2;
                            compare(arrayInsn1.desc, arrayInsn2.desc, "Desc operand of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
                            compare(arrayInsn1.dims, arrayInsn2.dims, "Dimension operand of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
                            break;
                        }
                    case FRAME:
                        {
                            FrameNode frameInsn1 = (FrameNode) instruction1;
                            FrameNode frameInsn2 = (FrameNode) instruction2;
                            compare(frameInsn1.type, frameInsn2.type, "Stack map frame (" + method1.name + ":" + index + ") frame type", false);
                            compareFrames(frameInsn1.local, frameInsn2.local, "Stack map frame (" + method1.name + ":" + index + ") types of the local variables");
                            compareFrames(frameInsn1.stack, frameInsn2.stack, "Stack map frame (" + method1.name + ":" + index + ") types of the operand stack elements");
                        }
                        break;
                    case LINE:
                        {
                            assert shouldCompareDebugInfo;
                            LineNumberNode lineInsn1 = (LineNumberNode) instruction1;
                            LineNumberNode lineInsn2 = (LineNumberNode) instruction2;
                            compare(lineInsn1.line, lineInsn2.line, "Line number (" + method1.name + ":" + index + ") line No.", false);
                            compare(method1, lineInsn1.start, method2, lineInsn2.start, "Line number (" + method1.name + ":" + index + ") offset of the 1st instruction");
                            break;
                        }
                    default:
                        assert false;
                }
            }
            index++;
        }
    }
}
Also used : TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) FrameNode(org.objectweb.asm.tree.FrameNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) LineNumberNode(org.objectweb.asm.tree.LineNumberNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 4 with TableSwitchInsnNode

use of org.objectweb.asm.tree.TableSwitchInsnNode in project soot by Sable.

the class AsmMethodSource method convert.

private void convert() {
    ArrayDeque<Edge> worklist = new ArrayDeque<Edge>();
    for (LabelNode ln : trapHandlers.keySet()) {
        if (checkInlineExceptionHandler(ln))
            handleInlineExceptionHandler(ln, worklist);
        else
            worklist.add(new Edge(ln, new ArrayList<Operand>()));
    }
    worklist.add(new Edge(instructions.getFirst(), new ArrayList<Operand>()));
    conversionWorklist = worklist;
    edges = HashBasedTable.create(1, 1);
    do {
        Edge edge = worklist.pollLast();
        AbstractInsnNode insn = edge.insn;
        stack = edge.stack;
        edge.stack = null;
        do {
            int type = insn.getType();
            if (type == FIELD_INSN) {
                convertFieldInsn((FieldInsnNode) insn);
            } else if (type == IINC_INSN) {
                convertIincInsn((IincInsnNode) insn);
            } else if (type == INSN) {
                convertInsn((InsnNode) insn);
                int op = insn.getOpcode();
                if ((op >= IRETURN && op <= RETURN) || op == ATHROW) {
                    break;
                }
            } else if (type == INT_INSN) {
                convertIntInsn((IntInsnNode) insn);
            } else if (type == LDC_INSN) {
                convertLdcInsn((LdcInsnNode) insn);
            } else if (type == JUMP_INSN) {
                JumpInsnNode jmp = (JumpInsnNode) insn;
                convertJumpInsn(jmp);
                int op = jmp.getOpcode();
                if (op == JSR)
                    throw new UnsupportedOperationException("JSR!");
                if (op != GOTO) {
                    /* ifX opcode, i.e. two successors */
                    AbstractInsnNode next = insn.getNext();
                    addEdges(insn, next, Collections.singletonList(jmp.label));
                } else {
                    addEdges(insn, jmp.label, null);
                }
                break;
            } else if (type == LOOKUPSWITCH_INSN) {
                LookupSwitchInsnNode swtch = (LookupSwitchInsnNode) insn;
                convertLookupSwitchInsn(swtch);
                LabelNode dflt = swtch.dflt;
                addEdges(insn, dflt, swtch.labels);
                break;
            } else if (type == METHOD_INSN) {
                convertMethodInsn((MethodInsnNode) insn);
            } else if (type == INVOKE_DYNAMIC_INSN) {
                convertInvokeDynamicInsn((InvokeDynamicInsnNode) insn);
            } else if (type == MULTIANEWARRAY_INSN) {
                convertMultiANewArrayInsn((MultiANewArrayInsnNode) insn);
            } else if (type == TABLESWITCH_INSN) {
                TableSwitchInsnNode swtch = (TableSwitchInsnNode) insn;
                convertTableSwitchInsn(swtch);
                LabelNode dflt = swtch.dflt;
                addEdges(insn, dflt, swtch.labels);
            } else if (type == TYPE_INSN) {
                convertTypeInsn((TypeInsnNode) insn);
            } else if (type == VAR_INSN) {
                if (insn.getOpcode() == RET)
                    throw new UnsupportedOperationException("RET!");
                convertVarInsn((VarInsnNode) insn);
            } else if (type == LABEL) {
                convertLabel((LabelNode) insn);
            } else if (type == LINE) {
                convertLine((LineNumberNode) insn);
            } else if (type == FRAME) {
            // we can ignore it
            } else
                throw new RuntimeException("Unknown instruction type: " + type);
        } while ((insn = insn.getNext()) != null);
    } while (!worklist.isEmpty());
    conversionWorklist = null;
    edges = null;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) ArrayList(java.util.ArrayList) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) ArrayDeque(java.util.ArrayDeque) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode)

Example 5 with TableSwitchInsnNode

use of org.objectweb.asm.tree.TableSwitchInsnNode in project spring-loaded by spring-projects.

the class TypeDiffComputer method sameTableSwitchInsn.

@SuppressWarnings("unchecked")
private static boolean sameTableSwitchInsn(AbstractInsnNode o, AbstractInsnNode n) {
    if (!(n instanceof TableSwitchInsnNode)) {
        return false;
    }
    TableSwitchInsnNode tsio = (TableSwitchInsnNode) o;
    TableSwitchInsnNode tsin = (TableSwitchInsnNode) n;
    if (sameLabels(tsio.dflt, tsin.dflt)) {
        return false;
    }
    if (tsio.min != tsin.min) {
        return false;
    }
    if (tsio.max != tsin.max) {
        return false;
    }
    List<LabelNode> labelso = tsio.labels;
    List<LabelNode> labelsn = tsin.labels;
    if (labelso.size() != labelsn.size()) {
        return false;
    }
    for (int i = 0, max = labelso.size(); i < max; i++) {
        if (!sameLabelNode(labelso.get(i), labelsn.get(i))) {
            return false;
        }
    }
    return true;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode)

Aggregations

TableSwitchInsnNode (org.objectweb.asm.tree.TableSwitchInsnNode)7 LabelNode (org.objectweb.asm.tree.LabelNode)6 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)3 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)3 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)3 ArrayList (java.util.ArrayList)2 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)2 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)2 MultiANewArrayInsnNode (org.objectweb.asm.tree.MultiANewArrayInsnNode)2 JsonObject (com.google.gson.JsonObject)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ResourceList (org.evosuite.classpath.ResourceList)1 LCSAJ (org.evosuite.coverage.lcsaj.LCSAJ)1 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)1 FrameNode (org.objectweb.asm.tree.FrameNode)1 InsnList (org.objectweb.asm.tree.InsnList)1