use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertGetBefore.
/**
* Insert a call that takes a boolean from the stack, and returns the
* appropriate distance
*
* @param position
* @param list
*/
public void insertGetBefore(AbstractInsnNode position, InsnList list) {
logger.info("Inserting get call before");
// Here, branchId is the first control dependency
// list.insertBefore(position,
// new LdcInsnNode(getControlDependentBranchID(currentMethodNode,
// position)));
// insertControlDependencyPlaceholder(currentMethodNode, position);
// branch
// approx
// value
Label label = new Label();
LabelNode labelNode = new LabelNode(label);
// BooleanTestabilityPlaceholderTransformer.addControlDependencyPlaceholder(label,
// insnNode);
currentMethodNode.instructions.insertBefore(position, labelNode);
// instructions.insertBefore(insnNode, new LdcInsnNode(0));
// mn.instructions.insertBefore(insnNode, new LdcInsnNode(0));
currentMethodNode.instructions.insertBefore(position, new LdcInsnNode(getControlDependentBranchID(currentMethodNode, position)));
currentMethodNode.instructions.insertBefore(position, new InsnNode(Opcodes.SWAP));
currentMethodNode.instructions.insertBefore(position, new LdcInsnNode(getApproximationLevel(currentMethodNode, position)));
currentMethodNode.instructions.insertBefore(position, new InsnNode(Opcodes.SWAP));
MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "getDistance", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE, Type.INT_TYPE }), false);
list.insertBefore(position, get);
}
use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertBranchIdPlaceholder.
private void insertBranchIdPlaceholder(MethodNode mn, JumpInsnNode jumpNode, int branchId) {
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(branchId));
}
use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.
the class BranchInstrumentation method addInstrumentationForDefaultTableswitchCase.
/**
* <p>
* addInstrumentationForDefaultTableswitchCase
* </p>
*
* @param v
* a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
* @param instrumentation
* a {@link org.objectweb.asm.tree.InsnList} object.
*/
protected void addInstrumentationForDefaultTableswitchCase(BytecodeInstruction v, InsnList instrumentation) {
if (!v.isTableSwitch())
throw new IllegalArgumentException("tableswitch instruction expected");
// setup instructions
TableSwitchInsnNode toInstrument = (TableSwitchInsnNode) v.getASMNode();
LabelNode caseLabel = new LabelNode();
LabelNode defaultLabel = new LabelNode();
LabelNode endLabel = new LabelNode();
int keySize = (toInstrument.max - toInstrument.min) + 1;
LabelNode[] caseLabels = new LabelNode[keySize];
for (int i = 0; i < keySize; i++) caseLabels[i] = caseLabel;
TableSwitchInsnNode mySwitch = new TableSwitchInsnNode(toInstrument.min, toInstrument.max, defaultLabel, caseLabels);
// add instrumentation
addDefaultCaseInstrumentation(v, instrumentation, mySwitch, defaultLabel, caseLabel, endLabel);
}
use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.
the class BranchInstrumentation method analyze.
/*
* (non-Javadoc)
*
* @see
* org.evosuite.cfg.MethodInstrumentation#analyze(org.objectweb
* .asm.tree.MethodNode, org.jgrapht.Graph, java.lang.String,
* java.lang.String, int)
*/
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public void analyze(ClassLoader classLoader, MethodNode mn, String className, String methodName, int access) {
this.classLoader = classLoader;
RawControlFlowGraph graph = GraphPool.getInstance(classLoader).getRawCFG(className, methodName);
Iterator<AbstractInsnNode> j = mn.instructions.iterator();
while (j.hasNext()) {
AbstractInsnNode in = j.next();
for (BytecodeInstruction v : graph.vertexSet()) {
// If this is in the CFG and it's a branch...
if (in.equals(v.getASMNode())) {
if (v.isBranch()) {
if (in.getPrevious() instanceof LabelNode) {
LabelNode label = (LabelNode) in.getPrevious();
if (label.getLabel() instanceof AnnotatedLabel) {
AnnotatedLabel aLabel = (AnnotatedLabel) label.getLabel();
if (aLabel.isStartTag()) {
if (!aLabel.shouldIgnore()) {
logger.debug("Found artificial branch: " + v);
Branch b = BranchPool.getInstance(classLoader).getBranchForInstruction(v);
b.setInstrumented(true);
} else {
continue;
}
}
}
}
mn.instructions.insertBefore(v.getASMNode(), getInstrumentation(v));
} else if (v.isSwitch()) {
mn.instructions.insertBefore(v.getASMNode(), getSwitchInstrumentation(v, mn, className, methodName));
}
}
}
}
mn.maxStack += 4;
}
use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.
the class NegateCondition 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>();
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;
}
Aggregations