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;
}
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);
}
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();
}
}
}
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);
}
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);
}
Aggregations