use of org.objectweb.asm.tree.LdcInsnNode 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.LdcInsnNode in project evosuite by EvoSuite.
the class ReplaceArithmeticOperator method getInfectionDistance.
/**
* <p>getInfectionDistance</p>
*
* @param opcodeOrig a int.
* @param opcodeNew a int.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) {
InsnList distance = new InsnList();
if (opcodesInt.contains(opcodeOrig)) {
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceInt", "(IIII)D", false));
} else if (opcodesLong.contains(opcodeOrig)) {
distance.add(new VarInsnNode(Opcodes.LSTORE, numVariable));
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new VarInsnNode(Opcodes.LLOAD, numVariable));
distance.add(new InsnNode(Opcodes.DUP2_X2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceLong", "(JJII)D", false));
numVariable += 2;
} else if (opcodesFloat.contains(opcodeOrig)) {
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceFloat", "(FFII)D", false));
} else if (opcodesDouble.contains(opcodeOrig)) {
distance.add(new VarInsnNode(Opcodes.DSTORE, numVariable));
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new VarInsnNode(Opcodes.DLOAD, numVariable));
distance.add(new InsnNode(Opcodes.DUP2_X2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceDouble", "(DDII)D", false));
numVariable += 2;
}
return distance;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class ReplaceBitwiseOperator method getInfectionDistance.
/**
* <p>getInfectionDistance</p>
*
* @param opcodeOrig a int.
* @param opcodeNew a int.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) {
InsnList distance = new InsnList();
if (opcodesInt.contains(opcodeOrig)) {
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceInt", "(IIII)D", false));
} else if (opcodesIntShift.contains(opcodeOrig)) {
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceInt", "(IIII)D", false));
} else if (opcodesLong.contains(opcodeOrig)) {
distance.add(new VarInsnNode(Opcodes.LSTORE, numVariable));
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new VarInsnNode(Opcodes.LLOAD, numVariable));
distance.add(new InsnNode(Opcodes.DUP2_X2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceLong", "(JJII)D", false));
numVariable += 2;
} else if (opcodesLongShift.contains(opcodeOrig)) {
distance.add(new VarInsnNode(Opcodes.ISTORE, numVariable));
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new VarInsnNode(Opcodes.ILOAD, numVariable));
distance.add(new InsnNode(Opcodes.DUP_X2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceLong", "(JIII)D", false));
numVariable += 1;
}
return distance;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class ReplaceConstant 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) {
List<Mutation> mutations = new LinkedList<Mutation>();
Object value = getValue(instruction.getASMNode());
for (Object replacement : getReplacement(value)) {
// insert mutation into bytecode with conditional
LdcInsnNode mutation = new LdcInsnNode(replacement);
// insert mutation into pool
String summary = NAME + " - " + value + " -> " + replacement;
if (replacement instanceof String) {
summary = summary.replace("*/", "*_/");
}
Mutation mutationObject = MutationPool.addMutation(className, methodName, summary, instruction, mutation, Mutation.getDefaultInfectionDistance());
mutations.add(mutationObject);
}
return mutations;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertBranchIdPlaceholder.
private void insertBranchIdPlaceholder(MethodNode mn, JumpInsnNode jumpNode) {
Label label = new Label();
LabelNode labelNode = new LabelNode(label);
// BooleanTestabilityPlaceholderTransformer.addBranchPlaceholder(label, jumpNode);
mn.instructions.insertBefore(jumpNode, labelNode);
// mn.instructions.insertBefore(jumpNode, new LdcInsnNode(0));
mn.instructions.insertBefore(jumpNode, new LdcInsnNode(getBranchID(mn, jumpNode)));
}
Aggregations