Search in sources :

Example 6 with P2SetVisitor

use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.

the class DemandCSPointsTo method checkContextsForAllocsCache.

protected PointsToSetInternal checkContextsForAllocsCache(VarAndContext varAndContext, AllocAndContextSet ret, PointsToSetInternal locs) {
    PointsToSetInternal retSet = null;
    if (contextsForAllocsCache.containsKey(varAndContext)) {
        for (AllocAndContext allocAndContext : contextsForAllocsCache.get(varAndContext).getO2()) {
            if (locs.contains(allocAndContext.alloc)) {
                ret.add(allocAndContext);
            }
        }
        final PointsToSetInternal oldLocs = contextsForAllocsCache.get(varAndContext).getO1();
        final PointsToSetInternal tmpSet = new HybridPointsToSet(locs.getType(), pag);
        locs.forall(new P2SetVisitor() {

            @Override
            public void visit(Node n) {
                if (!oldLocs.contains(n)) {
                    tmpSet.add(n);
                }
            }
        });
        retSet = tmpSet;
        oldLocs.addAll(tmpSet, null);
    } else {
        PointsToSetInternal storedSet = new HybridPointsToSet(locs.getType(), pag);
        storedSet.addAll(locs, null);
        contextsForAllocsCache.put(varAndContext, new Pair<PointsToSetInternal, AllocAndContextSet>(storedSet, new AllocAndContextSet()));
        retSet = locs;
    }
    return retSet;
}
Also used : 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) HybridPointsToSet(soot.jimple.spark.sets.HybridPointsToSet) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 7 with P2SetVisitor

use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.

the class PAG method reachingObjectsInternal.

private PointsToSet reachingObjectsInternal(PointsToSet s, final SparkField f) {
    if (getOpts().field_based() || getOpts().vta()) {
        VarNode n = findGlobalVarNode(f);
        if (n == null) {
            return EmptyPointsToSet.v();
        }
        return n.getP2Set();
    }
    if ((getOpts()).propagator() == SparkOptions.propagator_alias) {
        throw new RuntimeException("The alias edge propagator does not compute points-to information for instance fields! Use a different propagator.");
    }
    PointsToSetInternal bases = (PointsToSetInternal) s;
    final PointsToSetInternal ret = setFactory.newSet((f instanceof SootField) ? ((SootField) f).getType() : null, this);
    bases.forall(new P2SetVisitor() {

        public final void visit(Node n) {
            Node nDotF = ((AllocNode) n).dot(f);
            if (nDotF != null)
                ret.addAll(nDotF.getP2Set(), null);
        }
    });
    return ret;
}
Also used : PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) SootField(soot.SootField) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 8 with P2SetVisitor

use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.

the class PAGDumper method dumpPointsToSets.

public void dumpPointsToSets() {
    try {
        final PrintWriter file = new PrintWriter(new FileOutputStream(new File(output_dir, "solution")));
        file.println("Solution:");
        for (Iterator vnIt = pag.getVarNodeNumberer().iterator(); vnIt.hasNext(); ) {
            final VarNode vn = (VarNode) vnIt.next();
            if (vn.getReplacement() != vn) {
                continue;
            }
            PointsToSetInternal p2set = vn.getP2Set();
            if (p2set == null)
                continue;
            p2set.forall(new P2SetVisitor() {

                public final void visit(Node n) {
                    try {
                        dumpNode(vn, file);
                        file.print(" ");
                        dumpNode(n, file);
                        file.println("");
                    } catch (IOException e) {
                        throw new RuntimeException("Couldn't dump solution." + e);
                    }
                }
            });
        }
        file.close();
    } catch (IOException e) {
        throw new RuntimeException("Couldn't dump solution." + e);
    }
}
Also used : PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 9 with P2SetVisitor

use of soot.jimple.spark.sets.P2SetVisitor 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)

Example 10 with P2SetVisitor

use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.

the class PropAlias method handleVarNode.

/**
 * Propagates new points-to information of node src to all its successors.
 */
protected final boolean handleVarNode(final VarNode src) {
    boolean ret = false;
    if (src.getReplacement() != src)
        throw new RuntimeException("Got bad node " + src + " with rep " + src.getReplacement());
    final PointsToSetInternal newP2Set = src.getP2Set().getNewSet();
    if (newP2Set.isEmpty())
        return false;
    if (ofcg != null) {
        QueueReader<Node> addedEdges = pag.edgeReader();
        ofcg.updatedNode(src);
        ofcg.build();
        while (addedEdges.hasNext()) {
            Node addedSrc = (Node) addedEdges.next();
            Node addedTgt = (Node) addedEdges.next();
            ret = true;
            if (addedSrc instanceof VarNode) {
                VarNode edgeSrc = (VarNode) addedSrc;
                if (addedTgt instanceof VarNode) {
                    VarNode edgeTgt = (VarNode) addedTgt;
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null))
                        addToWorklist(edgeTgt);
                } else if (addedTgt instanceof NewInstanceNode) {
                    NewInstanceNode edgeTgt = (NewInstanceNode) addedTgt.getReplacement();
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
                        for (Node element : pag.assignInstanceLookup(edgeTgt)) {
                            addToWorklist((VarNode) element);
                        }
                    }
                }
            } else if (addedSrc instanceof AllocNode) {
                AllocNode edgeSrc = (AllocNode) addedSrc;
                VarNode edgeTgt = (VarNode) addedTgt;
                if (edgeTgt.makeP2Set().add(edgeSrc))
                    addToWorklist(edgeTgt);
            } else if (addedSrc instanceof NewInstanceNode && addedTgt instanceof VarNode) {
                final NewInstanceNode edgeSrc = (NewInstanceNode) addedSrc.getReplacement();
                final VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
                addedSrc.getP2Set().forall(new P2SetVisitor() {

                    @Override
                    public void visit(Node n) {
                        if (n instanceof ClassConstantNode) {
                            ClassConstantNode ccn = (ClassConstantNode) n;
                            Type ccnType = ccn.getClassConstant().toSootType();
                            // If the referenced class has not been loaded,
                            // we do this now
                            SootClass targetClass = ((RefType) ccnType).getSootClass();
                            if (targetClass.resolvingLevel() == SootClass.DANGLING)
                                Scene.v().forceResolve(targetClass.getName(), SootClass.SIGNATURES);
                            edgeTgt.makeP2Set().add(pag.makeAllocNode(edgeSrc.getValue(), ccnType, ccn.getMethod()));
                            addToWorklist(edgeTgt);
                        }
                    }
                });
            }
            FieldRefNode frn = null;
            if (addedSrc instanceof FieldRefNode)
                frn = (FieldRefNode) addedSrc;
            if (addedTgt instanceof FieldRefNode)
                frn = (FieldRefNode) addedTgt;
            if (frn != null) {
                VarNode base = frn.getBase();
                if (fieldToBase.put(frn.getField(), base)) {
                    aliasWorkList.add(base);
                }
            }
        }
    }
    Node[] simpleTargets = pag.simpleLookup(src);
    for (Node element : simpleTargets) {
        if (element.makeP2Set().addAll(newP2Set, null)) {
            addToWorklist((VarNode) element);
            ret = true;
        }
    }
    Node[] storeTargets = pag.storeLookup(src);
    for (Node element : storeTargets) {
        final FieldRefNode fr = (FieldRefNode) element;
        if (fr.makeP2Set().addAll(newP2Set, null)) {
            fieldRefWorkList.add(fr);
            ret = true;
        }
    }
    src.getP2Set().flushNew();
    return ret;
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) SootClass(soot.SootClass) RefType(soot.RefType) Type(soot.Type) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Aggregations

P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)26 AllocNode (soot.jimple.spark.pag.AllocNode)23 Node (soot.jimple.spark.pag.Node)23 VarNode (soot.jimple.spark.pag.VarNode)18 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)15 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)12 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)11 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)9 AllocDotField (soot.jimple.spark.pag.AllocDotField)7 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)7 SparkField (soot.jimple.spark.pag.SparkField)7 Type (soot.Type)6 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)5 RefType (soot.RefType)4 SootClass (soot.SootClass)4 SootMethod (soot.SootMethod)4 Value (soot.Value)4 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)4 HashSet (java.util.HashSet)3 Local (soot.Local)3