Search in sources :

Example 11 with PointsToSetInternal

use of soot.jimple.spark.sets.PointsToSetInternal 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 12 with PointsToSetInternal

use of soot.jimple.spark.sets.PointsToSetInternal 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 13 with PointsToSetInternal

use of soot.jimple.spark.sets.PointsToSetInternal 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 14 with PointsToSetInternal

use of soot.jimple.spark.sets.PointsToSetInternal 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 15 with PointsToSetInternal

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

the class SparkTransformer method findSetMass.

protected void findSetMass(PAG pag) {
    int mass = 0;
    int varMass = 0;
    int adfs = 0;
    int scalars = 0;
    for (final VarNode v : pag.getVarNodeNumberer()) {
        scalars++;
        PointsToSetInternal set = v.getP2Set();
        if (set != null)
            mass += set.size();
        if (set != null)
            varMass += set.size();
    }
    for (final AllocNode an : pag.allocSources()) {
        for (final AllocDotField adf : an.getFields()) {
            PointsToSetInternal set = adf.getP2Set();
            if (set != null)
                mass += set.size();
            if (set != null && set.size() > 0) {
                adfs++;
            }
        }
    }
    logger.debug("Set mass: " + mass);
    logger.debug("Variable mass: " + varMass);
    logger.debug("Scalars: " + scalars);
    logger.debug("adfs: " + adfs);
    // Compute points-to set sizes of dereference sites BEFORE
    // trimming sets by declared type
    int[] deRefCounts = new int[30001];
    for (VarNode v : pag.getDereferences()) {
        PointsToSetInternal set = v.getP2Set();
        int size = 0;
        if (set != null)
            size = set.size();
        deRefCounts[size]++;
    }
    int total = 0;
    for (int element : deRefCounts) total += element;
    logger.debug("Dereference counts BEFORE trimming (total = " + total + "):");
    for (int i = 0; i < deRefCounts.length; i++) {
        if (deRefCounts[i] > 0) {
            logger.debug("" + i + " " + deRefCounts[i] + " " + (deRefCounts[i] * 100.0 / total) + "%");
        }
    }
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) AllocDotField(soot.jimple.spark.pag.AllocDotField) AllocNode(soot.jimple.spark.pag.AllocNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal)

Aggregations

PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)37 AllocNode (soot.jimple.spark.pag.AllocNode)32 VarNode (soot.jimple.spark.pag.VarNode)28 Node (soot.jimple.spark.pag.Node)25 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)22 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)15 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)15 SparkField (soot.jimple.spark.pag.SparkField)12 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)9 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)9 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)9 HashSet (java.util.HashSet)8 AllocDotField (soot.jimple.spark.pag.AllocDotField)8 SootMethod (soot.SootMethod)7 AssignEdge (soot.jimple.spark.ondemand.pautil.AssignEdge)7 Type (soot.Type)5 ImmutableStack (soot.jimple.spark.ondemand.genericutil.ImmutableStack)5 Stack (soot.jimple.spark.ondemand.genericutil.Stack)5 ContextVarNode (soot.jimple.spark.pag.ContextVarNode)5 Propagator (soot.jimple.spark.ondemand.genericutil.Propagator)4