Search in sources :

Example 6 with PointsToSet

use of soot.PointsToSet in project soot by Sable.

the class PointsToAnalysis method printFieldIntersects.

private static void printFieldIntersects(Map ls, SootField f) {
    soot.PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
    Iterator i1 = ls.entrySet().iterator();
    while (i1.hasNext()) {
        Map.Entry e1 = (Map.Entry) i1.next();
        int p1 = ((Integer) e1.getKey()).intValue();
        Local l1 = (Local) e1.getValue();
        PointsToSet r1 = pta.reachingObjects(l1, f);
        Iterator i2 = ls.entrySet().iterator();
        while (i2.hasNext()) {
            Map.Entry e2 = (Map.Entry) i2.next();
            int p2 = ((Integer) e2.getKey()).intValue();
            Local l2 = (Local) e2.getValue();
            PointsToSet r2 = pta.reachingObjects(l2, f);
            if (p1 <= p2)
                System.out.println("[" + p1 + "," + p2 + "]\t Container.item intersect? " + r1.hasNonEmptyIntersection(r2));
        }
    }
}
Also used : PointsToSet(soot.PointsToSet) Iterator(java.util.Iterator) Local(soot.Local) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with PointsToSet

use of soot.PointsToSet in project soot by Sable.

the class CodeBlockRWSet method addFieldRef.

public boolean addFieldRef(PointsToSet otherBase, Object field) {
    boolean ret = false;
    if (fields == null)
        fields = new HashMap();
    // Get our points-to set, merge with other
    PointsToSet base = getBaseForField(field);
    if (base instanceof FullObjectSet)
        return false;
    if (otherBase instanceof FullObjectSet) {
        fields.put(field, otherBase);
        return true;
    }
    if (otherBase.equals(base))
        return false;
    if (base == null) {
        // NOTE: this line makes unsafe assumptions about the PTA
        PointsToSetInternal newpti = new HashPointsToSet(((PointsToSetInternal) otherBase).getType(), (PAG) Scene.v().getPointsToAnalysis());
        base = newpti;
        fields.put(field, base);
    }
    ret = ((PointsToSetInternal) base).addAll((PointsToSetInternal) otherBase, null) | ret;
    return ret;
}
Also used : PointsToSet(soot.PointsToSet)

Example 8 with PointsToSet

use of soot.PointsToSet in project soot by Sable.

the class CodeBlockRWSet method intersection.

public CodeBlockRWSet intersection(MethodRWSet other) {
    // May run slowly... O(n^2)
    CodeBlockRWSet ret = new CodeBlockRWSet();
    if (isFull)
        return ret;
    if (globals != null && other.globals != null && !globals.isEmpty() && !other.globals.isEmpty()) {
        for (Iterator it = other.globals.iterator(); it.hasNext(); ) {
            SootField sg = (SootField) it.next();
            if (globals.contains(sg))
                ret.addGlobal(sg);
        }
    }
    if (fields != null && other.fields != null && !fields.isEmpty() && !other.fields.isEmpty()) {
        for (Object element : other.fields.keySet()) {
            final Object field = element;
            if (fields.containsKey(field)) {
                PointsToSet pts1 = getBaseForField(field);
                PointsToSet pts2 = other.getBaseForField(field);
                if (pts1 instanceof FullObjectSet)
                    ret.addFieldRef(pts2, field);
                else if (pts2 instanceof FullObjectSet)
                    ret.addFieldRef(pts1, field);
                else if (pts1.hasNonEmptyIntersection(pts2)) {
                    if ((pts1 instanceof PointsToSetInternal) && (pts2 instanceof PointsToSetInternal)) {
                        final PointsToSetInternal pti1 = (PointsToSetInternal) pts1;
                        final PointsToSetInternal pti2 = (PointsToSetInternal) pts2;
                        final PointsToSetInternal newpti = new HashPointsToSet(pti1.getType(), (PAG) Scene.v().getPointsToAnalysis());
                        pti1.forall(new P2SetVisitor() {

                            public void visit(Node n) {
                                if (pti2.contains(n))
                                    newpti.add(n);
                            }
                        });
                        ret.addFieldRef(newpti, field);
                    }
                }
            }
        }
    }
    return ret;
}
Also used : PointsToSet(soot.PointsToSet) SootField(soot.SootField)

Example 9 with PointsToSet

use of soot.PointsToSet in project soot by Sable.

the class CodeBlockRWSet method union.

/**
 * Adds the RWSet other into this set.
 */
public boolean union(RWSet other) {
    if (other == null)
        return false;
    if (isFull)
        return false;
    boolean ret = false;
    if (other instanceof MethodRWSet) {
        MethodRWSet o = (MethodRWSet) other;
        if (o.getCallsNative()) {
            ret = !getCallsNative() | ret;
            setCallsNative();
        }
        if (o.isFull) {
            ret = !isFull | ret;
            isFull = true;
            if (true)
                throw new RuntimeException("attempt to add full set " + o + " into " + this);
            globals = null;
            fields = null;
            return ret;
        }
        if (o.globals != null) {
            if (globals == null)
                globals = new HashSet();
            ret = globals.addAll(o.globals) | ret;
            if (globals.size() > MAX_SIZE) {
                globals = null;
                isFull = true;
                throw new RuntimeException("attempt to add full set " + o + " into " + this);
            }
        }
        if (o.fields != null) {
            for (Object element : o.fields.keySet()) {
                final Object field = element;
                PointsToSet os = o.getBaseForField(field);
                ret = addFieldRef(os, field) | ret;
            }
        }
    } else if (other instanceof StmtRWSet) {
        StmtRWSet oth = (StmtRWSet) other;
        if (oth.base != null) {
            ret = addFieldRef(oth.base, oth.field) | ret;
        } else if (oth.field != null) {
            ret = addGlobal((SootField) oth.field) | ret;
        }
    } else if (other instanceof SiteRWSet) {
        SiteRWSet oth = (SiteRWSet) other;
        for (RWSet set : oth.sets) {
            this.union(set);
        }
    }
    if (!getCallsNative() && other.getCallsNative()) {
        setCallsNative();
        return true;
    }
    return ret;
}
Also used : PointsToSet(soot.PointsToSet)

Example 10 with PointsToSet

use of soot.PointsToSet in project soot by Sable.

the class MethodRWSet method addFieldRef.

public boolean addFieldRef(PointsToSet otherBase, Object field) {
    boolean ret = false;
    if (fields == null)
        fields = new HashMap();
    PointsToSet base = getBaseForField(field);
    if (base instanceof FullObjectSet)
        return false;
    if (otherBase instanceof FullObjectSet) {
        fields.put(field, otherBase);
        return true;
    }
    if (otherBase.equals(base))
        return false;
    Union u;
    if (base == null || !(base instanceof Union)) {
        u = G.v().Union_factory.newUnion();
        if (base != null)
            u.addAll(base);
        fields.put(field, u);
        if (base == null)
            addedField(fields.size());
        ret = true;
        if (fields.keySet().size() > MAX_SIZE) {
            fields = null;
            isFull = true;
            if (true)
                throw new RuntimeException("attempt to add more than " + MAX_SIZE + " fields into " + this);
            return true;
        }
    } else {
        u = (Union) base;
    }
    ret = u.addAll(otherBase) | ret;
    return ret;
}
Also used : PointsToSet(soot.PointsToSet) HashMap(java.util.HashMap)

Aggregations

PointsToSet (soot.PointsToSet)17 Local (soot.Local)5 EqualsSupportingPointsToSet (soot.jimple.spark.sets.EqualsSupportingPointsToSet)5 EmptyPointsToSet (soot.jimple.spark.sets.EmptyPointsToSet)4 HybridPointsToSet (soot.jimple.spark.sets.HybridPointsToSet)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)2 SootField (soot.SootField)2 Type (soot.Type)2 Value (soot.Value)2 ArrayRef (soot.jimple.ArrayRef)2 InstanceFieldRef (soot.jimple.InstanceFieldRef)2 FlowFunction (heros.FlowFunction)1 FlowFunctions (heros.FlowFunctions)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1