use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class DefUseInstrumentation method getInstrumentation.
/**
* Creates the instrumentation needed to track defs and uses
*/
private InsnList getInstrumentation(BytecodeInstruction v, boolean staticContext, String className, String methodName, MethodNode mn) {
InsnList instrumentation = new InsnList();
if (!v.isDefUse()) {
logger.warn("unexpected DefUseInstrumentation call for a non-DU-instruction");
return instrumentation;
}
if (DefUsePool.isKnownAsFieldMethodCall(v)) {
return getMethodInstrumentation(v, staticContext, instrumentation, mn);
}
if (DefUsePool.isKnownAsUse(v)) {
// The actual object that is defined is on the stack _after_ the load instruction
addObjectInstrumentation(v, instrumentation, mn);
addCallingObjectInstrumentation(staticContext, instrumentation);
instrumentation.add(new LdcInsnNode(DefUsePool.getUseCounter()));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedUse", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
}
if (DefUsePool.isKnownAsDefinition(v)) {
// The actual object that is defined is on the stack _before_ the store instruction
addObjectInstrumentation(v, instrumentation, mn);
addCallingObjectInstrumentation(staticContext, instrumentation);
instrumentation.add(new LdcInsnNode(DefUsePool.getDefCounter()));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcase.execution.ExecutionTracer.class), "passedDefinition", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
}
return instrumentation;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class Instrumenter method addCaptureEnableStatement.
private void addCaptureEnableStatement(final String className, final MethodNode mn, final InsnList il, final int returnValueVar) {
il.add(new LdcInsnNode(this.captureId));
if (TransformerUtil.isStatic(mn.access)) {
// static method
il.add(new LdcInsnNode(className));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(CaptureUtil.class), "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"));
} else {
// non-static method
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
}
final Type returnType = Type.getReturnType(mn.desc);
if (returnType.equals(Type.VOID_TYPE)) {
// load return value for VOID methods
il.add(new FieldInsnNode(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(CaptureLog.class), "RETURN_TYPE_VOID", Type.getDescriptor(Object.class)));
} else {
// load return value as object
il.add(new VarInsnNode(Opcodes.ALOAD, returnValueVar));
}
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.Capturer.class), "enable", "(ILjava/lang/Object;Ljava/lang/Object;)V"));
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class InstanceOfTransformer method transformTypeInsnNode.
/* (non-Javadoc)
* @see org.evosuite.instrumentation.MethodNodeTransformer#transformTypeInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.TypeInsnNode)
*/
@Override
protected AbstractInsnNode transformTypeInsnNode(MethodNode mn, TypeInsnNode typeNode) {
if (typeNode.getOpcode() == Opcodes.INSTANCEOF) {
TransformationStatistics.transformInstanceOf();
// Depending on the class version we need a String or a Class
// TODO: This needs to be class version of the class that's loaded, not cn!
// ClassReader reader;
int version = 48;
/*
String name = typeNode.desc.replace('/', '.');
try {
reader = new ClassReader(name);
ClassNode parent = new ClassNode();
reader.accept(parent, ClassReader.SKIP_CODE);
version = parent.version;
} catch (IOException e) {
TestabilityTransformation.logger.info("Error reading class " + name);
}
*/
if (version >= 49) {
if (!typeNode.desc.startsWith("[")) {
LdcInsnNode lin = new LdcInsnNode(Type.getType("L" + typeNode.desc + ";"));
mn.instructions.insertBefore(typeNode, lin);
} else {
LdcInsnNode lin = new LdcInsnNode(Type.getType(typeNode.desc + ";"));
mn.instructions.insertBefore(typeNode, lin);
}
} else {
LdcInsnNode lin = new LdcInsnNode(typeNode.desc.replace('/', '.'));
mn.instructions.insertBefore(typeNode, lin);
MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), new Type[] { Type.getType(String.class) }));
mn.instructions.insertBefore(typeNode, n);
}
MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "instanceOf", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.getType(Class.class) }));
mn.instructions.insertBefore(typeNode, n);
mn.instructions.remove(typeNode);
return n;
}
return typeNode;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class ReplaceComparisonOperator method getInfectionDistance.
/**
* <p>getInfectionDistance</p>
*
* @param opcodeOrig a int.
* @param opcodeNew a int.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) {
InsnList distance = new InsnList();
switch(opcodeOrig) {
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ICMPNE:
case Opcodes.IF_ICMPLE:
case Opcodes.IF_ICMPLT:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
distance.add(new InsnNode(Opcodes.DUP2));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(IIII)D", false));
break;
case Opcodes.IFEQ:
case Opcodes.IFNE:
case Opcodes.IFLE:
case Opcodes.IFLT:
case Opcodes.IFGE:
case Opcodes.IFGT:
distance.add(new InsnNode(Opcodes.DUP));
distance.add(new LdcInsnNode(opcodeOrig));
distance.add(new LdcInsnNode(opcodeNew));
distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(III)D", false));
break;
default:
distance.add(new LdcInsnNode(0.0));
}
return distance;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class ReplaceVariable method copy.
/**
* <p>
* copy
* </p>
*
* @param orig
* a {@link org.objectweb.asm.tree.InsnList} object.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
public static InsnList copy(InsnList orig) {
Iterator<?> it = orig.iterator();
InsnList copy = new InsnList();
while (it.hasNext()) {
AbstractInsnNode node = (AbstractInsnNode) it.next();
if (node instanceof VarInsnNode) {
VarInsnNode vn = (VarInsnNode) node;
copy.add(new VarInsnNode(vn.getOpcode(), vn.var));
} else if (node instanceof FieldInsnNode) {
FieldInsnNode fn = (FieldInsnNode) node;
copy.add(new FieldInsnNode(fn.getOpcode(), fn.owner, fn.name, fn.desc));
} else if (node instanceof InsnNode) {
if (node.getOpcode() != Opcodes.POP)
copy.add(new InsnNode(node.getOpcode()));
} else if (node instanceof LdcInsnNode) {
copy.add(new LdcInsnNode(((LdcInsnNode) node).cst));
} else {
throw new RuntimeException("Unexpected node type: " + node.getClass());
}
}
return copy;
}
Aggregations