use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class DeleteField method getInfectionDistance.
/**
* <p>
* getInfectionDistance
* </p>
*
* @param original
* a {@link org.objectweb.asm.tree.FieldInsnNode} object.
* @param mutant
* a {@link org.objectweb.asm.tree.InsnList} object.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public InsnList getInfectionDistance(FieldInsnNode original, InsnList mutant) {
InsnList distance = new InsnList();
if (original.getOpcode() == Opcodes.GETFIELD)
// make sure to re-load this for GETFIELD
distance.add(new InsnNode(Opcodes.DUP));
distance.add(new FieldInsnNode(original.getOpcode(), original.owner, original.name, original.desc));
Type type = Type.getType(original.desc);
if (type.getDescriptor().startsWith("L") || type.getDescriptor().startsWith("[")) {
ReplaceVariable.addReferenceDistanceCheck(distance, type, mutant);
} else {
ReplaceVariable.addPrimitiveDistanceCheck(distance, type, mutant);
}
return distance;
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method getName.
private String getName(MethodNode mn, AbstractInsnNode node) throws VariableNotFoundException {
if (node instanceof VarInsnNode) {
LocalVariableNode var = getLocal(mn, node, ((VarInsnNode) node).var);
return var.name;
} else if (node instanceof FieldInsnNode) {
return ((FieldInsnNode) node).name;
} else if (node instanceof IincInsnNode) {
IincInsnNode incNode = (IincInsnNode) node;
LocalVariableNode var = getLocal(mn, node, incNode.var);
return var.name;
} else {
throw new RuntimeException("Unknown variable node: " + node);
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.mutation.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) {
// TODO - need to keep InsnList in Mutation, not only Instruction?
// Mutation: Insert an INEG _after_ an iload
List<Mutation> mutations = new LinkedList<Mutation>();
List<InsnList> mutationCode = new LinkedList<InsnList>();
List<String> descriptions = new LinkedList<String>();
if (instruction.getASMNode() instanceof VarInsnNode) {
try {
InsnList mutation = new InsnList();
VarInsnNode node = (VarInsnNode) instruction.getASMNode();
// insert mutation into bytecode with conditional
mutation.add(new VarInsnNode(node.getOpcode(), node.var));
mutation.add(new InsnNode(getNegation(node.getOpcode())));
mutationCode.add(mutation);
if (!mn.localVariables.isEmpty())
descriptions.add("Negation of " + getName(mn, node));
else
descriptions.add("Negation");
if (node.getOpcode() == Opcodes.ILOAD) {
if (frame.getStack(frame.getStackSize() - 1) != BooleanValueInterpreter.BOOLEAN_VALUE) {
mutation = new InsnList();
mutation.add(new IincInsnNode(node.var, 1));
mutation.add(new VarInsnNode(node.getOpcode(), node.var));
if (!mn.localVariables.isEmpty())
descriptions.add("IINC 1 " + getName(mn, node));
else
descriptions.add("IINC 1");
mutationCode.add(mutation);
mutation = new InsnList();
mutation.add(new IincInsnNode(node.var, -1));
mutation.add(new VarInsnNode(node.getOpcode(), node.var));
if (!mn.localVariables.isEmpty())
descriptions.add("IINC -1 " + getName(mn, node));
else
descriptions.add("IINC -1");
mutationCode.add(mutation);
}
}
} catch (VariableNotFoundException e) {
logger.info("Could not find variable: " + e);
return new ArrayList<Mutation>();
}
} else {
InsnList mutation = new InsnList();
FieldInsnNode node = (FieldInsnNode) instruction.getASMNode();
Type type = Type.getType(node.desc);
mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
mutation.add(new InsnNode(getNegation(type)));
descriptions.add("Negation");
mutationCode.add(mutation);
if (type == Type.INT_TYPE) {
mutation = new InsnList();
mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
mutation.add(new InsnNode(Opcodes.ICONST_1));
mutation.add(new InsnNode(Opcodes.IADD));
descriptions.add("+1");
mutationCode.add(mutation);
mutation = new InsnList();
mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc));
mutation.add(new InsnNode(Opcodes.ICONST_M1));
mutation.add(new InsnNode(Opcodes.IADD));
descriptions.add("-1");
mutationCode.add(mutation);
}
}
int i = 0;
for (InsnList mutation : mutationCode) {
// insert mutation into pool
Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + descriptions.get(i++), instruction, mutation, Mutation.getDefaultInfectionDistance());
mutations.add(mutationObject);
}
return mutations;
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class GetStaticGraphGenerator method handleMethodNode.
/**
* Add all possible calls for a given method
*
* @param callGraph
* @param mn
*/
@SuppressWarnings("unchecked")
private static void handleMethodNode(GetStaticGraph staticUsageTree, ClassNode cn, MethodNode mn, int depth) {
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
// TODO: This really shouldn't be here but in its own class
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn instanceof MethodInsnNode) {
handleMethodInsnNode(staticUsageTree, cn, mn, (MethodInsnNode) insn, depth + 1);
} else if (insn instanceof FieldInsnNode) {
handleFieldInsnNode(staticUsageTree, cn, mn, (FieldInsnNode) insn, depth + 1);
}
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class Instrumenter method instrumentGETXXXFieldAccesses.
private void instrumentGETXXXFieldAccesses(final ClassNode cn, final String internalClassName, final MethodNode methodNode) {
final InsnList instructions = methodNode.instructions;
AbstractInsnNode ins = null;
FieldInsnNode fieldIns = null;
for (int i = 0; i < instructions.size(); i++) {
ins = instructions.get(i);
if (ins instanceof FieldInsnNode) {
fieldIns = (FieldInsnNode) ins;
/*
* Is field referencing outermost instance? if yes, ignore it
* http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
*/
if (fieldIns.name.endsWith("$0")) {
continue;
}
final int opcode = ins.getOpcode();
if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
final InsnList il = new InsnList();
if (opcode == Opcodes.GETFIELD) {
Type fieldType = Type.getType(fieldIns.desc);
if (fieldType.getSize() == 1) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
il.add(new InsnNode(Opcodes.SWAP));
} else if (fieldType.getSize() == 2) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
// v
// GETFIELD
// v, w
il.add(new InsnNode(Opcodes.DUP2_X1));
// w, v, w
il.add(new InsnNode(Opcodes.POP2));
// w, v
// -> Call
// w
}
} else
il.add(new InsnNode(Opcodes.ACONST_NULL));
il.add(new LdcInsnNode(this.captureId));
il.add(new LdcInsnNode(fieldIns.owner));
il.add(new LdcInsnNode(fieldIns.name));
il.add(new LdcInsnNode(fieldIns.desc));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.FieldRegistry.class), "notifyReadAccess", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));
i += il.size();
instructions.insert(fieldIns, il);
this.captureId++;
}
}
}
}
Aggregations