Search in sources :

Example 11 with VarNode

use of soot.jimple.spark.pag.VarNode in project soot by Sable.

the class DemandCSPointsTo method nodesPropagatedThrough.

@SuppressWarnings("unused")
protected Set<VarNode> nodesPropagatedThrough(final VarNode source, final PointsToSetInternal allocs) {
    final Set<VarNode> marked = new HashSet<VarNode>();
    final Stack<VarNode> worklist = new Stack<VarNode>();
    Propagator<VarNode> p = new Propagator<VarNode>(marked, worklist);
    p.prop(source);
    while (!worklist.isEmpty()) {
        VarNode curNode = worklist.pop();
        Node[] assignSources = pag.simpleInvLookup(curNode);
        for (int i = 0; i < assignSources.length; i++) {
            VarNode assignSrc = (VarNode) assignSources[i];
            if (assignSrc.getP2Set().hasNonEmptyIntersection(allocs)) {
                p.prop(assignSrc);
            }
        }
        Set<VarNode> matchSources = vMatches.vMatchInvLookup(curNode);
        for (VarNode matchSrc : matchSources) {
            if (matchSrc.getP2Set().hasNonEmptyIntersection(allocs)) {
                p.prop(matchSrc);
            }
        }
    }
    return marked;
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) Propagator(soot.jimple.spark.ondemand.genericutil.Propagator) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) HashSet(java.util.HashSet) Stack(soot.jimple.spark.ondemand.genericutil.Stack) ImmutableStack(soot.jimple.spark.ondemand.genericutil.ImmutableStack)

Example 12 with VarNode

use of soot.jimple.spark.pag.VarNode in project soot by Sable.

the class DemandCSPointsTo method getFlowsToHelper.

protected Set<VarNode> getFlowsToHelper(AllocAndContext allocAndContext) {
    Set<VarNode> ret = new ArraySet<VarNode>();
    try {
        HashSet<VarAndContext> marked = new HashSet<VarAndContext>();
        Stack<VarAndContext> worklist = new Stack<VarAndContext>();
        Propagator<VarAndContext> p = new Propagator<VarAndContext>(marked, worklist);
        AllocNode alloc = allocAndContext.alloc;
        ImmutableStack<Integer> allocContext = allocAndContext.context;
        Node[] newBarNodes = pag.allocLookup(alloc);
        for (int i = 0; i < newBarNodes.length; i++) {
            VarNode v = (VarNode) newBarNodes[i];
            ret.add(v);
            p.prop(new VarAndContext(v, allocContext));
        }
        while (!worklist.isEmpty()) {
            incrementNodesTraversed();
            VarAndContext curVarAndContext = worklist.pop();
            if (DEBUG) {
                debugPrint("looking at " + curVarAndContext);
            }
            VarNode curVar = curVarAndContext.var;
            ImmutableStack<Integer> curContext = curVarAndContext.context;
            ret.add(curVar);
            // assign
            Collection<AssignEdge> assignEdges = filterAssigns(curVar, curContext, false, true);
            for (AssignEdge assignEdge : assignEdges) {
                VarNode dst = assignEdge.getDst();
                ImmutableStack<Integer> newContext = curContext;
                if (assignEdge.isReturnEdge()) {
                    if (!curContext.isEmpty()) {
                        if (!callEdgeInSCC(assignEdge)) {
                            assert assignEdge.getCallSite().equals(curContext.peek()) : assignEdge + " " + curContext;
                            newContext = curContext.pop();
                        } else {
                            newContext = popRecursiveCallSites(curContext);
                        }
                    }
                } else if (assignEdge.isParamEdge()) {
                    if (DEBUG)
                        debugPrint("entering call site " + assignEdge.getCallSite());
                    // if (!isRecursive(curContext, assignEdge)) {
                    // newContext = curContext.push(assignEdge
                    // .getCallSite());
                    // }
                    newContext = pushWithRecursionCheck(curContext, assignEdge);
                }
                if (assignEdge.isReturnEdge() && curContext.isEmpty() && csInfo.isVirtCall(assignEdge.getCallSite())) {
                    Set<SootMethod> targets = refineCallSite(assignEdge.getCallSite(), newContext);
                    if (!targets.contains(((LocalVarNode) assignEdge.getDst()).getMethod())) {
                        continue;
                    }
                }
                if (dst instanceof GlobalVarNode) {
                    newContext = EMPTY_CALLSTACK;
                }
                p.prop(new VarAndContext(dst, newContext));
            }
            // putfield_bars
            Set<VarNode> matchTargets = vMatches.vMatchLookup(curVar);
            Node[] pfTargets = pag.storeLookup(curVar);
            for (int i = 0; i < pfTargets.length; i++) {
                FieldRefNode frNode = (FieldRefNode) pfTargets[i];
                final VarNode storeBase = frNode.getBase();
                SparkField field = frNode.getField();
                // FieldRefNode>(curVar, frNode);
                for (Pair<VarNode, VarNode> load : fieldToLoads.get(field)) {
                    final VarNode loadBase = load.getO2();
                    final PointsToSetInternal loadBaseP2Set = loadBase.getP2Set();
                    final PointsToSetInternal storeBaseP2Set = storeBase.getP2Set();
                    final VarNode matchTgt = load.getO1();
                    if (matchTargets.contains(matchTgt)) {
                        if (DEBUG) {
                            debugPrint("match source " + matchTgt);
                        }
                        PointsToSetInternal intersection = SootUtil.constructIntersection(storeBaseP2Set, loadBaseP2Set, pag);
                        boolean checkField = fieldCheckHeuristic.validateMatchesForField(field);
                        if (checkField) {
                            AllocAndContextSet sharedAllocContexts = findContextsForAllocs(new VarAndContext(storeBase, curContext), intersection);
                            for (AllocAndContext curAllocAndContext : sharedAllocContexts) {
                                CallingContextSet upContexts;
                                if (fieldCheckHeuristic.validFromBothEnds(field)) {
                                    upContexts = findUpContextsForVar(curAllocAndContext, new VarContextAndUp(loadBase, EMPTY_CALLSTACK, EMPTY_CALLSTACK));
                                } else {
                                    upContexts = findVarContextsFromAlloc(curAllocAndContext, loadBase);
                                }
                                for (ImmutableStack<Integer> upContext : upContexts) {
                                    p.prop(new VarAndContext(matchTgt, upContext));
                                }
                            }
                        } else {
                            p.prop(new VarAndContext(matchTgt, EMPTY_CALLSTACK));
                        }
                    // h.handleMatchSrc(matchSrc, intersection,
                    // storeBase,
                    // loadBase, varAndContext, checkGetfield);
                    // if (h.terminate())
                    // return;
                    }
                }
            }
        }
        return ret;
    } catch (CallSiteException e) {
        allocAndContextCache.remove(allocAndContext);
        throw e;
    }
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) AssignEdge(soot.jimple.spark.ondemand.pautil.AssignEdge) SparkField(soot.jimple.spark.pag.SparkField) Propagator(soot.jimple.spark.ondemand.genericutil.Propagator) HashSet(java.util.HashSet) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) ArraySet(soot.jimple.spark.ondemand.genericutil.ArraySet) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) Stack(soot.jimple.spark.ondemand.genericutil.Stack) ImmutableStack(soot.jimple.spark.ondemand.genericutil.ImmutableStack) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) SootMethod(soot.SootMethod) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Example 13 with VarNode

use of soot.jimple.spark.pag.VarNode in project soot by Sable.

the class DemandCSPointsTo method dumpPathForLoc.

/*
	 * (non-Javadoc)
	 * 
	 * @see AAA.summary.Refiner#dumpPathForBadLoc(soot.jimple.spark.pag.VarNode,
	 *      soot.jimple.spark.pag.AllocNode)
	 */
protected void dumpPathForLoc(VarNode v, final AllocNode badLoc, String filePrefix) {
    final HashSet<VarNode> visited = new HashSet<VarNode>();
    final DotPointerGraph dotGraph = new DotPointerGraph();
    final class Helper {

        boolean handle(VarNode curNode) {
            assert curNode.getP2Set().contains(badLoc);
            visited.add(curNode);
            Node[] newEdges = pag.allocInvLookup(curNode);
            for (int i = 0; i < newEdges.length; i++) {
                AllocNode alloc = (AllocNode) newEdges[i];
                if (alloc.equals(badLoc)) {
                    dotGraph.addNew(alloc, curNode);
                    return true;
                }
            }
            for (AssignEdge assignEdge : csInfo.getAssignEdges(curNode)) {
                VarNode other = assignEdge.getSrc();
                if (other.getP2Set().contains(badLoc) && !visited.contains(other) && handle(other)) {
                    if (assignEdge.isCallEdge()) {
                        dotGraph.addCall(other, curNode, assignEdge.getCallSite());
                    } else {
                        dotGraph.addAssign(other, curNode);
                    }
                    return true;
                }
            }
            Node[] loadEdges = pag.loadInvLookup(curNode);
            for (int i = 0; i < loadEdges.length; i++) {
                FieldRefNode frNode = (FieldRefNode) loadEdges[i];
                SparkField field = frNode.getField();
                VarNode base = frNode.getBase();
                PointsToSetInternal baseP2Set = base.getP2Set();
                for (Pair<VarNode, VarNode> store : fieldToStores.get(field)) {
                    if (store.getO2().getP2Set().hasNonEmptyIntersection(baseP2Set)) {
                        VarNode matchSrc = store.getO1();
                        if (matchSrc.getP2Set().contains(badLoc) && !visited.contains(matchSrc) && handle(matchSrc)) {
                            dotGraph.addMatch(matchSrc, curNode);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }
    Helper h = new Helper();
    h.handle(v);
    // logger.debug(""+dotGraph.numEdges() + " edges on path");
    dotGraph.dump("tmp/" + filePrefix + v.getNumber() + "_" + badLoc.getNumber() + ".dot");
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) AssignEdge(soot.jimple.spark.ondemand.pautil.AssignEdge) SparkField(soot.jimple.spark.pag.SparkField) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) HashSet(java.util.HashSet)

Example 14 with VarNode

use of soot.jimple.spark.pag.VarNode in project soot by Sable.

the class ContextSensitiveInfo method assignEdgesWellFormed.

@SuppressWarnings("unused")
private String assignEdgesWellFormed(PAG pag) {
    for (Iterator iter = pag.getVarNodeNumberer().iterator(); iter.hasNext(); ) {
        VarNode v = (VarNode) iter.next();
        Set<AssignEdge> outgoingAssigns = getAssignBarEdges(v);
        for (AssignEdge edge : outgoingAssigns) {
            if (edge.getSrc() != v)
                return edge + " src should be " + v;
        }
        Set<AssignEdge> incomingAssigns = getAssignEdges(v);
        for (AssignEdge edge : incomingAssigns) {
            if (edge.getDst() != v)
                return edge + " dst should be " + v;
        }
    }
    return null;
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) Iterator(java.util.Iterator)

Example 15 with VarNode

use of soot.jimple.spark.pag.VarNode in project soot by Sable.

the class SparkTransformer method addTags.

protected void addTags(PAG pag) {
    final Tag unknown = new StringTag("Untagged Spark node");
    final Map<Node, Tag> nodeToTag = pag.getNodeTags();
    for (final SootClass c : Scene.v().getClasses()) {
        for (final SootMethod m : c.getMethods()) {
            if (!m.isConcrete())
                continue;
            if (!m.hasActiveBody())
                continue;
            for (final Unit u : m.getActiveBody().getUnits()) {
                final Stmt s = (Stmt) u;
                if (s instanceof DefinitionStmt) {
                    Value lhs = ((DefinitionStmt) s).getLeftOp();
                    VarNode v = null;
                    if (lhs instanceof Local) {
                        v = pag.findLocalVarNode(lhs);
                    } else if (lhs instanceof FieldRef) {
                        v = pag.findGlobalVarNode(((FieldRef) lhs).getField());
                    }
                    if (v != null) {
                        PointsToSetInternal p2set = v.getP2Set();
                        p2set.forall(new P2SetVisitor() {

                            public final void visit(Node n) {
                                addTag(s, n, nodeToTag, unknown);
                            }
                        });
                        Node[] simpleSources = pag.simpleInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.allocInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.loadInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                    }
                }
            }
        }
    }
}
Also used : StringTag(soot.tagkit.StringTag) VarNode(soot.jimple.spark.pag.VarNode) FieldRef(soot.jimple.FieldRef) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Local(soot.Local) SootClass(soot.SootClass) Unit(soot.Unit) Stmt(soot.jimple.Stmt) DefinitionStmt(soot.jimple.DefinitionStmt) Value(soot.Value) SootMethod(soot.SootMethod) Tag(soot.tagkit.Tag) StringTag(soot.tagkit.StringTag) DefinitionStmt(soot.jimple.DefinitionStmt) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Aggregations

VarNode (soot.jimple.spark.pag.VarNode)47 AllocNode (soot.jimple.spark.pag.AllocNode)37 Node (soot.jimple.spark.pag.Node)29 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)24 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)23 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)22 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)17 SparkField (soot.jimple.spark.pag.SparkField)15 HashSet (java.util.HashSet)11 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)11 SootMethod (soot.SootMethod)10 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)10 RefType (soot.RefType)8 Type (soot.Type)8 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)8 AssignEdge (soot.jimple.spark.ondemand.pautil.AssignEdge)7 Iterator (java.util.Iterator)6 ImmutableStack (soot.jimple.spark.ondemand.genericutil.ImmutableStack)6 Stack (soot.jimple.spark.ondemand.genericutil.Stack)6 AllocDotField (soot.jimple.spark.pag.AllocDotField)6