Search in sources :

Example 31 with JumpInsnNode

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

the class ReplaceComparisonOperator method apply.

/* (non-Javadoc)
	 * @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
	 */
/**
 * {@inheritDoc}
 */
@Override
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;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) InsnList(org.objectweb.asm.tree.InsnList) LinkedList(java.util.LinkedList)

Example 32 with JumpInsnNode

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

the class MutationInstrumentation method addInstrumentation.

/**
 * <p>
 * addInstrumentation
 * </p>
 *
 * @param mn
 *            a {@link org.objectweb.asm.tree.MethodNode} object.
 * @param original
 *            a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param mutations
 *            a {@link java.util.List} object.
 */
protected void addInstrumentation(MethodNode mn, AbstractInsnNode original, List<Mutation> mutations) {
    InsnList instructions = new InsnList();
    // TODO: All mutations in the id are touched, not just one!
    for (Mutation mutation : mutations) {
        instructions.add(mutation.getInfectionDistance());
        instructions.add(new LdcInsnNode(mutation.getId()));
        MethodInsnNode touched = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(ExecutionTracer.class), "passedMutation", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.INT_TYPE }), false);
        instructions.add(touched);
    }
    LabelNode endLabel = new LabelNode();
    for (Mutation mutation : mutations) {
        LabelNode nextLabel = new LabelNode();
        LdcInsnNode mutationId = new LdcInsnNode(mutation.getId());
        instructions.add(mutationId);
        FieldInsnNode activeId = new FieldInsnNode(Opcodes.GETSTATIC, Type.getInternalName(MutationObserver.class), "activeMutation", "I");
        instructions.add(activeId);
        instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, nextLabel));
        instructions.add(mutation.getMutation());
        instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabel));
        instructions.add(nextLabel);
    }
    mn.instructions.insertBefore(original, instructions);
    mn.instructions.insert(original, endLabel);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) MutationObserver(org.evosuite.coverage.mutation.MutationObserver) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) InsnList(org.objectweb.asm.tree.InsnList) ExecutionTracer(org.evosuite.testcase.execution.ExecutionTracer)

Example 33 with JumpInsnNode

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

the class MethodNodeTransformer method transform.

/**
 * <p>transform</p>
 *
 * @param mn a {@link org.objectweb.asm.tree.MethodNode} object.
 */
public void transform(MethodNode mn) {
    setupLocals(mn);
    Set<AbstractInsnNode> originalNodes = new HashSet<AbstractInsnNode>();
    AbstractInsnNode node = mn.instructions.getFirst();
    while (node != mn.instructions.getLast()) {
        originalNodes.add(node);
        node = node.getNext();
    }
    // int currentIndex = 0;
    node = mn.instructions.getFirst();
    // while (currentIndex < mn.instructions.size()) {
    boolean finished = false;
    while (!finished) {
        // } else
        if (node instanceof MethodInsnNode) {
            node = transformMethodInsnNode(mn, (MethodInsnNode) node);
        } else if (node instanceof VarInsnNode) {
            node = transformVarInsnNode(mn, (VarInsnNode) node);
        } else if (node instanceof FieldInsnNode) {
            node = transformFieldInsnNode(mn, (FieldInsnNode) node);
        } else if (node instanceof InsnNode) {
            node = transformInsnNode(mn, (InsnNode) node);
        } else if (node instanceof TypeInsnNode) {
            node = transformTypeInsnNode(mn, (TypeInsnNode) node);
        } else if (node instanceof JumpInsnNode) {
            node = transformJumpInsnNode(mn, (JumpInsnNode) node);
        } else if (node instanceof LabelNode) {
            node = transformLabelNode(mn, (LabelNode) node);
        } else if (node instanceof IntInsnNode) {
            node = transformIntInsnNode(mn, (IntInsnNode) node);
        } else if (node instanceof MultiANewArrayInsnNode) {
            node = transformMultiANewArrayInsnNode(mn, (MultiANewArrayInsnNode) node);
        }
        if (node == mn.instructions.getLast()) {
            finished = true;
        } else {
            node = node.getNext();
        }
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) MultiANewArrayInsnNode(org.objectweb.asm.tree.MultiANewArrayInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) HashSet(java.util.HashSet)

Example 34 with JumpInsnNode

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

the class BooleanTestabilityTransformation method insertPush.

/**
 * Insert a call to the distance function for unary comparison
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPush(int opcode, JumpInsnNode position, InsnList list) {
    list.insertBefore(position, new InsnNode(Opcodes.DUP));
    // TODO: We have to put a placeholder here instead of the actual branch ID
    // TODO: And then later add another transformation where we replace this with
    // actual branch IDs
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    insertBranchIdPlaceholder(currentMethodNode, position);
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 35 with JumpInsnNode

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

the class BooleanTestabilityTransformation method insertPushEquals.

/**
 * Insert a call to the reference equality check helper function
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPushEquals(int opcode, JumpInsnNode position, InsnList list) {
    MethodInsnNode equalCheck = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "isEqual", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.getType(Object.class), Type.INT_TYPE }), false);
    list.insertBefore(position, new InsnNode(Opcodes.DUP2));
    list.insertBefore(position, new LdcInsnNode(opcode));
    list.insertBefore(position, equalCheck);
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    insertBranchIdPlaceholder(currentMethodNode, position);
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Aggregations

JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)49 LabelNode (org.objectweb.asm.tree.LabelNode)36 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)28 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)26 InsnNode (org.objectweb.asm.tree.InsnNode)25 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)24 InsnList (org.objectweb.asm.tree.InsnList)22 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)18 MethodNode (org.objectweb.asm.tree.MethodNode)18 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 Label (org.objectweb.asm.Label)11 Type (org.objectweb.asm.Type)9 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)6 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)4 LinkedList (java.util.LinkedList)3 Mutation (org.evosuite.coverage.mutation.Mutation)3 FieldNode (org.objectweb.asm.tree.FieldNode)3