Search in sources :

Example 16 with VarNode

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

the class SparkTransformer method findSetMass.

protected void findSetMass(PAG pag) {
    int mass = 0;
    int varMass = 0;
    int adfs = 0;
    int scalars = 0;
    for (final VarNode v : pag.getVarNodeNumberer()) {
        scalars++;
        PointsToSetInternal set = v.getP2Set();
        if (set != null)
            mass += set.size();
        if (set != null)
            varMass += set.size();
    }
    for (final AllocNode an : pag.allocSources()) {
        for (final AllocDotField adf : an.getFields()) {
            PointsToSetInternal set = adf.getP2Set();
            if (set != null)
                mass += set.size();
            if (set != null && set.size() > 0) {
                adfs++;
            }
        }
    }
    logger.debug("Set mass: " + mass);
    logger.debug("Variable mass: " + varMass);
    logger.debug("Scalars: " + scalars);
    logger.debug("adfs: " + adfs);
    // Compute points-to set sizes of dereference sites BEFORE
    // trimming sets by declared type
    int[] deRefCounts = new int[30001];
    for (VarNode v : pag.getDereferences()) {
        PointsToSetInternal set = v.getP2Set();
        int size = 0;
        if (set != null)
            size = set.size();
        deRefCounts[size]++;
    }
    int total = 0;
    for (int element : deRefCounts) total += element;
    logger.debug("Dereference counts BEFORE trimming (total = " + total + "):");
    for (int i = 0; i < deRefCounts.length; i++) {
        if (deRefCounts[i] > 0) {
            logger.debug("" + i + " " + deRefCounts[i] + " " + (deRefCounts[i] * 100.0 / total) + "%");
        }
    }
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) AllocDotField(soot.jimple.spark.pag.AllocDotField) AllocNode(soot.jimple.spark.pag.AllocNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal)

Example 17 with VarNode

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

the class GeomQueries method isAlias.

/**
 * Test if two pointers given in geomPTA form are an alias under any contexts.
 * @param pn1 and @param pn2 cannot be null.
 */
public boolean isAlias(IVarAbstraction pn1, IVarAbstraction pn2) {
    pn1 = pn1.getRepresentative();
    pn2 = pn2.getRepresentative();
    if (!pn1.hasPTResult() || !pn2.hasPTResult()) {
        VarNode vn1 = (VarNode) pn1.getWrappedNode();
        VarNode vn2 = (VarNode) pn2.getWrappedNode();
        return isAliasCI((Local) vn1.getVariable(), (Local) vn2.getVariable());
    }
    return pn1.heap_sensitive_intersection(pn2);
}
Also used : LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode)

Example 18 with VarNode

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

the class MergeChecker method check.

/**
 * Actually does the propagation.
 */
public void check() {
    for (Object object : pag.allocSources()) {
        handleAllocNode((AllocNode) object);
    }
    for (Object object : pag.simpleSources()) {
        handleSimples((VarNode) object);
    }
    for (Object object : pag.loadSources()) {
        handleLoads((FieldRefNode) object);
    }
    for (Object object : pag.storeSources()) {
        handleStores((VarNode) object);
    }
    for (Object object : pag.loadSources()) {
        final FieldRefNode fr = (FieldRefNode) object;
        fieldToBase.put(fr.getField(), fr.getBase());
    }
    for (Object object : pag.storeInvSources()) {
        final FieldRefNode fr = (FieldRefNode) object;
        fieldToBase.put(fr.getField(), fr.getBase());
    }
    for (final VarNode src : pag.getVarNodeNumberer()) {
        for (FieldRefNode fr : src.getAllFieldRefs()) {
            for (VarNode dst : fieldToBase.get(fr.getField())) {
                if (!src.getP2Set().hasNonEmptyIntersection(dst.getP2Set()))
                    continue;
                FieldRefNode fr2 = dst.dot(fr.getField());
                if (fr2.getReplacement() != fr.getReplacement()) {
                    logger.debug("Check failure: " + fr + " should be merged with " + fr2);
                }
            }
        }
    }
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode)

Example 19 with VarNode

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

the class PropAlias method handleVarNode.

/**
 * Propagates new points-to information of node src to all its successors.
 */
protected final boolean handleVarNode(final VarNode src) {
    boolean ret = false;
    if (src.getReplacement() != src)
        throw new RuntimeException("Got bad node " + src + " with rep " + src.getReplacement());
    final PointsToSetInternal newP2Set = src.getP2Set().getNewSet();
    if (newP2Set.isEmpty())
        return false;
    if (ofcg != null) {
        QueueReader<Node> addedEdges = pag.edgeReader();
        ofcg.updatedNode(src);
        ofcg.build();
        while (addedEdges.hasNext()) {
            Node addedSrc = (Node) addedEdges.next();
            Node addedTgt = (Node) addedEdges.next();
            ret = true;
            if (addedSrc instanceof VarNode) {
                VarNode edgeSrc = (VarNode) addedSrc;
                if (addedTgt instanceof VarNode) {
                    VarNode edgeTgt = (VarNode) addedTgt;
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null))
                        addToWorklist(edgeTgt);
                } else if (addedTgt instanceof NewInstanceNode) {
                    NewInstanceNode edgeTgt = (NewInstanceNode) addedTgt.getReplacement();
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
                        for (Node element : pag.assignInstanceLookup(edgeTgt)) {
                            addToWorklist((VarNode) element);
                        }
                    }
                }
            } else if (addedSrc instanceof AllocNode) {
                AllocNode edgeSrc = (AllocNode) addedSrc;
                VarNode edgeTgt = (VarNode) addedTgt;
                if (edgeTgt.makeP2Set().add(edgeSrc))
                    addToWorklist(edgeTgt);
            } else if (addedSrc instanceof NewInstanceNode && addedTgt instanceof VarNode) {
                final NewInstanceNode edgeSrc = (NewInstanceNode) addedSrc.getReplacement();
                final VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
                addedSrc.getP2Set().forall(new P2SetVisitor() {

                    @Override
                    public void visit(Node n) {
                        if (n instanceof ClassConstantNode) {
                            ClassConstantNode ccn = (ClassConstantNode) n;
                            Type ccnType = ccn.getClassConstant().toSootType();
                            // If the referenced class has not been loaded,
                            // we do this now
                            SootClass targetClass = ((RefType) ccnType).getSootClass();
                            if (targetClass.resolvingLevel() == SootClass.DANGLING)
                                Scene.v().forceResolve(targetClass.getName(), SootClass.SIGNATURES);
                            edgeTgt.makeP2Set().add(pag.makeAllocNode(edgeSrc.getValue(), ccnType, ccn.getMethod()));
                            addToWorklist(edgeTgt);
                        }
                    }
                });
            }
            FieldRefNode frn = null;
            if (addedSrc instanceof FieldRefNode)
                frn = (FieldRefNode) addedSrc;
            if (addedTgt instanceof FieldRefNode)
                frn = (FieldRefNode) addedTgt;
            if (frn != null) {
                VarNode base = frn.getBase();
                if (fieldToBase.put(frn.getField(), base)) {
                    aliasWorkList.add(base);
                }
            }
        }
    }
    Node[] simpleTargets = pag.simpleLookup(src);
    for (Node element : simpleTargets) {
        if (element.makeP2Set().addAll(newP2Set, null)) {
            addToWorklist((VarNode) element);
            ret = true;
        }
    }
    Node[] storeTargets = pag.storeLookup(src);
    for (Node element : storeTargets) {
        final FieldRefNode fr = (FieldRefNode) element;
        if (fr.makeP2Set().addAll(newP2Set, null)) {
            fieldRefWorkList.add(fr);
            ret = true;
        }
    }
    src.getP2Set().flushNew();
    return ret;
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) SootClass(soot.SootClass) RefType(soot.RefType) Type(soot.Type) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 20 with VarNode

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

the class PropAlias method propagate.

/**
 * Actually does the propagation.
 */
public final void propagate() {
    ofcg = pag.getOnFlyCallGraph();
    new TopoSorter(pag, false).sort();
    for (Object object : pag.loadSources()) {
        final FieldRefNode fr = (FieldRefNode) object;
        fieldToBase.put(fr.getField(), fr.getBase());
    }
    for (Object object : pag.storeInvSources()) {
        final FieldRefNode fr = (FieldRefNode) object;
        fieldToBase.put(fr.getField(), fr.getBase());
    }
    for (Object object : pag.allocSources()) {
        handleAllocNode((AllocNode) object);
    }
    boolean verbose = pag.getOpts().verbose();
    do {
        if (verbose) {
            logger.debug("Worklist has " + varNodeWorkList.size() + " nodes.");
        }
        aliasWorkList = new HashSet<VarNode>();
        while (!varNodeWorkList.isEmpty()) {
            VarNode src = varNodeWorkList.iterator().next();
            varNodeWorkList.remove(src);
            aliasWorkList.add(src);
            handleVarNode(src);
        }
        if (verbose) {
            logger.debug("Now handling field references");
        }
        for (VarNode src : aliasWorkList) {
            for (FieldRefNode srcFr : src.getAllFieldRefs()) {
                SparkField field = srcFr.getField();
                for (VarNode dst : fieldToBase.get(field)) {
                    if (src.getP2Set().hasNonEmptyIntersection(dst.getP2Set())) {
                        FieldRefNode dstFr = dst.dot(field);
                        aliasEdges.put(srcFr, dstFr);
                        aliasEdges.put(dstFr, srcFr);
                        fieldRefWorkList.add(srcFr);
                        fieldRefWorkList.add(dstFr);
                        if (makeP2Set(dstFr).addAll(srcFr.getP2Set().getOldSet(), null)) {
                            outFieldRefWorkList.add(dstFr);
                        }
                        if (makeP2Set(srcFr).addAll(dstFr.getP2Set().getOldSet(), null)) {
                            outFieldRefWorkList.add(srcFr);
                        }
                    }
                }
            }
        }
        for (FieldRefNode src : fieldRefWorkList) {
            for (FieldRefNode dst : aliasEdges.get(src)) {
                if (makeP2Set(dst).addAll(src.getP2Set().getNewSet(), null)) {
                    outFieldRefWorkList.add(dst);
                }
            }
            src.getP2Set().flushNew();
        }
        fieldRefWorkList = new HashSet<FieldRefNode>();
        for (FieldRefNode src : outFieldRefWorkList) {
            PointsToSetInternal set = getP2Set(src).getNewSet();
            if (set.isEmpty())
                continue;
            Node[] targets = pag.loadLookup(src);
            for (Node element0 : targets) {
                VarNode target = (VarNode) element0;
                if (target.makeP2Set().addAll(set, null)) {
                    addToWorklist(target);
                }
            }
            getP2Set(src).flushNew();
        }
        outFieldRefWorkList = new HashSet<FieldRefNode>();
    } while (!varNodeWorkList.isEmpty());
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) SparkField(soot.jimple.spark.pag.SparkField) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode)

Aggregations

VarNode (soot.jimple.spark.pag.VarNode)47 AllocNode (soot.jimple.spark.pag.AllocNode)37 Node (soot.jimple.spark.pag.Node)29 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)24 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)23 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)22 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)17 SparkField (soot.jimple.spark.pag.SparkField)15 HashSet (java.util.HashSet)11 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)11 SootMethod (soot.SootMethod)10 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)10 RefType (soot.RefType)8 Type (soot.Type)8 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)8 AssignEdge (soot.jimple.spark.ondemand.pautil.AssignEdge)7 Iterator (java.util.Iterator)6 ImmutableStack (soot.jimple.spark.ondemand.genericutil.ImmutableStack)6 Stack (soot.jimple.spark.ondemand.genericutil.Stack)6 AllocDotField (soot.jimple.spark.pag.AllocDotField)6