use of org.objectweb.asm.tree.TableSwitchInsnNode in project maple-ir by LLVM-but-worse.
the class TableSwitchInsnNodeSerializer method deserialize.
@Override
public TableSwitchInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
int min = jsonObject.get("min").getAsInt();
int max = jsonObject.get("max").getAsInt();
LabelNode dflt = context.deserialize(jsonObject.get("dflt"), LabelNode.class);
List<LabelNode> labelList = context.deserialize(jsonObject.get("labels"), List.class);
LabelNode[] labels = new LabelNode[labelList.size()];
for (int i = 0; i < labels.length; i++) {
labels[i] = labelList.get(i);
}
return new TableSwitchInsnNode(min, max, dflt, labels);
}
use of org.objectweb.asm.tree.TableSwitchInsnNode in project evosuite by EvoSuite.
the class LCSAJsInstrumentation method analyze.
/* (non-Javadoc)
* @see org.evosuite.cfg.MethodInstrumentation#analyze(org.objectweb.asm.tree.MethodNode, org.jgrapht.Graph, java.lang.String, java.lang.String)
*/
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
// using external lib
@Override
public void analyze(ClassLoader classLoader, MethodNode mn, String className, String methodName, int access) {
Queue<LCSAJ> lcsaj_queue = new LinkedList<LCSAJ>();
HashSet<Integer> targets_reached = new HashSet<Integer>();
AbstractInsnNode start = mn.instructions.getFirst();
int startID = 0;
// TODO: This should replace the hack below
if (methodName.startsWith("<init>")) {
Iterator<AbstractInsnNode> j = mn.instructions.iterator();
boolean constructorInvoked = false;
while (j.hasNext()) {
AbstractInsnNode in = j.next();
startID++;
if (!constructorInvoked) {
if (in.getOpcode() == Opcodes.INVOKESPECIAL) {
MethodInsnNode cn = (MethodInsnNode) in;
Collection<String> superClasses = DependencyAnalysis.getInheritanceTree().getSuperclasses(className);
superClasses.add(className);
String classNameWithDots = ResourceList.getClassNameFromResourcePath(cn.owner);
if (superClasses.contains(classNameWithDots)) {
constructorInvoked = true;
break;
}
} else {
continue;
}
}
}
}
/*
if (methodName.startsWith("<init>")) {
if (mn.instructions.size() >= 4) {
start = mn.instructions.get(4);
startID = 4;
}
}
*/
LCSAJ a = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader).getInstruction(className, methodName, startID, start));
lcsaj_queue.add(a);
targets_reached.add(0);
ArrayList<TryCatchBlockNode> tc_blocks = (ArrayList<TryCatchBlockNode>) mn.tryCatchBlocks;
for (TryCatchBlockNode t : tc_blocks) {
LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader).getInstruction(className, methodName, mn.instructions.indexOf(t.handler), t.handler));
lcsaj_queue.add(b);
}
while (!lcsaj_queue.isEmpty()) {
LCSAJ currentLCSAJ = lcsaj_queue.poll();
int position = mn.instructions.indexOf(currentLCSAJ.getLastNodeAccessed());
// go to next bytecode instruction
position++;
if (position >= mn.instructions.size()) {
// New LCSAJ for current + return
LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
continue;
}
AbstractInsnNode next = mn.instructions.get(position);
currentLCSAJ.lookupInstruction(position, BytecodeInstructionPool.getInstance(classLoader).getInstruction(className, methodName, position, next));
if (next instanceof JumpInsnNode) {
JumpInsnNode jump = (JumpInsnNode) next;
// New LCSAJ for current + jump to target
LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
LabelNode target = jump.label;
int targetPosition = mn.instructions.indexOf(target);
if (jump.getOpcode() != Opcodes.GOTO) {
LCSAJ copy = new LCSAJ(currentLCSAJ);
lcsaj_queue.add(copy);
}
if (!targets_reached.contains(targetPosition)) {
LCSAJ c = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader).getInstruction(className, methodName, targetPosition, target));
lcsaj_queue.add(c);
targets_reached.add(targetPosition);
}
} else if (next instanceof TableSwitchInsnNode) {
TableSwitchInsnNode tswitch = (TableSwitchInsnNode) next;
List<LabelNode> allTargets = tswitch.labels;
for (LabelNode target : allTargets) {
int targetPosition = mn.instructions.indexOf(target);
if (!targets_reached.contains(targetPosition)) {
LCSAJ b = new LCSAJ(className, methodName, BytecodeInstructionPool.getInstance(classLoader).getInstruction(className, methodName, targetPosition, target));
lcsaj_queue.add(b);
targets_reached.add(targetPosition);
}
}
} else if (next instanceof InsnNode) {
InsnNode insn = (InsnNode) next;
// New LCSAJ for current + throw / return
if (insn.getOpcode() == Opcodes.ATHROW || insn.getOpcode() == Opcodes.RETURN || insn.getOpcode() == Opcodes.ARETURN || insn.getOpcode() == Opcodes.IRETURN || insn.getOpcode() == Opcodes.DRETURN || insn.getOpcode() == Opcodes.LRETURN || insn.getOpcode() == Opcodes.FRETURN) {
LCSAJPool.add_lcsaj(className, methodName, currentLCSAJ);
} else
lcsaj_queue.add(currentLCSAJ);
} else
lcsaj_queue.add(currentLCSAJ);
}
if (Properties.STRATEGY != Strategy.EVOSUITE)
addInstrumentation(classLoader, mn, className, methodName);
// if (Properties.WRITE_CFG)
// for (LCSAJ l : LCSAJPool.getLCSAJs(className, methodName)) {
// LCSAJGraph graph = new LCSAJGraph(l, false);
// String graphDestination = "evosuite-graphs/LCSAJGraphs/" + className
// + "/" + methodName;
// File dir = new File(graphDestination);
// if (dir.mkdirs())
// graph.generate(new File(graphDestination + "/LCSAJGraph no: "
// + l.getID() + ".dot"));
// else if (dir.exists())
// graph.generate(new File(graphDestination + "/LCSAJGraph no: "
// + l.getID() + ".dot"));
// }
}
Aggregations