Search in sources :

Example 11 with Node

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

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

Example 13 with Node

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

the class EvalResults method profileSparkBasicMetrics.

/**
 * Collecting basic statistical information for SPARK.
 */
public void profileSparkBasicMetrics() {
    int n_legal_var = 0;
    int[] limits = new int[] { 1, 5, 10, 25, 50, 75, 100 };
    evalRes.pts_size_bar_spark = new Histogram(limits);
    for (IVarAbstraction pn : ptsProvider.pointers) {
        // We don't consider exception pointers
        Node var = pn.getWrappedNode();
        if (ptsProvider.isExceptionPointer(var))
            continue;
        ++n_legal_var;
        int size = var.getP2Set().size();
        evalRes.pts_size_bar_spark.addNumber(size);
        evalRes.total_spark_pts += size;
        if (size > evalRes.max_pts_spark)
            evalRes.max_pts_spark = size;
    }
    evalRes.avg_spark_pts = (double) evalRes.total_spark_pts / n_legal_var;
}
Also used : Histogram(soot.jimple.spark.geom.utils.Histogram) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) 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 14 with Node

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

the class MethodNodeFactory method handleStmt.

/**
 * Adds the edges required for this statement to the graph.
 */
public final void handleStmt(Stmt s) {
    // We only consider reflective class creation when it is enabled
    if (s.containsInvokeExpr()) {
        if (!pag.getCGOpts().types_for_invoke())
            return;
        InvokeExpr iexpr = s.getInvokeExpr();
        if (iexpr instanceof VirtualInvokeExpr) {
            if (!isReflectionNewInstance(iexpr))
                return;
        } else if (!(iexpr instanceof StaticInvokeExpr))
            return;
    }
    s.apply(new AbstractStmtSwitch() {

        @Override
        public final void caseAssignStmt(AssignStmt as) {
            Value l = as.getLeftOp();
            Value r = as.getRightOp();
            if (!(l.getType() instanceof RefLikeType))
                return;
            assert r.getType() instanceof RefLikeType : "Type mismatch in assignment " + as + " in method " + method.getSignature();
            l.apply(MethodNodeFactory.this);
            Node dest = getNode();
            r.apply(MethodNodeFactory.this);
            Node src = getNode();
            if (l instanceof InstanceFieldRef) {
                ((InstanceFieldRef) l).getBase().apply(MethodNodeFactory.this);
                pag.addDereference((VarNode) getNode());
            }
            if (r instanceof InstanceFieldRef) {
                ((InstanceFieldRef) r).getBase().apply(MethodNodeFactory.this);
                pag.addDereference((VarNode) getNode());
            } else if (r instanceof StaticFieldRef) {
                StaticFieldRef sfr = (StaticFieldRef) r;
                SootFieldRef s = sfr.getFieldRef();
                if (pag.getOpts().empties_as_allocs()) {
                    if (s.declaringClass().getName().equals("java.util.Collections")) {
                        if (s.name().equals("EMPTY_SET")) {
                            src = pag.makeAllocNode(RefType.v("java.util.HashSet"), RefType.v("java.util.HashSet"), method);
                        } else if (s.name().equals("EMPTY_MAP")) {
                            src = pag.makeAllocNode(RefType.v("java.util.HashMap"), RefType.v("java.util.HashMap"), method);
                        } else if (s.name().equals("EMPTY_LIST")) {
                            src = pag.makeAllocNode(RefType.v("java.util.LinkedList"), RefType.v("java.util.LinkedList"), method);
                        }
                    } else if (s.declaringClass().getName().equals("java.util.Hashtable")) {
                        if (s.name().equals("emptyIterator")) {
                            src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyIterator"), RefType.v("java.util.Hashtable$EmptyIterator"), method);
                        } else if (s.name().equals("emptyEnumerator")) {
                            src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyEnumerator"), RefType.v("java.util.Hashtable$EmptyEnumerator"), method);
                        }
                    }
                }
            }
            mpag.addInternalEdge(src, dest);
        }

        @Override
        public final void caseReturnStmt(ReturnStmt rs) {
            if (!(rs.getOp().getType() instanceof RefLikeType))
                return;
            rs.getOp().apply(MethodNodeFactory.this);
            Node retNode = getNode();
            mpag.addInternalEdge(retNode, caseRet());
        }

        @Override
        public final void caseIdentityStmt(IdentityStmt is) {
            if (!(is.getLeftOp().getType() instanceof RefLikeType))
                return;
            Value leftOp = is.getLeftOp();
            Value rightOp = is.getRightOp();
            leftOp.apply(MethodNodeFactory.this);
            Node dest = getNode();
            rightOp.apply(MethodNodeFactory.this);
            Node src = getNode();
            mpag.addInternalEdge(src, dest);
            // in case library mode is activated add allocations to any
            // possible type of this local and
            // parameters of accessible methods
            int libOption = pag.getCGOpts().library();
            if (libOption != CGOptions.library_disabled && (accessibilityOracle.isAccessible(method))) {
                if (rightOp instanceof IdentityRef) {
                    Type rt = rightOp.getType();
                    rt.apply(new SparkLibraryHelper(pag, src, method));
                }
            }
        }

        @Override
        public final void caseThrowStmt(ThrowStmt ts) {
            ts.getOp().apply(MethodNodeFactory.this);
            mpag.addOutEdge(getNode(), pag.nodeFactory().caseThrow());
        }
    });
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) AssignStmt(soot.jimple.AssignStmt) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) SootFieldRef(soot.SootFieldRef) StaticFieldRef(soot.jimple.StaticFieldRef) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) RefLikeType(soot.RefLikeType) RefType(soot.RefType) Type(soot.Type) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) IdentityRef(soot.jimple.IdentityRef) AbstractStmtSwitch(soot.jimple.AbstractStmtSwitch) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) ReturnStmt(soot.jimple.ReturnStmt) ThrowStmt(soot.jimple.ThrowStmt) IdentityStmt(soot.jimple.IdentityStmt) SparkLibraryHelper(soot.jimple.spark.internal.SparkLibraryHelper)

Example 15 with Node

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

the class MethodNodeFactory method caseCastExpr.

@Override
public final void caseCastExpr(CastExpr ce) {
    Pair<Expr, String> castPair = new Pair<Expr, String>(ce, PointsToAnalysis.CAST_NODE);
    ce.getOp().apply(this);
    Node opNode = getNode();
    Node castNode = pag.makeLocalVarNode(castPair, ce.getCastType(), method);
    mpag.addInternalEdge(opNode, castNode);
    setResult(castNode);
}
Also used : NewArrayExpr(soot.jimple.NewArrayExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) PhiExpr(soot.shimple.PhiExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) CastExpr(soot.jimple.CastExpr) InvokeExpr(soot.jimple.InvokeExpr) NewExpr(soot.jimple.NewExpr) Expr(soot.jimple.Expr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Pair(soot.toolkits.scalar.Pair)

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