use of org.evosuite.graphs.cfg.BytecodeInstruction 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.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class ClassControlFlowGraph method addCCFGMethodExitNode.
private CCFGMethodExitNode addCCFGMethodExitNode(RawControlFlowGraph cfg, Map<BytecodeInstruction, CCFGCodeNode> temp) {
CCFGMethodExitNode exit = new CCFGMethodExitNode(cfg.getMethodName());
addVertex(exit);
for (BytecodeInstruction exitPoint : cfg.determineExitPoints()) {
addEdge(temp.get(exitPoint), exit);
}
methodExits.put(cfg.getMethodName(), exit);
return exit;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class ClassControlFlowGraph method importCFGs.
private void importCFGs() {
Map<RawControlFlowGraph, Map<BytecodeInstruction, CCFGCodeNode>> tempMap = new HashMap<RawControlFlowGraph, Map<BytecodeInstruction, CCFGCodeNode>>();
// replace each class call node with corresponding CFG
for (ClassCallNode ccgNode : ccg.vertexSet()) {
RawControlFlowGraph cfg = getRCFG(ccgNode);
tempMap.put(cfg, importCFG(cfg));
}
connectCFGs(tempMap);
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class ImplicitElseTransformer method transformVarInsnNode.
/* (non-Javadoc)
* @see org.evosuite.instrumentation.MethodNodeTransformer#transformVarInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.VarInsnNode)
*/
@Override
protected AbstractInsnNode transformVarInsnNode(MethodNode mn, VarInsnNode varNode) {
if (varNode.getOpcode() == Opcodes.ISTORE && this.booleanTestabilityTransformation.isBooleanVariable(varNode.var, mn)) {
// Check if ICONST_0 or ICONST_1 are on the stack
ControlDependenceGraph cdg = GraphPool.getInstance(this.booleanTestabilityTransformation.classLoader).getCDG(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc);
int index = mn.instructions.indexOf(varNode);
BytecodeInstruction insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, index);
// varNode);
if (insn == null) {
// TODO: Debug this on org.exolab.jms.net.uri.URI
BooleanTestabilityTransformation.logger.info("WARNING: Instruction not found!");
return varNode;
}
if (insn.getASMNode().getOpcode() != varNode.getOpcode()) {
BooleanTestabilityTransformation.logger.info("Found wrong bytecode instruction at this index!");
insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className, mn.name + mn.desc, varNode);
if (insn == null) {
// TODO: Debug this on org.exolab.jms.net.uri.URI
BooleanTestabilityTransformation.logger.info("WARNING: Instruction not found!");
return varNode;
}
}
Set<ControlDependency> dependencies = insn.getControlDependencies();
BooleanTestabilityTransformation.logger.info("Found flag assignment: " + insn + ", checking " + dependencies.size() + " control dependencies");
for (ControlDependency dep : dependencies) {
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, varNode, insn);
}
// Only do completion if there's only one dependency
// Not sure how other cases would look like
/*
//if (dependencies.size() > 1)
// return varNode;
//else
if (dependencies.isEmpty())
return varNode;
ControlDependency dep = dependencies.iterator().next();
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, varNode, insn);
*/
}
return varNode;
}
use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.
the class ImplicitElseTransformer method transformFieldInsnNode.
/* (non-Javadoc)
* @see org.evosuite.instrumentation.MethodNodeTransformer#transformFieldInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.FieldInsnNode)
*/
@SuppressWarnings("unchecked")
@Override
protected AbstractInsnNode transformFieldInsnNode(MethodNode mn, FieldInsnNode fieldNode) {
if ((fieldNode.getOpcode() == Opcodes.PUTFIELD || fieldNode.getOpcode() == Opcodes.PUTSTATIC) && DescriptorMapping.getInstance().isTransformedOrBooleanField(fieldNode.owner, fieldNode.name, fieldNode.desc)) {
if (addedInsns.contains(fieldNode))
return fieldNode;
// whether we need to pop one or two words
if (fieldNode.getOpcode() == Opcodes.PUTFIELD) {
AbstractInsnNode previous = fieldNode.getPrevious();
while (previous instanceof LineNumberNode || previous instanceof FrameNode || previous.getOpcode() == Opcodes.ICONST_0 || previous.getOpcode() == Opcodes.ICONST_1) previous = previous.getPrevious();
if (previous.getOpcode() != Opcodes.ALOAD) {
BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
return fieldNode;
}
VarInsnNode varNode = (VarInsnNode) previous;
if (varNode.var != 0) {
BooleanTestabilityTransformation.logger.info("Can't handle case of " + previous);
return fieldNode;
}
}
BooleanTestabilityTransformation.logger.info("Handling PUTFIELD case!");
// Check if ICONST_0 or ICONST_1 are on the stack
ControlDependenceGraph cdg = GraphPool.getInstance(this.booleanTestabilityTransformation.classLoader).getCDG(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc);
int index = mn.instructions.indexOf(fieldNode);
BooleanTestabilityTransformation.logger.info("Getting bytecode instruction for " + fieldNode.name + "/" + ((FieldInsnNode) mn.instructions.get(index)).name);
InsnList nodes = mn.instructions;
ListIterator<AbstractInsnNode> it = nodes.iterator();
while (it.hasNext()) {
BytecodeInstruction in = new BytecodeInstruction(this.booleanTestabilityTransformation.classLoader, this.booleanTestabilityTransformation.className, mn.name, 0, 0, it.next());
BooleanTestabilityTransformation.logger.info(in.toString());
}
BytecodeInstruction insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, index);
if (insn == null)
insn = BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className.replace("/", "."), mn.name + mn.desc, fieldNode);
// varNode);
if (insn == null) {
// TODO: Find out why
BooleanTestabilityTransformation.logger.info("ERROR: Could not find node");
return fieldNode;
}
if (insn.getASMNode().getOpcode() != fieldNode.getOpcode()) {
BooleanTestabilityTransformation.logger.info("Found wrong bytecode instruction at this index!");
BytecodeInstructionPool.getInstance(this.booleanTestabilityTransformation.classLoader).getInstruction(this.booleanTestabilityTransformation.className, mn.name + mn.desc, fieldNode);
}
if (insn.getBasicBlock() == null) {
BooleanTestabilityTransformation.logger.info("ERROR: Problematic node found");
return fieldNode;
}
Set<ControlDependency> dependencies = insn.getControlDependencies();
BooleanTestabilityTransformation.logger.info("Found flag assignment: " + insn + ", checking " + dependencies.size() + " control dependencies");
for (ControlDependency dep : dependencies) {
if (!addedNodes.contains(dep))
handleDependency(dep, cdg, mn, fieldNode, insn);
}
}
return fieldNode;
}
Aggregations