Search in sources :

Example 21 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class AllUsesAnalysis method useStoredInformationForMethodCall.

private Set<Map<String, VariableDefinition>> useStoredInformationForMethodCall(CCFGMethodEntryNode investigatedMethod, CCFGMethodCallNode callNode, Set<Map<String, VariableDefinition>> activeDefMapsInCaller, Set<BytecodeInstruction> freeUses, Set<DefUseCoverageTestFitness> foundPairs, MethodCall call) {
    // 
    Set<BytecodeInstruction> freeUsesInCalledMethod = determinedFreeUses.get(callNode.getCalledMethod());
    for (BytecodeInstruction freeUseInCalledMethod : freeUsesInCalledMethod) {
        for (Map<String, VariableDefinition> activeDefMap : activeDefMapsInCaller) {
            VariableDefinition activeDef = activeDefMap.get(freeUseInCalledMethod.getVariableName());
            if (activeDef == null) {
                // there was a path to the calledMethod that did not define
                // the variable of our freeUse, so it is still free
                freeUses.add(freeUseInCalledMethod);
            } else {
                // inter-method pair
                if (freeUseInCalledMethod.isFieldUse()) {
                    addNewGoalToFoundPairs(investigatedMethod, activeDef, freeUseInCalledMethod, DefUsePairType.INTER_METHOD, foundPairs);
                }
            }
        }
    }
    Set<Map<String, BytecodeInstruction>> activeDefMapsInCallee = determinedActiveDefs.get(callNode.getCalledMethod());
    Set<Map<String, VariableDefinition>> activeDefMapsAfterCurrentCall = new HashSet<Map<String, VariableDefinition>>();
    long start = System.currentTimeMillis();
    // mingle each of these maps with each of the currently active maps
    for (Map<String, BytecodeInstruction> activeDefMapInCallee : activeDefMapsInCallee) {
        for (Map<String, VariableDefinition> activeDefMapInCaller : activeDefMapsInCaller) {
            Set<String> relevantVariables = new HashSet<String>(activeDefMapInCallee.keySet());
            relevantVariables.addAll(activeDefMapInCaller.keySet());
            // mingle both activeDefMaps from prior to the call and when
            // returning from call to a new one that will be true after the
            // call
            Map<String, VariableDefinition> activeDefMapAfterCurrentCall = new HashMap<String, VariableDefinition>();
            for (String variable : relevantVariables) {
                BytecodeInstruction activeDefAfterCall = activeDefMapInCallee.get(variable);
                VariableDefinition activeDefPriorToCall = activeDefMapInCaller.get(variable);
                if (activeDefAfterCall == null) {
                    if (activeDefPriorToCall == null)
                        throw new IllegalStateException("expect activeDefMaps not to map to null values");
                    // variable was not overwritten in called
                    // method, so the activeDef prior to the call stays
                    // active
                    activeDefMapAfterCurrentCall.put(variable, activeDefPriorToCall);
                } else {
                    // variable was overwritten in call, so we will make a
                    // new VariableDefinition and keep that active in the
                    // newly created map
                    VariableDefinition overwritingDefinition = new VariableDefinition(activeDefAfterCall, call);
                    activeDefMapAfterCurrentCall.put(variable, overwritingDefinition);
                }
            }
            // System.out.println("mingled map:");
            // printVDDefMap(activeDefMapAfterCurrentCall);
            activeDefMapsAfterCurrentCall.add(activeDefMapAfterCurrentCall);
        }
    }
    // System.out.println("Finished mingling. #Resulting-Maps: "+activeDefMapsAfterCurrentCall.size());
    timeSpentMingling += System.currentTimeMillis() - start;
    return activeDefMapsAfterCurrentCall;
}
Also used : HashMap(java.util.HashMap) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 22 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class AllUsesAnalysis method createIntraClassPairsForFreeUse.

private Set<DefUseCoverageTestFitness> createIntraClassPairsForFreeUse(BytecodeInstruction freeUse) {
    checkFreeUseSanity(freeUse);
    Set<DefUseCoverageTestFitness> r = new HashSet<DefUseCoverageTestFitness>();
    for (String method : determinedActiveDefs.keySet()) {
        if (!ccfg.isPublicMethod(method)) {
            continue;
        }
        Set<Map<String, BytecodeInstruction>> activeDefss = determinedActiveDefs.get(method);
        for (Map<String, BytecodeInstruction> activeDefs : activeDefss) {
            // checkActiveDefsSanity(activeDefs);
            // if (activeDefs.get(freeUse.getDUVariableName()) == null)
            // continue;
            BytecodeInstruction activeDef = activeDefs.get(freeUse.getVariableName());
            if (activeDef == null)
                continue;
            addNewGoalToFoundPairs(null, activeDef, freeUse, DefUsePairType.INTRA_CLASS, r);
        }
    }
    return r;
}
Also used : DefUseCoverageTestFitness(org.evosuite.coverage.dataflow.DefUseCoverageTestFitness) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class DefUseCoverageTestFitness method getInstructionsBeforeGoalUse.

/**
 * Returns a set containing all CFGVertices in the goal use method that come
 * before the goal use.
 *
 * Look at ControlFlowGraph.getPreviousInstructionInMethod() for details
 *
 * @return a {@link java.util.Set} object.
 */
public Set<BytecodeInstruction> getInstructionsBeforeGoalUse() {
    RawControlFlowGraph cfg = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getRawCFG(goalUse.getClassName(), goalUse.getMethodName());
    BytecodeInstruction useVertex = cfg.getInstruction(goalUse.getInstructionId());
    Set<BytecodeInstruction> r = cfg.getPreviousInstructionsInMethod(useVertex);
    // }
    return r;
}
Also used : BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Example 24 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction in project evosuite by EvoSuite.

the class DefUseExecutionTraceAnalyzer method getOverwritingDefinitionsIn.

/**
 * Returns a Set containing all elements in the given vertex set that are
 * overwriting definitions for the given targetDefinition
 *
 * @param targetDefinition
 *            a {@link org.evosuite.coverage.dataflow.Definition} object.
 * @param vertices
 *            a {@link java.util.Collection} object.
 * @return a {@link java.util.Set} object.
 */
public static Set<BytecodeInstruction> getOverwritingDefinitionsIn(Definition targetDefinition, Collection<BytecodeInstruction> vertices) {
    Set<BytecodeInstruction> r = new HashSet<BytecodeInstruction>();
    for (BytecodeInstruction vertex : vertices) {
        if (!vertex.isDefinition())
            continue;
        BytecodeInstruction vertexInOtherGraph = GraphPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getRawCFG(vertex.getClassName(), vertex.getMethodName()).getInstruction(vertex.getInstructionId());
        Definition currentDefinition = DefUseFactory.makeDefinition(vertexInOtherGraph);
        if (isOverwritingDefinition(targetDefinition, currentDefinition))
            r.add(vertex);
    }
    return r;
}
Also used : BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) HashSet(java.util.HashSet)

Example 25 with BytecodeInstruction

use of org.evosuite.graphs.cfg.BytecodeInstruction 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);
                }
            }
        }
    }
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Aggregations

BytecodeInstruction (org.evosuite.graphs.cfg.BytecodeInstruction)28 RawControlFlowGraph (org.evosuite.graphs.cfg.RawControlFlowGraph)10 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)6 ControlDependency (org.evosuite.graphs.cfg.ControlDependency)5 InsnList (org.objectweb.asm.tree.InsnList)5 HashSet (java.util.HashSet)4 LabelNode (org.objectweb.asm.tree.LabelNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Branch (org.evosuite.coverage.branch.Branch)3 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CCFGCodeNode (org.evosuite.graphs.ccfg.CCFGCodeNode)2 ControlDependenceGraph (org.evosuite.graphs.cdg.ControlDependenceGraph)2 BasicBlock (org.evosuite.graphs.cfg.BasicBlock)2 ControlFlowEdge (org.evosuite.graphs.cfg.ControlFlowEdge)2 AnnotatedLabel (org.evosuite.runtime.instrumentation.AnnotatedLabel)2 Label (org.objectweb.asm.Label)2 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)2