Search in sources :

Example 6 with LabelNode

use of org.objectweb.asm.tree.LabelNode 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);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Label(org.objectweb.asm.Label)

Example 7 with LabelNode

use of org.objectweb.asm.tree.LabelNode 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));
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Label(org.objectweb.asm.Label)

Example 8 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.

the class BranchInstrumentation method addInstrumentationForDefaultTableswitchCase.

/**
 * <p>
 * addInstrumentationForDefaultTableswitchCase
 * </p>
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 */
protected void addInstrumentationForDefaultTableswitchCase(BytecodeInstruction v, InsnList instrumentation) {
    if (!v.isTableSwitch())
        throw new IllegalArgumentException("tableswitch instruction expected");
    // setup instructions
    TableSwitchInsnNode toInstrument = (TableSwitchInsnNode) v.getASMNode();
    LabelNode caseLabel = new LabelNode();
    LabelNode defaultLabel = new LabelNode();
    LabelNode endLabel = new LabelNode();
    int keySize = (toInstrument.max - toInstrument.min) + 1;
    LabelNode[] caseLabels = new LabelNode[keySize];
    for (int i = 0; i < keySize; i++) caseLabels[i] = caseLabel;
    TableSwitchInsnNode mySwitch = new TableSwitchInsnNode(toInstrument.min, toInstrument.max, defaultLabel, caseLabels);
    // add instrumentation
    addDefaultCaseInstrumentation(v, instrumentation, mySwitch, defaultLabel, caseLabel, endLabel);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode)

Example 9 with LabelNode

use of org.objectweb.asm.tree.LabelNode 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;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) AnnotatedLabel(org.evosuite.runtime.instrumentation.AnnotatedLabel) Branch(org.evosuite.coverage.branch.Branch) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Example 10 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project evosuite by EvoSuite.

the class NegateCondition method apply.

/* (non-Javadoc)
	 * @see org.evosuite.cfg.instrumentation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
	 */
/**
 * {@inheritDoc}
 */
@Override
public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) {
    List<Mutation> mutations = new LinkedList<Mutation>();
    JumpInsnNode node = (JumpInsnNode) instruction.getASMNode();
    LabelNode target = node.label;
    // insert mutation into bytecode with conditional
    JumpInsnNode mutation = new JumpInsnNode(getOpposite(node.getOpcode()), target);
    // insert mutation into pool
    Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME, instruction, mutation, Mutation.getDefaultInfectionDistance());
    mutations.add(mutationObject);
    return mutations;
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) Mutation(org.evosuite.coverage.mutation.Mutation) LinkedList(java.util.LinkedList)

Aggregations

LabelNode (org.objectweb.asm.tree.LabelNode)89 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)37 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)32 Label (org.objectweb.asm.Label)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)23 InsnList (org.objectweb.asm.tree.InsnList)22 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)21 InsnNode (org.objectweb.asm.tree.InsnNode)20 MethodNode (org.objectweb.asm.tree.MethodNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)17 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)16 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)10 Type (org.objectweb.asm.Type)8 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)8 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)5 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)5