Search in sources :

Example 1 with P2SetVisitor

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

the class GeomPointsTo method finalizeInternalData.

/**
 * 1. Update the call graph;
 * 2. Eliminate the pointers, objects, and constraints related to the unreachable code.
 */
private void finalizeInternalData() {
    // Compute the set of reachable functions after the points-to analysis
    markReachableMethods();
    // Clean the unreachable objects
    for (Iterator<IVarAbstraction> it = allocations.iterator(); it.hasNext(); ) {
        IVarAbstraction po = it.next();
        AllocNode obj = (AllocNode) po.getWrappedNode();
        SootMethod sm = obj.getMethod();
        if (sm != null && func2int.containsKey(sm) == false)
            it.remove();
    }
    // Clean the unreachable pointers
    final Vector<AllocNode> removeSet = new Vector<AllocNode>();
    for (Iterator<IVarAbstraction> it = pointers.iterator(); it.hasNext(); ) {
        IVarAbstraction pn = it.next();
        // Is this pointer obsoleted?
        Node vn = pn.getWrappedNode();
        SootMethod sm = null;
        if (vn instanceof LocalVarNode) {
            sm = ((LocalVarNode) vn).getMethod();
        } else if (vn instanceof AllocDotField) {
            sm = ((AllocDotField) vn).getBase().getMethod();
        }
        if (sm != null) {
            if (func2int.containsKey(sm) == false) {
                pn.deleteAll();
                vn.discardP2Set();
                it.remove();
                continue;
            }
        }
        if (pn.getRepresentative() != pn)
            continue;
        removeSet.clear();
        if (pn.hasPTResult()) {
            // We remove the useless shapes or objects
            Set<AllocNode> objSet = pn.get_all_points_to_objects();
            for (Iterator<AllocNode> oit = objSet.iterator(); oit.hasNext(); ) {
                AllocNode obj = oit.next();
                IVarAbstraction po = consG.get(obj);
                if (!po.reachable() || pn.isDeadObject(obj)) {
                    removeSet.add(obj);
                }
            }
            for (AllocNode obj : removeSet) pn.remove_points_to(obj);
            pn.drop_duplicates();
        } else {
            // We also remove unreachable objects for SPARK nodes
            PointsToSetInternal pts = vn.getP2Set();
            pts.forall(new P2SetVisitor() {

                @Override
                public void visit(Node n) {
                    IVarAbstraction pan = findInternalNode(n);
                    // The removeSet is misused as a contains set
                    if (pan.reachable())
                        removeSet.add((AllocNode) n);
                }
            });
            pts = vn.makeP2Set();
            for (AllocNode an : removeSet) pts.add(an);
        }
    }
    // Clean the useless constraints
    for (Iterator<PlainConstraint> cIt = constraints.iterator(); cIt.hasNext(); ) {
        PlainConstraint cons = cIt.next();
        IVarAbstraction lhs = cons.getLHS();
        IVarAbstraction rhs = cons.getRHS();
        if (!lhs.reachable() || !rhs.reachable() || getMethodIDFromPtr(lhs) == Constants.UNKNOWN_FUNCTION || getMethodIDFromPtr(rhs) == Constants.UNKNOWN_FUNCTION) {
            cIt.remove();
        }
    }
    // We reassign the IDs to the pointers, objects and constraints
    pointers.reassign();
    allocations.reassign();
    constraints.reassign();
}
Also used : AllocDotField(soot.jimple.spark.pag.AllocDotField) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ContextVarNode(soot.jimple.spark.pag.ContextVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) AllocNode(soot.jimple.spark.pag.AllocNode) SootMethod(soot.SootMethod) Vector(java.util.Vector) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 2 with P2SetVisitor

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

the class GeomPointsTo method field_p2set.

// --------------------------------------------------------------------------------------------------------
// -------------------------------Soot Standard Points-to Query Interface----------------------------------
// --------------------------------------------------------------------------------------------------------
private PointsToSetInternal field_p2set(PointsToSet s, final SparkField f) {
    if (!(s instanceof PointsToSetInternal))
        throw new RuntimeException("Base pointers must be stored in *PointsToSetInternal*.");
    PointsToSetInternal bases = (PointsToSetInternal) s;
    final PointsToSetInternal ret = getSetFactory().newSet(f.getType(), this);
    bases.forall(new P2SetVisitor() {

        public final void visit(Node n) {
            Node nDotF = ((AllocNode) n).dot(f);
            if (nDotF != null) {
                // nDotF.getP2Set() has been discarded in solve()
                IVarAbstraction pn = consG.get(nDotF);
                if (pn == null || hasTransformed || nDotF.getP2Set() != EmptyPointsToSet.v()) {
                    ret.addAll(nDotF.getP2Set(), null);
                    return;
                }
                pn = pn.getRepresentative();
                // PointsToSetInternal ptSet = nDotF.makeP2Set();
                for (AllocNode obj : pn.get_all_points_to_objects()) {
                    ret.add(obj);
                // ptSet.add(obj);
                }
            }
        }
    });
    return ret;
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ContextVarNode(soot.jimple.spark.pag.ContextVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 3 with P2SetVisitor

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

the class OfflineProcessor method buildDependenceGraph.

/**
 * The dependence graph reverses the assignment relations. E.g., p = q  =>  p -> q
 * Note that, the assignments that are eliminated by local variable merging should be used here.
 * Otherwise, the graph would be erroneously disconnected.
 */
protected void buildDependenceGraph() {
    for (PlainConstraint cons : geomPTA.constraints) {
        // In our constraint representation, lhs -> rhs means rhs = lhs.
        final IVarAbstraction lhs = cons.getLHS();
        final IVarAbstraction rhs = cons.getRHS();
        final SparkField field = cons.f;
        IVarAbstraction rep;
        // Now we use this constraint for graph construction
        switch(cons.type) {
            // rhs = lhs
            case Constants.ASSIGN_CONS:
                add_graph_edge(rhs.id, lhs.id);
                break;
            // rhs = lhs.f
            case Constants.LOAD_CONS:
                {
                    rep = lhs.getRepresentative();
                    if (rep.hasPTResult() == false) {
                        lhs.getWrappedNode().getP2Set().forall(new P2SetVisitor() {

                            @Override
                            public void visit(Node n) {
                                IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) n, field);
                                if (padf == null || padf.reachable() == false)
                                    return;
                                off_graph_edge e = add_graph_edge(rhs.id, padf.id);
                                e.base_var = lhs;
                            }
                        });
                    } else {
                        // Use geom
                        for (AllocNode o : rep.get_all_points_to_objects()) {
                            IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) o, field);
                            if (padf == null || padf.reachable() == false)
                                continue;
                            off_graph_edge e = add_graph_edge(rhs.id, padf.id);
                            e.base_var = lhs;
                        }
                    }
                }
                break;
            // rhs.f = lhs
            case Constants.STORE_CONS:
                {
                    rep = rhs.getRepresentative();
                    if (rep.hasPTResult() == false) {
                        rhs.getWrappedNode().getP2Set().forall(new P2SetVisitor() {

                            @Override
                            public void visit(Node n) {
                                IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) n, field);
                                if (padf == null || padf.reachable() == false)
                                    return;
                                off_graph_edge e = add_graph_edge(padf.id, lhs.id);
                                e.base_var = rhs;
                            }
                        });
                    } else {
                        // use geom
                        for (AllocNode o : rep.get_all_points_to_objects()) {
                            IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) o, field);
                            if (padf == null || padf.reachable() == false)
                                continue;
                            off_graph_edge e = add_graph_edge(padf.id, lhs.id);
                            e.base_var = rhs;
                        }
                    }
                }
                break;
        }
    }
}
Also used : PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) AllocNode(soot.jimple.spark.pag.AllocNode) SparkField(soot.jimple.spark.pag.SparkField) 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) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 4 with P2SetVisitor

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

the class OfflineProcessor method distillConstraints.

/**
 * Eliminate the constraints that do not contribute points-to information to the seed pointers.
 * Prerequisite: dependence graph
 */
protected void distillConstraints() {
    IVarAbstraction pn;
    // Mark the pointers
    computeReachablePts();
    // Mark the constraints
    for (PlainConstraint cons : geomPTA.constraints) {
        // We only look at the receiver pointers
        pn = cons.getRHS();
        final SparkField field = cons.f;
        visitedFlag = false;
        switch(cons.type) {
            case Constants.NEW_CONS:
            case Constants.ASSIGN_CONS:
            case Constants.LOAD_CONS:
                visitedFlag = pn.willUpdate;
                break;
            case Constants.STORE_CONS:
                /**
                 * Interesting point in store constraint p.f = q:
                 * For example, pts(p) = { o1, o2 };
                 * If any of the o1.f and the o2.f (e.g. o1.f) will be updated, this constraint should be kept.
                 * However, in the points-to analysis, we only assign to o1.f.
                 */
                pn = pn.getRepresentative();
                if (pn.hasPTResult() == false) {
                    pn.getWrappedNode().getP2Set().forall(new P2SetVisitor() {

                        @Override
                        public void visit(Node n) {
                            if (visitedFlag)
                                return;
                            IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) n, field);
                            if (padf == null || padf.reachable() == false)
                                return;
                            visitedFlag |= padf.willUpdate;
                        }
                    });
                } else {
                    // Use the geometric points-to result
                    for (AllocNode o : pn.get_all_points_to_objects()) {
                        IVarAbstraction padf = geomPTA.findInstanceField((AllocNode) o, field);
                        if (padf == null || padf.reachable() == false)
                            continue;
                        visitedFlag |= padf.willUpdate;
                        if (visitedFlag)
                            break;
                    }
                }
                break;
        }
        cons.isActive = visitedFlag;
    }
}
Also used : PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) AllocNode(soot.jimple.spark.pag.AllocNode) SparkField(soot.jimple.spark.pag.SparkField) 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) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 5 with P2SetVisitor

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

the class HeapInsNode method injectPts.

@Override
public void injectPts() {
    final GeomPointsTo geomPTA = (GeomPointsTo) Scene.v().getPointsToAnalysis();
    pt_objs = new HashMap<AllocNode, HeapInsIntervalManager>();
    me.getP2Set().forall(new P2SetVisitor() {

        @Override
        public void visit(Node n) {
            if (geomPTA.isValidGeometricNode(n))
                pt_objs.put((AllocNode) n, (HeapInsIntervalManager) stubManager);
        }
    });
    new_pts = null;
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode) StringConstantNode(soot.jimple.spark.pag.StringConstantNode) RectangleNode(soot.jimple.spark.geom.dataRep.RectangleNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) 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