Search in sources :

Example 1 with GeomPointsTo

use of soot.jimple.spark.geom.geomPA.GeomPointsTo 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 2 with GeomPointsTo

use of soot.jimple.spark.geom.geomPA.GeomPointsTo in project soot by Sable.

the class HeapInsNode method get_all_context_sensitive_objects.

@Override
public void get_all_context_sensitive_objects(long l, long r, PtSensVisitor visitor) {
    if (parent != this) {
        getRepresentative().get_all_context_sensitive_objects(l, r, visitor);
        return;
    }
    GeomPointsTo geomPTA = (GeomPointsTo) Scene.v().getPointsToAnalysis();
    for (Map.Entry<AllocNode, HeapInsIntervalManager> entry : pt_objs.entrySet()) {
        AllocNode obj = entry.getKey();
        HeapInsIntervalManager im = entry.getValue();
        SegmentNode[] int_entry = im.getFigures();
        // We first get the 1-CFA contexts for the object
        SootMethod sm = obj.getMethod();
        int sm_int = 0;
        long n_contexts = 1;
        if (sm != null) {
            sm_int = geomPTA.getIDFromSootMethod(sm);
            n_contexts = geomPTA.context_size[sm_int];
        }
        // We search for all the pointers falling in the range [1, r) that may point to this object
        for (int i = 0; i < HeapInsIntervalManager.Divisions; ++i) {
            SegmentNode p = int_entry[i];
            while (p != null) {
                long R = p.I1 + p.L;
                long objL = -1, objR = -1;
                // Now we compute which context sensitive objects are pointed to by this pointer
                if (i == HeapInsIntervalManager.ALL_TO_MANY) {
                    // all-to-many figures
                    objL = p.I2;
                    objR = p.I2 + p.L;
                } else {
                    // We compute the intersection
                    if (l <= p.I1 && p.I1 < r) {
                        if (i != HeapInsIntervalManager.MANY_TO_ALL) {
                            long d = r - p.I1;
                            if (d > p.L)
                                d = p.L;
                            objL = p.I2;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    } else if (p.I1 <= l && l < R) {
                        if (i != HeapInsIntervalManager.MANY_TO_ALL) {
                            long d = R - l;
                            if (R > r)
                                d = r - l;
                            objL = p.I2 + l - p.I1;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    }
                }
                // Now we test which context versions should this interval [objL, objR) maps to
                if (objL != -1 && objR != -1)
                    visitor.visit(obj, objL, objR, sm_int);
                p = p.next;
            }
        }
    }
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) SootMethod(soot.SootMethod) HashMap(java.util.HashMap) Map(java.util.Map) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode)

Example 3 with GeomPointsTo

use of soot.jimple.spark.geom.geomPA.GeomPointsTo in project soot by Sable.

the class PtInsNode method get_all_context_sensitive_objects.

@Override
public void get_all_context_sensitive_objects(long l, long r, PtSensVisitor visitor) {
    if (parent != this) {
        getRepresentative().get_all_context_sensitive_objects(l, r, visitor);
        return;
    }
    GeomPointsTo geomPTA = (GeomPointsTo) Scene.v().getPointsToAnalysis();
    for (Map.Entry<AllocNode, PtInsIntervalManager> entry : pt_objs.entrySet()) {
        AllocNode obj = entry.getKey();
        PtInsIntervalManager im = entry.getValue();
        SegmentNode[] int_entry = im.getFigures();
        // We first get the 1-CFA contexts for the object
        SootMethod sm = obj.getMethod();
        int sm_int = 0;
        long n_contexts = 1;
        if (sm != null) {
            sm_int = geomPTA.getIDFromSootMethod(sm);
            n_contexts = geomPTA.context_size[sm_int];
        }
        // We search for all the pointers falling in the range [1, r) that may point to this object
        for (int i = 0; i < PtInsIntervalManager.Divisions; ++i) {
            SegmentNode p = int_entry[i];
            while (p != null) {
                long R = p.I1 + p.L;
                long objL = -1, objR = -1;
                // Now we compute which context sensitive objects are pointed to by this pointer
                if (i == PtInsIntervalManager.ALL_TO_MANY) {
                    // all-to-many figures
                    objL = p.I2;
                    objR = p.I2 + p.L;
                } else {
                    // We compute the intersection
                    if (l <= p.I1 && p.I1 < r) {
                        if (i != PtInsIntervalManager.MANY_TO_ALL) {
                            long d = r - p.I1;
                            if (d > p.L)
                                d = p.L;
                            objL = p.I2;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    } else if (p.I1 <= l && l < R) {
                        if (i != PtInsIntervalManager.MANY_TO_ALL) {
                            long d = R - l;
                            if (R > r)
                                d = r - l;
                            objL = p.I2 + l - p.I1;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    }
                }
                // Now we test which context versions should this interval [objL, objR) maps to
                if (objL != -1 && objR != -1)
                    visitor.visit(obj, objL, objR, sm_int);
                p = p.next;
            }
        }
    }
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) SootMethod(soot.SootMethod) HashMap(java.util.HashMap) Map(java.util.Map) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode)

Example 4 with GeomPointsTo

use of soot.jimple.spark.geom.geomPA.GeomPointsTo in project soot by Sable.

the class SparkTransformer method internalTransform.

protected void internalTransform(String phaseName, Map<String, String> options) {
    SparkOptions opts = new SparkOptions(options);
    final String output_dir = SourceLocator.v().getOutputDir();
    // Build pointer assignment graph
    ContextInsensitiveBuilder b = new ContextInsensitiveBuilder();
    if (opts.pre_jimplify())
        b.preJimplify();
    if (opts.force_gc())
        doGC();
    Date startBuild = new Date();
    final PAG pag = b.setup(opts);
    b.build();
    Date endBuild = new Date();
    reportTime("Pointer Assignment Graph", startBuild, endBuild);
    if (opts.force_gc())
        doGC();
    // Build type masks
    Date startTM = new Date();
    pag.getTypeManager().makeTypeMask();
    Date endTM = new Date();
    reportTime("Type masks", startTM, endTM);
    if (opts.force_gc())
        doGC();
    if (opts.verbose()) {
        logger.debug("VarNodes: " + pag.getVarNodeNumberer().size());
        logger.debug("FieldRefNodes: " + pag.getFieldRefNodeNumberer().size());
        logger.debug("AllocNodes: " + pag.getAllocNodeNumberer().size());
    }
    // Simplify pag
    Date startSimplify = new Date();
    // these option interdependencies more cleanly would be nice...
    if ((opts.simplify_sccs() && !opts.on_fly_cg()) || opts.vta()) {
        new SCCCollapser(pag, opts.ignore_types_for_sccs()).collapse();
    }
    if (opts.simplify_offline() && !opts.on_fly_cg()) {
        new EBBCollapser(pag).collapse();
    }
    if (true || opts.simplify_sccs() || opts.vta() || opts.simplify_offline()) {
        pag.cleanUpMerges();
    }
    Date endSimplify = new Date();
    reportTime("Pointer Graph simplified", startSimplify, endSimplify);
    if (opts.force_gc())
        doGC();
    // Dump pag
    PAGDumper dumper = null;
    if (opts.dump_pag() || opts.dump_solution()) {
        dumper = new PAGDumper(pag, output_dir);
    }
    if (opts.dump_pag())
        dumper.dump();
    // Propagate
    Date startProp = new Date();
    propagatePAG(opts, pag);
    Date endProp = new Date();
    reportTime("Propagation", startProp, endProp);
    reportTime("Solution found", startSimplify, endProp);
    if (opts.force_gc())
        doGC();
    if (!opts.on_fly_cg() || opts.vta()) {
        CallGraphBuilder cgb = new CallGraphBuilder(pag);
        cgb.build();
    }
    if (opts.verbose()) {
        logger.debug("[Spark] Number of reachable methods: " + Scene.v().getReachableMethods().size());
    }
    if (opts.set_mass())
        findSetMass(pag);
    if (opts.dump_answer())
        new ReachingTypeDumper(pag, output_dir).dump();
    if (opts.dump_solution())
        dumper.dumpPointsToSets();
    if (opts.dump_html())
        new PAG2HTML(pag, output_dir).dump();
    Scene.v().setPointsToAnalysis(pag);
    if (opts.add_tags()) {
        addTags(pag);
    }
    if (opts.geom_pta()) {
        if (opts.simplify_offline() || opts.simplify_sccs()) {
            logger.debug("" + "Please turn off the simplify-offline and simplify-sccs to run the geometric points-to analysis");
            logger.debug("Now, we keep the SPARK result for querying.");
        } else {
            // We perform the geometric points-to analysis
            GeomPointsTo geomPTA = (GeomPointsTo) pag;
            geomPTA.parametrize(endProp.getTime() - startSimplify.getTime());
            geomPTA.solve();
        }
    }
    if (opts.cs_demand()) {
        // replace by demand-driven refinement-based context-sensitive analysis
        Date startOnDemand = new Date();
        PointsToAnalysis onDemandAnalysis = DemandCSPointsTo.makeWithBudget(opts.traversal(), opts.passes(), opts.lazy_pts());
        Date endOndemand = new Date();
        reportTime("Initialized on-demand refinement-based context-sensitive analysis", startOnDemand, endOndemand);
        Scene.v().setPointsToAnalysis(onDemandAnalysis);
    }
}
Also used : PAGDumper(soot.jimple.spark.pag.PAGDumper) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) EBBCollapser(soot.jimple.spark.solver.EBBCollapser) ContextInsensitiveBuilder(soot.jimple.spark.builder.ContextInsensitiveBuilder) ReachingTypeDumper(soot.jimple.ReachingTypeDumper) Date(java.util.Date) SparkOptions(soot.options.SparkOptions) CallGraphBuilder(soot.jimple.toolkits.callgraph.CallGraphBuilder) PAG(soot.jimple.spark.pag.PAG) PAG2HTML(soot.jimple.spark.pag.PAG2HTML) SCCCollapser(soot.jimple.spark.solver.SCCCollapser) PointsToAnalysis(soot.PointsToAnalysis)

Example 5 with GeomPointsTo

use of soot.jimple.spark.geom.geomPA.GeomPointsTo in project soot by Sable.

the class ContextInsensitiveBuilder method setup.

/**
 * Creates an empty pointer assignment graph.
 */
public PAG setup(SparkOptions opts) {
    pag = opts.geom_pta() ? new GeomPointsTo(opts) : new PAG(opts);
    if (opts.simulate_natives()) {
        pag.nativeMethodDriver = new NativeMethodDriver(new SparkNativeHelper(pag));
    }
    if (opts.on_fly_cg() && !opts.vta()) {
        ofcg = new OnFlyCallGraph(pag, opts.apponly());
        pag.setOnFlyCallGraph(ofcg);
    } else {
        cgb = new CallGraphBuilder(DumbPointerAnalysis.v());
    }
    return pag;
}
Also used : NativeMethodDriver(soot.jimple.toolkits.pointer.util.NativeMethodDriver) OnFlyCallGraph(soot.jimple.spark.solver.OnFlyCallGraph) CallGraphBuilder(soot.jimple.toolkits.callgraph.CallGraphBuilder) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) PAG(soot.jimple.spark.pag.PAG) MethodPAG(soot.jimple.spark.pag.MethodPAG) SparkNativeHelper(soot.jimple.spark.internal.SparkNativeHelper)

Aggregations

GeomPointsTo (soot.jimple.spark.geom.geomPA.GeomPointsTo)8 SegmentNode (soot.jimple.spark.geom.dataRep.SegmentNode)6 AllocNode (soot.jimple.spark.pag.AllocNode)6 RectangleNode (soot.jimple.spark.geom.dataRep.RectangleNode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SootMethod (soot.SootMethod)3 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)3 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)3 Node (soot.jimple.spark.pag.Node)3 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)3 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)3 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)2 PAG (soot.jimple.spark.pag.PAG)2 CallGraphBuilder (soot.jimple.toolkits.callgraph.CallGraphBuilder)2 Date (java.util.Date)1 PointsToAnalysis (soot.PointsToAnalysis)1 ReachingTypeDumper (soot.jimple.ReachingTypeDumper)1 ContextInsensitiveBuilder (soot.jimple.spark.builder.ContextInsensitiveBuilder)1 SparkNativeHelper (soot.jimple.spark.internal.SparkNativeHelper)1