Search in sources :

Example 11 with LocalVarNode

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

the class SootUtil method buildStoreMap.

public static FieldAccessMap buildStoreMap(PAG pag) {
    FieldAccessMap ret = new FieldAccessMap();
    Iterator frNodeIter = pag.storeInvSourcesIterator();
    while (frNodeIter.hasNext()) {
        FieldRefNode frNode = (FieldRefNode) frNodeIter.next();
        SparkField field = frNode.getField();
        Node[] targets = pag.storeInvLookup(frNode);
        for (int i = 0; i < targets.length; i++) {
            VarNode target = (VarNode) targets[i];
            if (target instanceof GlobalVarNode)
                continue;
            ret.put(field, new Pair<FieldRefNode, LocalVarNode>(frNode, (LocalVarNode) target));
        }
    }
    return ret;
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) SparkField(soot.jimple.spark.pag.SparkField) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) StringConstantNode(soot.jimple.spark.pag.StringConstantNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Iterator(java.util.Iterator) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Example 12 with LocalVarNode

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

the class GeomPointsTo method getMethodIDFromPtr.

/**
 * Get the index of the enclosing function of the specified node.
 */
public int getMethodIDFromPtr(IVarAbstraction pn) {
    SootMethod sm = null;
    int ret = Constants.SUPER_MAIN;
    Node node = pn.getWrappedNode();
    if (node instanceof AllocNode) {
        sm = ((AllocNode) node).getMethod();
    } else if (node instanceof LocalVarNode) {
        sm = ((LocalVarNode) node).getMethod();
    } else if (node instanceof AllocDotField) {
        sm = ((AllocDotField) node).getBase().getMethod();
    }
    if (sm != null && func2int.containsKey(sm)) {
        int id = func2int.get(sm);
        if (vis_cg[id] == 0)
            ret = Constants.UNKNOWN_FUNCTION;
        else
            ret = id;
    }
    return ret;
}
Also used : AllocDotField(soot.jimple.spark.pag.AllocDotField) AllocNode(soot.jimple.spark.pag.AllocNode) 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) SootMethod(soot.SootMethod) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint)

Example 13 with LocalVarNode

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

the class HeapInsNode method do_before_propagation.

@Override
public void do_before_propagation() {
    // if ( complex_cons == null )
    do_pts_interval_merge();
    // if ( !(me instanceof LocalVarNode) )
    do_flow_edge_interval_merge();
    // This pointer filter, please read the comments at this line in file FullSensitiveNode.java
    Node wrappedNode = getWrappedNode();
    if (wrappedNode instanceof LocalVarNode && ((LocalVarNode) wrappedNode).isThisPtr()) {
        SootMethod func = ((LocalVarNode) wrappedNode).getMethod();
        if (!func.isConstructor()) {
            // We don't process the specialinvoke call edge
            SootClass defClass = func.getDeclaringClass();
            Hierarchy typeHierarchy = Scene.v().getActiveHierarchy();
            for (Iterator<AllocNode> it = new_pts.keySet().iterator(); it.hasNext(); ) {
                AllocNode obj = it.next();
                if (obj.getType() instanceof RefType) {
                    SootClass sc = ((RefType) obj.getType()).getSootClass();
                    if (defClass != sc) {
                        try {
                            SootMethod rt_func = typeHierarchy.resolveConcreteDispatch(sc, func);
                            if (rt_func != func) {
                                it.remove();
                                // Also preclude it from propagation again
                                pt_objs.put(obj, (HeapInsIntervalManager) deadManager);
                            }
                        } catch (RuntimeException e) {
                        // If the input program has a wrong type cast, resolveConcreteDispatch fails and it goes here
                        // We simply ignore this error
                        }
                    }
                }
            }
        }
    }
}
Also used : RefType(soot.RefType) Hierarchy(soot.Hierarchy) AllocNode(soot.jimple.spark.pag.AllocNode) 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) SootMethod(soot.SootMethod) SootClass(soot.SootClass) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Example 14 with LocalVarNode

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

the class EvalResults method checkAliasAnalysis.

/**
 * Count how many aliased base pointers appeared in all user's functions.
 */
public void checkAliasAnalysis() {
    Set<IVarAbstraction> access_expr = new HashSet<IVarAbstraction>();
    ArrayList<IVarAbstraction> al = new ArrayList<IVarAbstraction>();
    Value[] values = new Value[2];
    for (SootMethod sm : ptsProvider.getAllReachableMethods()) {
        if (sm.isJavaLibraryMethod())
            continue;
        if (!sm.isConcrete())
            continue;
        if (!sm.hasActiveBody()) {
            sm.retrieveActiveBody();
        }
        if (!ptsProvider.isValidMethod(sm))
            continue;
        // access_expr.clear();
        for (Iterator<Unit> stmts = sm.getActiveBody().getUnits().iterator(); stmts.hasNext(); ) {
            Stmt st = (Stmt) stmts.next();
            if (st instanceof AssignStmt) {
                AssignStmt a = (AssignStmt) st;
                values[0] = a.getLeftOp();
                values[1] = a.getRightOp();
                for (Value v : values) {
                    // expression: p.f
                    if (v instanceof InstanceFieldRef) {
                        InstanceFieldRef ifr = (InstanceFieldRef) v;
                        final SootField field = ifr.getField();
                        if (!(field.getType() instanceof RefType))
                            continue;
                        LocalVarNode vn = ptsProvider.findLocalVarNode((Local) ifr.getBase());
                        if (vn == null)
                            continue;
                        if (ptsProvider.isExceptionPointer(vn))
                            continue;
                        IVarAbstraction pn = ptsProvider.findInternalNode(vn);
                        if (pn == null)
                            continue;
                        pn = pn.getRepresentative();
                        if (pn.hasPTResult())
                            access_expr.add(pn);
                    }
                }
            }
        }
    }
    access_expr.remove(null);
    al.addAll(access_expr);
    access_expr = null;
    // Next, we pair up all the pointers
    Date begin = new Date();
    int size = al.size();
    for (int i = 0; i < size; ++i) {
        IVarAbstraction pn = al.get(i);
        VarNode n1 = (VarNode) pn.getWrappedNode();
        for (int j = i + 1; j < size; ++j) {
            IVarAbstraction qn = al.get(j);
            VarNode n2 = (VarNode) qn.getWrappedNode();
            if (pn.heap_sensitive_intersection(qn))
                evalRes.n_hs_alias++;
            // We directly use the SPARK points-to sets
            if (n1.getP2Set().hasNonEmptyIntersection(n2.getP2Set()))
                evalRes.n_hi_alias++;
        }
    }
    evalRes.n_alias_pairs = size * (size - 1) / 2;
    Date end = new Date();
    ptsProvider.ps.println();
    ptsProvider.ps.println("--------> Alias Pairs Evaluation <---------");
    ptsProvider.ps.println("Number of pointer pairs in app code: " + evalRes.n_alias_pairs);
    ptsProvider.ps.printf("Heap sensitive alias pairs (by Geom): %d, Percentage = %.3f%%\n", evalRes.n_hs_alias, (double) evalRes.n_hs_alias / evalRes.n_alias_pairs * 100);
    ptsProvider.ps.printf("Heap insensitive alias pairs (by SPARK): %d, Percentage = %.3f%%\n", evalRes.n_hi_alias, (double) evalRes.n_hi_alias / evalRes.n_alias_pairs * 100);
    ptsProvider.ps.printf("Using time: %dms \n", end.getTime() - begin.getTime());
    ptsProvider.ps.println();
}
Also used : LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) AssignStmt(soot.jimple.AssignStmt) ArrayList(java.util.ArrayList) Unit(soot.Unit) Date(java.util.Date) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) RefType(soot.RefType) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) SootMethod(soot.SootMethod) SootField(soot.SootField) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) HashSet(java.util.HashSet)

Example 15 with LocalVarNode

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

the class EvalResults method estimateHeapDefuseGraph.

/**
 * Estimate the size of the def-use graph for the heap memory. The heap
 * graph is estimated without context information.
 */
public void estimateHeapDefuseGraph() {
    final Map<IVarAbstraction, int[]> defUseCounterForGeom = new HashMap<IVarAbstraction, int[]>();
    final Map<AllocDotField, int[]> defUseCounterForSpark = new HashMap<AllocDotField, int[]>();
    Date begin = new Date();
    for (SootMethod sm : ptsProvider.getAllReachableMethods()) {
        if (sm.isJavaLibraryMethod())
            continue;
        if (!sm.isConcrete())
            continue;
        if (!sm.hasActiveBody()) {
            sm.retrieveActiveBody();
        }
        if (!ptsProvider.isValidMethod(sm))
            continue;
        // We first gather all the memory access expressions
        for (Iterator<Unit> stmts = sm.getActiveBody().getUnits().iterator(); stmts.hasNext(); ) {
            Stmt st = (Stmt) stmts.next();
            if (!(st instanceof AssignStmt))
                continue;
            AssignStmt a = (AssignStmt) st;
            final Value lValue = a.getLeftOp();
            final Value rValue = a.getRightOp();
            InstanceFieldRef ifr = null;
            if (lValue instanceof InstanceFieldRef) {
                // Def statement
                ifr = (InstanceFieldRef) lValue;
            } else if (rValue instanceof InstanceFieldRef) {
                // Use statement
                ifr = (InstanceFieldRef) rValue;
            }
            if (ifr != null) {
                final SootField field = ifr.getField();
                LocalVarNode vn = ptsProvider.findLocalVarNode((Local) ifr.getBase());
                if (vn == null)
                    continue;
                IVarAbstraction pn = ptsProvider.findInternalNode(vn);
                if (pn == null)
                    continue;
                pn = pn.getRepresentative();
                if (!pn.hasPTResult())
                    continue;
                // Spark
                vn.getP2Set().forall(new P2SetVisitor() {

                    @Override
                    public void visit(Node n) {
                        IVarAbstraction padf = ptsProvider.findAndInsertInstanceField((AllocNode) n, field);
                        AllocDotField adf = (AllocDotField) padf.getWrappedNode();
                        int[] defUseUnit = defUseCounterForSpark.get(adf);
                        if (defUseUnit == null) {
                            defUseUnit = new int[2];
                            defUseCounterForSpark.put(adf, defUseUnit);
                        }
                        if (lValue instanceof InstanceFieldRef) {
                            defUseUnit[0]++;
                        } else {
                            defUseUnit[1]++;
                        }
                    }
                });
                // Geom
                Set<AllocNode> objsSet = pn.get_all_points_to_objects();
                for (AllocNode obj : objsSet) {
                    /*
						 * We will create a lot of instance fields. Because in
						 * points-to analysis, we concern only the reference
						 * type fields. But here, we concern all the fields read
						 * write including the primitive type fields.
						 */
                    IVarAbstraction padf = ptsProvider.findAndInsertInstanceField(obj, field);
                    int[] defUseUnit = defUseCounterForGeom.get(padf);
                    if (defUseUnit == null) {
                        defUseUnit = new int[2];
                        defUseCounterForGeom.put(padf, defUseUnit);
                    }
                    if (lValue instanceof InstanceFieldRef) {
                        defUseUnit[0]++;
                    } else {
                        defUseUnit[1]++;
                    }
                }
            }
        }
    }
    for (int[] defUseUnit : defUseCounterForSpark.values()) {
        evalRes.n_spark_du_pairs += ((long) defUseUnit[0]) * defUseUnit[1];
    }
    for (int[] defUseUnit : defUseCounterForGeom.values()) {
        evalRes.n_geom_du_pairs += ((long) defUseUnit[0]) * defUseUnit[1];
    }
    Date end = new Date();
    ptsProvider.ps.println();
    ptsProvider.ps.println("-----------> Heap Def Use Graph Evaluation <------------");
    ptsProvider.ps.println("The edges in the heap def-use graph is (by Geom): " + evalRes.n_geom_du_pairs);
    ptsProvider.ps.println("The edges in the heap def-use graph is (by Spark): " + evalRes.n_spark_du_pairs);
    ptsProvider.ps.printf("Using time: %dms \n", end.getTime() - begin.getTime());
    ptsProvider.ps.println();
}
Also used : AllocDotField(soot.jimple.spark.pag.AllocDotField) HashMap(java.util.HashMap) AssignStmt(soot.jimple.AssignStmt) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Unit(soot.Unit) Date(java.util.Date) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) AllocNode(soot.jimple.spark.pag.AllocNode) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) SootMethod(soot.SootMethod) SootField(soot.SootField) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Aggregations

LocalVarNode (soot.jimple.spark.pag.LocalVarNode)22 SootMethod (soot.SootMethod)16 AllocNode (soot.jimple.spark.pag.AllocNode)15 Node (soot.jimple.spark.pag.Node)13 VarNode (soot.jimple.spark.pag.VarNode)11 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)8 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)6 RefType (soot.RefType)5 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)5 SootClass (soot.SootClass)4 CgEdge (soot.jimple.spark.geom.dataRep.CgEdge)4 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)4 AssignEdge (soot.jimple.spark.ondemand.pautil.AssignEdge)4 ContextVarNode (soot.jimple.spark.pag.ContextVarNode)4 SparkField (soot.jimple.spark.pag.SparkField)4 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)4 HashSet (java.util.HashSet)3 Hierarchy (soot.Hierarchy)3 Unit (soot.Unit)3 AssignStmt (soot.jimple.AssignStmt)3