use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class Instrumenter method instrumentPUTXXXFieldAccesses.
private void instrumentPUTXXXFieldAccesses(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.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
// construction of
// Capturer.capture(final Object receiver, final String methodName, final Object[] methodParams)
// call
final InsnList il = new InsnList();
if (opcode == Opcodes.PUTFIELD) {
Type fieldType = Type.getType(fieldIns.desc);
if (fieldType.getSize() == 1) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP2));
il.add(new InsnNode(Opcodes.POP));
} else if (fieldType.getSize() == 2) {
InsnList uglyList = new InsnList();
// v, w
uglyList.add(new InsnNode(Opcodes.DUP2_X1));
// w, v, w
uglyList.add(new InsnNode(Opcodes.POP2));
// w, v
uglyList.add(new InsnNode(Opcodes.DUP));
// w, v, v
uglyList.add(new InsnNode(Opcodes.DUP2_X2));
// v, v, w, v, v
uglyList.add(new InsnNode(Opcodes.POP2));
// v, v, w
instructions.insertBefore(fieldIns, uglyList);
// PUTFIELD
// v
}
} 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(FieldRegistry.class), "notifyModification", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));
// PUTFIELDRegistry.notifyModification also adds corresponding GETFIELD capture instructions
this.captureId++;
i += il.size();
instructions.insert(fieldIns, il);
this.captureId++;
}
}
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class LCSAJsInstrumentation method addInstrumentation.
@SuppressWarnings("unchecked")
private void addInstrumentation(ClassLoader classLoader, MethodNode mn, String className, String methodName) {
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.isForcedBranch()) {
LCSAJPool.addLCSAJBranch(BranchPool.getInstance(classLoader).getBranchForInstruction(v));
int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(v);
InsnList instrumentation = new InsnList();
instrumentation.add(new LdcInsnNode(v.getASMNode().getOpcode()));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(v.getInstructionId()));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/evosuite/testcase/ExecutionTracer", "passedUnconditionalBranch", "(III)V"));
if (v.isLabel())
mn.instructions.insert(v.getASMNode(), instrumentation);
else
mn.instructions.insertBefore(v.getASMNode(), instrumentation);
}
}
}
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project cassandra by apache.
the class MonitorMethodTransformer method invokePreMonitorEnter.
void invokePreMonitorEnter() {
pushRef();
instructions.add(new LdcInsnNode(monitorDelayChance.get()));
instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/apache/cassandra/simulator/systems/InterceptorOfSystemMethods$Global", "preMonitorEnter", "(Ljava/lang/Object;F)Ljava/lang/Object;", false));
}
use of org.objectweb.asm.tree.LdcInsnNode in project spring-loaded by spring-projects.
the class TypeDiffComputer method sameLdcInsnNode.
private static boolean sameLdcInsnNode(AbstractInsnNode o, AbstractInsnNode n) {
LdcInsnNode oi = (LdcInsnNode) o;
if (!(n instanceof LdcInsnNode)) {
return false;
}
LdcInsnNode ni = (LdcInsnNode) n;
Object ocst = oi.cst;
if (ocst instanceof Integer) {
if (!(ni.cst instanceof Integer)) {
return false;
}
return ((Integer) ocst).equals(ni.cst);
}
if (ocst instanceof Float) {
if (!(ni.cst instanceof Float)) {
return false;
}
return ((Float) ocst).equals(ni.cst);
}
if (ocst instanceof Long) {
if (!(ni.cst instanceof Long)) {
return false;
}
return ((Long) ocst).equals(ni.cst);
}
if (ocst instanceof Double) {
if (!(ni.cst instanceof Double)) {
return false;
}
return ((Double) ocst).equals(ni.cst);
}
if (ocst instanceof String) {
if (!(ni.cst instanceof String)) {
return false;
}
return ((String) ocst).equals(ni.cst);
}
// must be Type
return ((Type) ocst).equals(ni.cst);
}
use of org.objectweb.asm.tree.LdcInsnNode in project parseq by linkedin.
the class Util method getDescriptionForTypeInsnNode.
/* package private */
static String getDescriptionForTypeInsnNode(TypeInsnNode typeInsnNode) {
AbstractInsnNode nextInsn = typeInsnNode.getNext();
StringJoiner argsDesc = new StringJoiner(",", "(", ")");
while (nextInsn != null) {
if (nextInsn instanceof LdcInsnNode) {
argsDesc.add("_");
} else if (nextInsn.getOpcode() == Opcodes.DUP) {
// ignore
} else {
break;
}
nextInsn = nextInsn.getNext();
}
if (typeInsnNode.getOpcode() == Opcodes.NEW) {
return "new " + Util.extractSimpleName(typeInsnNode.desc, "/") + argsDesc.toString();
}
return "";
}
Aggregations