use of org.objectweb.asm.tree.LdcInsnNode 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.LdcInsnNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method insertPush2.
/**
* Insert a call to the distance function for binary comparison
*
* @param opcode
* @param position
* @param list
*/
public void insertPush2(int opcode, JumpInsnNode position, InsnList list) {
list.insertBefore(position, new InsnNode(Opcodes.DUP2));
// list.insertBefore(position, new InsnNode(Opcodes.ISUB));
MethodInsnNode sub = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
list.insertBefore(position, sub);
insertBranchIdPlaceholder(currentMethodNode, position);
// list.insertBefore(position,
// new LdcInsnNode(getBranchID(currentMethodNode, position)));
MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
list.insertBefore(position, push);
}
use of org.objectweb.asm.tree.LdcInsnNode 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.LdcInsnNode in project evosuite by EvoSuite.
the class BranchInstrumentation method getInstrumentation.
/**
* <p>
* getInstrumentation
* </p>
*
* @param instruction
* a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
* @return a {@link org.objectweb.asm.tree.InsnList} object.
*/
protected InsnList getInstrumentation(BytecodeInstruction instruction) {
if (instruction == null)
throw new IllegalArgumentException("null given");
if (!instruction.isActualBranch())
throw new IllegalArgumentException("branch instruction expected");
if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction))
throw new IllegalArgumentException("expect given instruction to be known by the BranchPool as a normal branch instruction");
int opcode = instruction.getASMNode().getOpcode();
int instructionId = instruction.getInstructionId();
int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction);
if (branchId < 0)
throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions");
InsnList instrumentation = new InsnList();
switch(opcode) {
case Opcodes.IFEQ:
case Opcodes.IFNE:
case Opcodes.IFLT:
case Opcodes.IFGE:
case Opcodes.IFGT:
case Opcodes.IFLE:
instrumentation.add(new InsnNode(Opcodes.DUP));
instrumentation.add(new LdcInsnNode(opcode));
// instrumentation.add(new LdcInsnNode(id));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(instructionId));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id=" + instructionId);
break;
case Opcodes.IF_ICMPEQ:
case Opcodes.IF_ICMPNE:
case Opcodes.IF_ICMPLT:
case Opcodes.IF_ICMPGE:
case Opcodes.IF_ICMPGT:
case Opcodes.IF_ICMPLE:
instrumentation.add(new InsnNode(Opcodes.DUP2));
instrumentation.add(new LdcInsnNode(opcode));
// instrumentation.add(new LdcInsnNode(id));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(instructionId));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
break;
case Opcodes.IF_ACMPEQ:
case Opcodes.IF_ACMPNE:
instrumentation.add(new InsnNode(Opcodes.DUP2));
instrumentation.add(new LdcInsnNode(opcode));
// instrumentation.add(new LdcInsnNode(id));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(instructionId));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;Ljava/lang/Object;III)V", false));
break;
case Opcodes.IFNULL:
case Opcodes.IFNONNULL:
instrumentation.add(new InsnNode(Opcodes.DUP));
instrumentation.add(new LdcInsnNode(opcode));
// instrumentation.add(new LdcInsnNode(id));
instrumentation.add(new LdcInsnNode(branchId));
instrumentation.add(new LdcInsnNode(instructionId));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;III)V", false));
break;
}
return instrumentation;
}
use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class DefUseInstrumentation method getMethodInstrumentation.
private InsnList getMethodInstrumentation(BytecodeInstruction call, boolean staticContext, InsnList instrumentation, MethodNode mn) {
String descriptor = call.getMethodCallDescriptor();
Type[] args = Type.getArgumentTypes(descriptor);
int loc = getNextLocalNum(mn);
Map<Integer, Integer> to = new HashMap<Integer, Integer>();
for (int i = args.length - 1; i >= 0; i--) {
Type type = args[i];
instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ISTORE), loc));
to.put(i, loc);
loc++;
}
// instrumentation.add(new InsnNode(Opcodes.DUP));//callee
addObjectInstrumentation(call, instrumentation, mn);
addCallingObjectInstrumentation(staticContext, instrumentation);
// field method calls get special treatment:
// during instrumentation it is not clear whether a field method
// call constitutes a definition or a use. So the instrumentation
// will call a special function of the ExecutionTracer which will
// redirect the call to either passedUse() or passedDefinition()
// using the information available during runtime (the CCFGs)
instrumentation.add(new LdcInsnNode(DefUsePool.getDefUseCounter()));
instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedFieldMethodCall", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
for (int i = 0; i < args.length; i++) {
Type type = args[i];
instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), to.get(i)));
}
return instrumentation;
}
Aggregations