Example usage for org.objectweb.asm.tree JumpInsnNode getOpcode

List of usage examples for org.objectweb.asm.tree JumpInsnNode getOpcode

Introduction

In this page you can find the example usage for org.objectweb.asm.tree JumpInsnNode getOpcode.

Prototype

public int getOpcode() 

Source Link

Document

Returns the opcode of this instruction.

Usage

From source file:com.retroduction.carma.transformer.asm.ror.ROR_Transition.java

License:Open Source License

@Override
protected void checkNode(ClassNode classNode, MethodNode methodNode, List<Mutant> result, CRTEntry jcovInfo,
        AbstractInsnNode node) {/*from   w w w  .jav  a 2 s.  c o m*/

    if (node instanceof JumpInsnNode) {

        JumpInsnNode jumpNode = (JumpInsnNode) node;

        if (jumpNode.getOpcode() == this.sourceInstruction) {

            jumpNode.setOpcode(this.targetInstruction);

            ClassWriter writer = new ClassWriter(0);
            classNode.accept(writer);

            SourceCodeMapping sourceMapping = new SourceCodeMapping();
            sourceMapping.setLineStart(jcovInfo.getStartLine());
            sourceMapping.setLineEnd(jcovInfo.getEndLine());
            sourceMapping.setColumnStart(jcovInfo.getStartColumn());
            sourceMapping.setColumnEnd(jcovInfo.getEndColumn());

            Mutant mutant = new Mutant();
            mutant.setByteCode(writer.toByteArray());
            mutant.setSourceMapping(sourceMapping);
            mutant.setSurvived(true);
            mutant.setTransition(this);

            result.add(mutant);
            jumpNode.setOpcode(this.sourceInstruction);

        }

    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.LoopMatcher.java

License:Open Source License

private static JumpInsnNode reverse(final JumpInsnNode ifNode) {
    switch (ifNode.getOpcode()) {
    case IF_ICMPEQ:
        return new JumpInsnNode(IF_ICMPNE, ifNode.label);
    case IF_ICMPGE:
        return new JumpInsnNode(IF_ICMPLT, ifNode.label);
    case IF_ICMPGT:
        return new JumpInsnNode(IF_ICMPLE, ifNode.label);
    case IF_ICMPLE:
        return new JumpInsnNode(IF_ICMPGT, ifNode.label);
    case IF_ICMPLT:
        return new JumpInsnNode(IF_ICMPGE, ifNode.label);
    case IF_ICMPNE:
        return new JumpInsnNode(IF_ICMPEQ, ifNode.label);
    case IFEQ:/*from  w  ww. j a  v  a2s.  c  o  m*/
        return new JumpInsnNode(IFNE, ifNode.label);
    case IFNE:
        return new JumpInsnNode(IFEQ, ifNode.label);
    case IFLT:
        return new JumpInsnNode(IFGE, ifNode.label);
    case IFGE:
        return new JumpInsnNode(IFLT, ifNode.label);
    case IFGT:
        return new JumpInsnNode(IFLE, ifNode.label);
    case IFLE:
        return new JumpInsnNode(IFGT, ifNode.label);
    default:
        return null;
    }
}

From source file:de.unisb.cs.st.javaslicer.tracer.instrumentation.TracingMethodInstrumenter.java

License:Open Source License

private void transformJumpInsn(final JumpInsnNode insn) {
    final JumpInstruction jumpInstr = new JumpInstruction(this.readMethod, insn.getOpcode(), this.currentLine,
            null);/*from   w  w  w.  j  a  va2 s .co  m*/
    this.jumpInstructions.put(jumpInstr, insn.label);
    registerInstruction(jumpInstr, InstructionType.UNSAFE);
    if (insn.getOpcode() == JSR) {
        // JSR is like a method call, so we have to add a label after this instruction
        addLabelIfNecessary(insn);
    }
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void interpret(JumpInsnNode insn, FrameState frame, BBInfo block) {
    //All JumpInsnNodes have a target.  Find it.
    BBInfo target = blockByInsn(insn.label);
    assert target != null;

    if (insn.getOpcode() == Opcodes.GOTO) {
        block.block.instructions().add(new JumpInst(target.block));
        return;//from  w w w .j av  a2  s.  c  o  m
    } else if (insn.getOpcode() == Opcodes.JSR)
        throw new UnsupportedOperationException("jsr not supported; upgrade to Java 6-era class files");

    //Remaining opcodes are branches.
    BBInfo fallthrough = blocks.get(blocks.indexOf(block) + 1);
    BranchInst.Sense sense = OPCODE_TO_SENSE.get(insn.getOpcode());
    //The second operand may come from the stack or may be a constant 0 or null.
    Value right;
    switch (insn.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        right = module.constants().getConstant(0);
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        right = module.constants().getNullConstant();
        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:
        right = frame.stack.pop();
        break;
    default:
        throw new AssertionError("Can't happen! Branch opcode missing? " + insn.getOpcode());
    }
    //First operand always comes from the stack.
    Value left = frame.stack.pop();
    block.block.instructions().add(new BranchInst(left, sense, right, target.block, fallthrough.block));
}

From source file:jaspex.speculation.newspec.RemoveOverspeculation.java

License:Open Source License

/** Scan simples para tentar eliminar overspeculation.
  *//from   w  w  w  . j  a  v  a2  s. c o m
  * A ideia deste mtodo  determinar se entre uma operao de spawnSpeculation e o get do seu Future /
  * nonTransactionalActionAttempted existem instruces suficientes para valer o trabalho de fazer
  * especulao.
  *
  * Quando observamos um spawnSpeculation, comeamos a fazer tracking dele. Se virmos alguma
  * operao complexa (alguns saltos, outros mtodos, etc), paramos o tracking. Caso contrrio, se
  * ainda estivermos a fazer tracking quando encontramos o get / nonTransactionalActionAttempted, ento
  * colocamos o mtodo na lista de especulaes a rejeitar.
  **/
private TrackingResult scanFuture(MethodInsnNode tracking, AbstractInsnNode start) {
    for (AbstractInsnNode node = start; node != null; node = node.getNext()) {
        if (node instanceof MethodInsnNode) {
            MethodInsnNode mInsn = (MethodInsnNode) node;

            if (mInsn.owner.equals(CommonTypes.CONTSPECULATIONCONTROL.asmName())
                    && mInsn.name.equals("spawnSpeculation")) {
                // do nothing
            } else if (mInsn.owner.startsWith(CommonTypes.FUTURE.asmName()) && mInsn.name.equals("get")) {
                int futureId = Integer.parseInt(mInsn.owner.substring(mInsn.owner.lastIndexOf('$') + 1));

                if (getFutureId(tracking) == futureId) {
                    return TrackingResult.NEEDVALUE;
                }
            } else if (mInsn.owner.equals(CommonTypes.SPECULATIONCONTROL.asmName())
                    && (mInsn.name.equals("nonTransactionalActionAttempted")
                            || mInsn.name.equals("blacklistedActionAttempted"))) {
                return TrackingResult.FORCEDSYNC;
            } else if (mInsn.owner.equals(CommonTypes.TRANSACTION.asmName())
                    || mInsn.owner.equals(CommonTypes.MARKER_BEFOREINLINEDSTORE)
                    || mInsn.owner.equals(CommonTypes.DEBUGCLASS.asmName())) {
                continue;
            } else if (mInsn.owner.equals(CommonTypes.REPLACEMENTS.asmName())) {
                // do nothing
            } else if (mInsn.owner.startsWith("jaspex")
                    && !CodegenHelper.isCodegenClass(Type.fromAsm(mInsn.owner))) {
                throw new AssertionError("Resetting tracking due to call to " + mInsn.owner + "." + mInsn.name);
            }

            return TrackingResult.OK;
        } else if (node instanceof JumpInsnNode) {
            JumpInsnNode jInsn = (JumpInsnNode) node;

            if (_mNode.instructions.indexOf(jInsn) > _mNode.instructions.indexOf(jInsn.label)) {
                // Salto para trs, no continuar tracking
                return TrackingResult.OK;
            }

            if (jInsn.getOpcode() == Opcodes.GOTO)
                return scanFuture(tracking, jInsn.label);
            if (jInsn.getOpcode() == Opcodes.JSR)
                throw new AssertionError();

            // Opcode  um de
            // IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT,
            // IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, IFNULL, IFNONNULL
            // Portanto vamos ter que analisar ambos os branches

            return TrackingResult.combine(scanFuture(tracking, jInsn.getNext()),
                    scanFuture(tracking, jInsn.label));
        } else if (node instanceof LookupSwitchInsnNode || node instanceof TableSwitchInsnNode) {
            List<LabelNode> targets = new UtilArrayList<LabelNode>();

            // Infelizmente o ASM no tem uma classe comum entre os dois tipos de switch
            if (node instanceof LookupSwitchInsnNode) {
                LookupSwitchInsnNode sInsn = (LookupSwitchInsnNode) node;
                if (sInsn.dflt != null)
                    targets.add(sInsn.dflt);
                targets.addAll(sInsn.labels);
            } else {
                TableSwitchInsnNode sInsn = (TableSwitchInsnNode) node;
                if (sInsn.dflt != null)
                    targets.add(sInsn.dflt);
                targets.addAll(sInsn.labels);
            }

            // Vamos analisar todos os targets do switch e fazer merge do resultado
            TrackingResult mergedResult = null;
            for (LabelNode l : targets) {
                TrackingResult res = scanFuture(tracking, l);

                if (mergedResult == null) {
                    mergedResult = res;
                } else {
                    mergedResult = TrackingResult.combine(mergedResult, res);
                }
            }

            return mergedResult;
        } else if (node instanceof InsnNode) {
            InsnNode insn = (InsnNode) node;

            // Encontrmos fim do mtodo
            if (insn.getOpcode() == Opcodes.ATHROW || returnOpcodes.contains(insn.getOpcode())) {
                if (new InvokedMethod(_mNode).returnType().equals(Type.PRIM_VOID)) {
                    // Caso especial: Todos os mtodos que retornam void so
                    // escolhidos para especulao -- Uma consequncia directa
                    // disso  que ter um futuro activo aquando do retorno do
                    // mtodo no serve para nada, j que a nica coisa que vai
                    // acontecer  a especulao acabada de criar vai tentar fazer
                    // commit imediatamente
                    return TrackingResult.FORCEDSYNC;
                }

                return TrackingResult.OK;
            }
        }
    }

    // FIXME: Alguma vez aqui chegamos?
    //return TrackingResult.OK;
    throw new AssertionError("FIXME");
}

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

License:Open Source License

/**
 * Compiles a {@link MethodNode} to MCode.
 * /*w w w .j a v  a2s  .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:nova.core.wrapper.mc.forge.v17.asm.lib.InsnListPrinter.java

License:Open Source License

private void _visitInsn(AbstractInsnNode insn) {
    switch (insn.getType()) {
    case 0://from  ww w.j a v  a 2 s  .c  om
        visitInsn(insn.getOpcode());
        break;
    case 1:
        IntInsnNode iinsn = (IntInsnNode) insn;
        visitIntInsn(iinsn.getOpcode(), iinsn.operand);
        break;
    case 2:
        VarInsnNode vinsn = (VarInsnNode) insn;
        visitVarInsn(vinsn.getOpcode(), vinsn.var);
        break;
    case 3:
        TypeInsnNode tinsn = (TypeInsnNode) insn;
        visitTypeInsn(tinsn.getOpcode(), tinsn.desc);
        break;
    case 4:
        FieldInsnNode finsn = (FieldInsnNode) insn;
        visitFieldInsn(finsn.getOpcode(), finsn.owner, finsn.name, finsn.desc);
        break;
    case 5:
        MethodInsnNode minsn = (MethodInsnNode) insn;
        visitMethodInsn(minsn.getOpcode(), minsn.owner, minsn.name, minsn.desc);
        break;
    case 6:
        InvokeDynamicInsnNode idinsn = (InvokeDynamicInsnNode) insn;
        visitInvokeDynamicInsn(idinsn.name, idinsn.desc, idinsn.bsm, idinsn.bsmArgs);
        break;
    case 7:
        JumpInsnNode jinsn = (JumpInsnNode) insn;
        visitJumpInsn(jinsn.getOpcode(), jinsn.label.getLabel());
        break;
    case 8:
        LabelNode linsn = (LabelNode) insn;
        visitLabel(linsn.getLabel());
        break;
    case 9:
        LdcInsnNode ldcinsn = (LdcInsnNode) insn;
        visitLdcInsn(ldcinsn.cst);
        break;
    case 10:
        IincInsnNode iiinsn = (IincInsnNode) insn;
        visitIincInsn(iiinsn.var, iiinsn.incr);
        break;
    case 11:
        TableSwitchInsnNode tsinsn = (TableSwitchInsnNode) insn;
        Label[] tslables = new Label[tsinsn.labels.size()];
        for (int i = 0; i < tslables.length; i++) {
            tslables[i] = tsinsn.labels.get(i).getLabel();
        }
        visitTableSwitchInsn(tsinsn.min, tsinsn.max, tsinsn.dflt.getLabel(), tslables);
        break;
    case 12:
        LookupSwitchInsnNode lsinsn = (LookupSwitchInsnNode) insn;
        Label[] lslables = new Label[lsinsn.labels.size()];
        for (int i = 0; i < lslables.length; i++) {
            lslables[i] = lsinsn.labels.get(i).getLabel();
        }
        int[] lskeys = new int[lsinsn.keys.size()];
        for (int i = 0; i < lskeys.length; i++) {
            lskeys[i] = lsinsn.keys.get(i);
        }
        visitLookupSwitchInsn(lsinsn.dflt.getLabel(), lskeys, lslables);
        break;
    case 13:
        MultiANewArrayInsnNode ainsn = (MultiANewArrayInsnNode) insn;
        visitMultiANewArrayInsn(ainsn.desc, ainsn.dims);
        break;
    case 14:
        FrameNode fnode = (FrameNode) insn;
        switch (fnode.type) {
        case -1:
        case 0:
            visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), fnode.stack.size(),
                    fnode.stack.toArray());
            break;
        case 1:
            visitFrame(fnode.type, fnode.local.size(), fnode.local.toArray(), 0, null);
            break;
        case 2:
            visitFrame(fnode.type, fnode.local.size(), null, 0, null);
            break;
        case 3:
            visitFrame(fnode.type, 0, null, 0, null);
            break;
        case 4:
            visitFrame(fnode.type, 0, null, 1, fnode.stack.toArray());
        }
        break;
    case 15:
        LineNumberNode lnode = (LineNumberNode) insn;
        visitLineNumber(lnode.line, lnode.start.getLabel());
        break;
    }
}

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

License:Open Source License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
//using external lib
@Override/*w  w w .  ja v a2s  .  c om*/
public void analyze(ClassLoader classLoader, MethodNode mn, String className, String methodName, int access) {

    Queue<LCSAJ> lcsaj_queue = new LinkedList<LCSAJ>();
    HashSet<Integer> targets_reached = new HashSet<Integer>();

    AbstractInsnNode start = mn.instructions.getFirst();
    int startID = 0;

    // TODO: This should replace the hack below
    if (methodName.startsWith("<init>")) {
        Iterator<AbstractInsnNode> j = mn.instructions.iterator();
        boolean constructorInvoked = false;
        while (j.hasNext()) {
            AbstractInsnNode in = j.next();
            startID++;
            if (!constructorInvoked) {
                if (in.getOpcode() == Opcodes.INVOKESPECIAL) {
                    MethodInsnNode cn = (MethodInsnNode) in;
                    Collection<String> superClasses = DependencyAnalysis.getInheritanceTree()
                            .getSuperclasses(className);
                    superClasses.add(className);
                    String classNameWithDots = ResourceList.getClassNameFromResourcePath(cn.owner);
                    if (superClasses.contains(classNameWithDots)) {
                        constructorInvoked = true;
                        break;
                    }
                } else {
                    continue;
                }
            }
        }
    }

    /*
    if (methodName.startsWith("<init>")) {
       if (mn.instructions.size() >= 4) {
    start = mn.instructions.get(4);
    startID = 4;
       }
    }
    */

    LCSAJ a = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader)
            .getInstruction(className, methodName, startID, start));
    lcsaj_queue.add(a);

    targets_reached.add(0);

    ArrayList<TryCatchBlockNode> tc_blocks = (ArrayList<TryCatchBlockNode>) mn.tryCatchBlocks;

    for (TryCatchBlockNode t : tc_blocks) {
        LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader)
                .getInstruction(className, methodName, mn.instructions.indexOf(t.handler), t.handler));
        lcsaj_queue.add(b);
    }

    while (!lcsaj_queue.isEmpty()) {

        LCSAJ currentLCSAJ = lcsaj_queue.poll();
        int position = mn.instructions.indexOf(currentLCSAJ.getLastNodeAccessed());
        // go to next bytecode instruction
        position++;

        if (position >= mn.instructions.size()) {
            // New LCSAJ for current + return
            LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
            continue;
        }

        AbstractInsnNode next = mn.instructions.get(position);
        currentLCSAJ.lookupInstruction(position, BytecodeInstructionPool.getInstance(classLoader)
                .getInstruction(className, methodName, position, next));

        if (next instanceof JumpInsnNode) {

            JumpInsnNode jump = (JumpInsnNode) next;
            // New LCSAJ for current + jump to target
            LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
            LabelNode target = jump.label;
            int targetPosition = mn.instructions.indexOf(target);

            if (jump.getOpcode() != Opcodes.GOTO) {

                LCSAJ copy = new LCSAJ(currentLCSAJ);
                lcsaj_queue.add(copy);

            }

            if (!targets_reached.contains(targetPosition)) {
                LCSAJ c = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader)
                        .getInstruction(className, methodName, targetPosition, target));
                lcsaj_queue.add(c);

                targets_reached.add(targetPosition);
            }

        } else if (next instanceof TableSwitchInsnNode) {

            TableSwitchInsnNode tswitch = (TableSwitchInsnNode) next;
            List<LabelNode> allTargets = tswitch.labels;

            for (LabelNode target : allTargets) {

                int targetPosition = mn.instructions.indexOf(target);

                if (!targets_reached.contains(targetPosition)) {

                    LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader)
                            .getInstruction(className, methodName, targetPosition, target));
                    lcsaj_queue.add(b);

                    targets_reached.add(targetPosition);
                }
            }

        } else if (next instanceof InsnNode) {
            InsnNode insn = (InsnNode) next;
            // New LCSAJ for current + throw / return
            if (insn.getOpcode() == Opcodes.ATHROW || insn.getOpcode() == Opcodes.RETURN
                    || insn.getOpcode() == Opcodes.ARETURN || insn.getOpcode() == Opcodes.IRETURN
                    || insn.getOpcode() == Opcodes.DRETURN || insn.getOpcode() == Opcodes.LRETURN
                    || insn.getOpcode() == Opcodes.FRETURN) {

                LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
            } else
                lcsaj_queue.add(currentLCSAJ);
        } else
            lcsaj_queue.add(currentLCSAJ);
    }

    if (Properties.STRATEGY != Strategy.EVOSUITE)
        addInstrumentation(classLoader, mn, className, methodName);

    //      if (Properties.WRITE_CFG)
    //         for (LCSAJ l : LCSAJPool.getLCSAJs(className, methodName)) {
    //            LCSAJGraph graph = new LCSAJGraph(l, false);
    //            String graphDestination = "evosuite-graphs/LCSAJGraphs/" + className
    //                    + "/" + methodName;
    //            File dir = new File(graphDestination);
    //            if (dir.mkdirs())
    //               graph.generate(new File(graphDestination + "/LCSAJGraph no: "
    //                       + l.getID() + ".dot"));
    //            else if (dir.exists())
    //               graph.generate(new File(graphDestination + "/LCSAJGraph no: "
    //                       + l.getID() + ".dot"));
    //         }
}

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

License:Open Source License

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

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

    JumpInsnNode node = (JumpInsnNode) instruction.getASMNode();
    LabelNode target = node.label;

    // insert mutation into bytecode with conditional
    JumpInsnNode mutation = new JumpInsnNode(getOpposite(node.getOpcode()), target);
    // insert mutation into pool
    Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME, instruction, mutation,
            Mutation.getDefaultInfectionDistance());

    mutations.add(mutationObject);
    return mutations;
}

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

License:Open Source License

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

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

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

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

    return mutations;
}