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;
}
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();
}
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;
}
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;
}
Aggregations