Search in sources :

Example 6 with Node

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

the class GeomPointsTo method transformToCIResult.

/**
 * For many applications, they only need the context insensitive points-to result.
 * We provide a way to transfer our result back to SPARK.
 * After the transformation, we discard the context sensitive points-to information.
 * Therefore, if context sensitive queries are needed in future, please call ddSolve() for queried pointers first.
 */
public void transformToCIResult() {
    for (IVarAbstraction pn : pointers) {
        if (pn.getRepresentative() != pn)
            continue;
        Node node = pn.getWrappedNode();
        node.discardP2Set();
        PointsToSetInternal ptSet = node.makeP2Set();
        for (AllocNode obj : pn.get_all_points_to_objects()) {
            ptSet.add(obj);
        }
        pn.deleteAll();
    }
    hasTransformed = true;
}
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)

Example 7 with Node

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

the class OfflineProcessor method addUserDefPts.

/**
 * Compute the refined points-to results for specified pointers.
 * @param initVars
 */
public void addUserDefPts(Set<Node> initVars) {
    for (Node vn : initVars) {
        IVarAbstraction pn = geomPTA.findInternalNode(vn);
        if (pn == null) {
            // I don't know where is this pointer
            continue;
        }
        pn = pn.getRepresentative();
        if (pn.reachable()) {
            pn.willUpdate = true;
        }
    }
}
Also used : 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)

Example 8 with Node

use of soot.jimple.spark.pag.Node 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 9 with Node

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

the class OfflineProcessor method releaseSparkMem.

public void releaseSparkMem() {
    for (int i = 0; i < n_var; ++i) {
        IVarAbstraction pn = int2var.get(i);
        // Keep only the points-to results for representatives
        if (pn != pn.getRepresentative()) {
            continue;
        }
        if (pn.willUpdate) {
            Node vn = pn.getWrappedNode();
            vn.discardP2Set();
        }
    }
    System.gc();
    System.gc();
    System.gc();
    System.gc();
}
Also used : 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) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint)

Example 10 with Node

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

the class OfflineProcessor method setAllUserCodeVariablesUseful.

/**
 * All the pointers that we need their points-to information are marked.
 * @param virtualBaseSet
 */
protected void setAllUserCodeVariablesUseful() {
    for (int i = 0; i < n_var; ++i) {
        IVarAbstraction pn = int2var.get(i);
        if (pn != pn.getRepresentative())
            continue;
        Node node = pn.getWrappedNode();
        int sm_id = geomPTA.getMethodIDFromPtr(pn);
        if (!geomPTA.isReachableMethod(sm_id))
            continue;
        if (node instanceof VarNode) {
            // flag == true if node is defined in the Java library
            boolean defined_in_lib = false;
            if (node instanceof LocalVarNode) {
                defined_in_lib = ((LocalVarNode) node).getMethod().isJavaLibraryMethod();
            } else if (node instanceof GlobalVarNode) {
                SootClass sc = ((GlobalVarNode) node).getDeclaringClass();
                if (sc != null)
                    defined_in_lib = sc.isJavaLibraryClass();
            }
            if (!defined_in_lib && !geomPTA.isExceptionPointer(node)) {
                // Defined in the user code
                pn.willUpdate = true;
            }
        }
    }
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) 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) SootClass(soot.SootClass) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint)

Aggregations

Node (soot.jimple.spark.pag.Node)65 AllocNode (soot.jimple.spark.pag.AllocNode)62 VarNode (soot.jimple.spark.pag.VarNode)54 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)36 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)36 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)25 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)23 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)18 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)17 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)17 SparkField (soot.jimple.spark.pag.SparkField)17 SootMethod (soot.SootMethod)15 RefType (soot.RefType)12 Type (soot.Type)11 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)11 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)10 AllocDotField (soot.jimple.spark.pag.AllocDotField)10 HashSet (java.util.HashSet)9 SootClass (soot.SootClass)9 Value (soot.Value)6