Search in sources :

Example 21 with BitVector

use of soot.util.BitVector in project soot by Sable.

the class TypeManager method makeClassTypeMask.

private final BitVector makeClassTypeMask(SootClass clazz) {
    {
        BitVector cachedMask = typeMask.get(clazz.getType());
        if (cachedMask != null) {
            return cachedMask;
        }
    }
    int nBits = pag.getAllocNodeNumberer().size();
    final BitVector mask = new BitVector(nBits);
    List<AllocNode> allocs = null;
    if (clazz.isConcrete()) {
        allocs = class2allocs.get(clazz);
    }
    if (allocs != null) {
        for (AllocNode an : allocs) {
            mask.set(an.getNumber());
        }
    }
    Collection<SootClass> subclasses = fh.getSubclassesOf(clazz);
    if (subclasses == Collections.EMPTY_LIST) {
        for (AllocNode an : anySubtypeAllocs) {
            mask.set(an.getNumber());
        }
        typeMask.put(clazz.getType(), mask);
        return mask;
    }
    for (SootClass subcl : subclasses) {
        mask.or(makeClassTypeMask(subcl));
    }
    typeMask.put(clazz.getType(), mask);
    return mask;
}
Also used : BitVector(soot.util.BitVector) AllocNode(soot.jimple.spark.pag.AllocNode) SootClass(soot.SootClass)

Example 22 with BitVector

use of soot.util.BitVector in project soot by Sable.

the class TypeManager method makeTypeMask.

public final void makeTypeMask() {
    RefType.v("java.lang.Class");
    typeMask = new LargeNumberedMap<Type, BitVector>(Scene.v().getTypeNumberer());
    if (fh == null)
        return;
    int numTypes = Scene.v().getTypeNumberer().size();
    if (pag.getOpts().verbose())
        logger.debug("" + "Total types: " + numTypes);
    // **
    initClass2allocs();
    makeClassTypeMask(Scene.v().getSootClass("java.lang.Object"));
    BitVector visitedTypes = new BitVector();
    {
        Iterator<Type> it = typeMask.keyIterator();
        while (it.hasNext()) {
            Type t = it.next();
            visitedTypes.set(t.getNumber());
        }
    }
    // **
    ArrayNumberer<AllocNode> allocNodes = pag.getAllocNodeNumberer();
    for (Type t : Scene.v().getTypeNumberer()) {
        if (!(t instanceof RefLikeType))
            continue;
        if (t instanceof AnySubType)
            continue;
        if (isUnresolved(t))
            continue;
        // **
        if (t instanceof RefType && !t.equals(RefType.v("java.lang.Object")) && !t.equals(RefType.v("java.io.Serializable")) && !t.equals(RefType.v("java.lang.Cloneable"))) {
            SootClass sc = ((RefType) t).getSootClass();
            if (sc.isInterface()) {
                makeMaskOfInterface(sc);
            }
            if (!visitedTypes.get(t.getNumber()) && !((RefType) t).getSootClass().isPhantom()) {
                makeClassTypeMask(((RefType) t).getSootClass());
            }
            continue;
        }
        // **
        BitVector mask = new BitVector(allocNodes.size());
        for (Node n : allocNodes) {
            if (castNeverFails(n.getType(), t)) {
                mask.set(n.getNumber());
            }
        }
        typeMask.put(t, mask);
    }
    allocNodeListener = pag.allocNodeListener();
}
Also used : RefLikeType(soot.RefLikeType) RefType(soot.RefType) BitVector(soot.util.BitVector) RefType(soot.RefType) AnySubType(soot.AnySubType) NullType(soot.NullType) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) Iterator(java.util.Iterator) AnySubType(soot.AnySubType) SootClass(soot.SootClass)

Example 23 with BitVector

use of soot.util.BitVector in project soot by Sable.

the class TypeManager method get.

public final BitVector get(Type type) {
    if (type == null)
        return null;
    while (allocNodeListener.hasNext()) {
        AllocNode n = allocNodeListener.next();
        for (final Type t : Scene.v().getTypeNumberer()) {
            if (!(t instanceof RefLikeType))
                continue;
            if (t instanceof AnySubType)
                continue;
            if (isUnresolved(t))
                continue;
            if (castNeverFails(n.getType(), t)) {
                BitVector mask = typeMask.get(t);
                if (mask == null) {
                    typeMask.put(t, mask = new BitVector());
                    for (final AllocNode an : pag.getAllocNodeNumberer()) {
                        if (castNeverFails(an.getType(), t)) {
                            mask.set(an.getNumber());
                        }
                    }
                    continue;
                }
                mask.set(n.getNumber());
            }
        }
    }
    BitVector ret = (BitVector) typeMask.get(type);
    if (ret == null && fh != null) {
        // If we have a phantom class and have no type mask, we assume that
        // it is not cast-compatible to anything
        SootClass curClass = ((RefType) type).getSootClass();
        if (type instanceof RefType && curClass.isPhantom())
            return new BitVector();
        else {
            // Scan through the hierarchy. We might have a phantom class higher up
            while (curClass.hasSuperclass()) {
                curClass = curClass.getSuperclass();
                if (type instanceof RefType && curClass.isPhantom())
                    return new BitVector();
            }
            throw new RuntimeException("Type mask not found for type " + type);
        }
    }
    return ret;
}
Also used : RefLikeType(soot.RefLikeType) RefType(soot.RefType) BitVector(soot.util.BitVector) RefType(soot.RefType) AnySubType(soot.AnySubType) NullType(soot.NullType) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) AnySubType(soot.AnySubType) SootClass(soot.SootClass)

Example 24 with BitVector

use of soot.util.BitVector in project soot by Sable.

the class HybridPointsToSet method nativeAddAll.

private boolean nativeAddAll(HybridPointsToSet other, HybridPointsToSet exclude) {
    boolean ret = false;
    TypeManager typeManager = pag.getTypeManager();
    if (other.bits != null) {
        convertToBits();
        if (exclude != null) {
            exclude.convertToBits();
        }
        BitVector mask = null;
        if (!typeManager.castNeverFails(other.getType(), this.getType())) {
            mask = typeManager.get(this.getType());
        }
        BitVector ebits = (exclude == null ? null : exclude.bits);
        ret = bits.orAndAndNot(other.bits, mask, ebits);
    } else {
        for (int i = 0; i < nodes.length; i++) {
            if (other.nodes[i] == null)
                break;
            if (exclude == null || !exclude.contains(other.nodes[i])) {
                ret = add(other.nodes[i]) | ret;
            }
        }
    }
    if (ret)
        empty = false;
    return ret;
}
Also used : BitVector(soot.util.BitVector) TypeManager(soot.jimple.spark.internal.TypeManager)

Aggregations

BitVector (soot.util.BitVector)24 SootClass (soot.SootClass)4 AllocNode (soot.jimple.spark.pag.AllocNode)4 BitSetIterator (soot.util.BitSetIterator)4 Node (soot.jimple.spark.pag.Node)3 AnySubType (soot.AnySubType)2 ArrayType (soot.ArrayType)2 NullType (soot.NullType)2 RefLikeType (soot.RefLikeType)2 RefType (soot.RefType)2 Type (soot.Type)2 TypeManager (soot.jimple.spark.internal.TypeManager)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 LongType (soot.LongType)1