public void setInterference(Local l1, Local l2) { // We need the mapping in both directions // l1 -> l2 Set<Local> locals = localToLocals.get(l1); if (locals == null) { locals = new ArraySet<Local>(); localToLocals.put(l1, locals); } locals.add(l2); // l2 -> l1 locals = localToLocals.get(l2); if (locals == null) { locals = new ArraySet<Local>(); localToLocals.put(l2, locals); } locals.add(l1); }
@SuppressWarnings("unchecked") final public boolean addAll(Collection<? extends E> s) { boolean ret = false; if (!(s instanceof ArraySet)) { return super.addAll(s); } ArraySet<?> as = (ArraySet<?>) s; int asSize = as.size(); Object[] asElements = as.elements; for (int i = 0; i < asSize; i++) { ret = add((E) asElements[i]) | ret; } return ret; }
/** Returns a list of implementers of c, excluding itself. */ public List<SootClass> getImplementersOf(SootClass i) { i.checkLevel(SootClass.HIERARCHY); if (!i.isInterface()) { throw new RuntimeException("interface needed; got " + i); } checkState(); ArraySet<SootClass> set = new ArraySet<SootClass>(); for (SootClass c : getSubinterfacesOfIncluding(i)) { set.addAll(getDirectImplementersOf(c)); } ArrayList<SootClass> l = new ArrayList<SootClass>(); l.addAll(set); return Collections.unmodifiableList(l); }
final public boolean add(E e) { if (e == null) { throw new RuntimeException("oops"); } if (contains(e)) { return false; } else { // Expand array if necessary if (numElements == maxElements) { doubleCapacity(); } // Add element elements[numElements++] = e; return true; } }
/** Given a set of definite receiver types, returns a list of possible targets. */ public List resolveConcreteDispatch(List classes, SootMethod m) { m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); ArraySet s = new ArraySet(); Iterator classesIt = classes.iterator(); while (classesIt.hasNext()) { Object cls = classesIt.next(); if (cls instanceof RefType) s.add(resolveConcreteDispatch(((RefType)cls).getSootClass(), m)); else if (cls instanceof ArrayType) { s.add(resolveConcreteDispatch((RefType.v("java.lang.Object")).getSootClass(), m)); } else throw new RuntimeException("Unable to resolve concrete dispatch of type "+ cls); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
/** * Create a set which contains the given elements. */ public ArraySet(E[] elements) { this(); for (E element : elements) { add(element); } }
/** * Add an element without checking whether it is already in the set. It is up to the caller to guarantee that it isn't. */ final public boolean addElement(E e) { if (e == null) { throw new RuntimeException("oops"); } // Expand array if necessary if (numElements == maxElements) { doubleCapacity(); } // Add element elements[numElements++] = e; return true; }
private class ArrayIterator<V> implements Iterator<V> { int nextIndex; ArrayIterator() { nextIndex = 0; } final public boolean hasNext() { return nextIndex < numElements; } @SuppressWarnings("unchecked") final public V next() throws NoSuchElementException { if (!(nextIndex < numElements)) { throw new NoSuchElementException(); } return (V) elements[nextIndex++]; } final public void remove() throws NoSuchElementException { if (nextIndex == 0) { throw new NoSuchElementException(); } else { removeElementAt(nextIndex - 1); nextIndex = nextIndex - 1; } } }
public boolean localsInterfere(Local l1, Local l2) { return localToLocals.get(l1).contains(l2); }
Local[] getInterferencesOf(Local l) { Object[] objects = localToLocals.get(l).toArray(); Local[] locals = new Local[objects.length]; for(int i = 0; i < objects.length; i++) locals[i] = (Local) objects[i]; return locals; } }
/** Given a set of definite receiver types, returns a list of possible targets. */ public List resolveConcreteDispatch(List classes, SootMethod m) { m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); ArraySet s = new ArraySet(); Iterator classesIt = classes.iterator(); while (classesIt.hasNext()) { Object cls = classesIt.next(); if (cls instanceof RefType) s.add(resolveConcreteDispatch(((RefType)cls).getSootClass(), m)); else if (cls instanceof ArrayType) { s.add(resolveConcreteDispatch((RefType.v("java.lang.Object")).getSootClass(), m)); } else throw new RuntimeException("Unable to resolve concrete dispatch of type "+ cls); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
final public boolean add(E e) { if(e==null) throw new RuntimeException( "oops" ); if(contains(e)) return false; else { // Expand array if necessary if(numElements == maxElements) doubleCapacity(); // Add element elements[numElements++] = e; return true; } }
/** * Create a set which contains the given elements. */ public ArraySet(E[] elements) { this(); for (E element : elements) add(element); }
/** Add an element without checking whether it is already in the set. * It is up to the caller to guarantee that it isn't. */ final public boolean addElement(E e) { if(e==null) throw new RuntimeException( "oops" ); // Expand array if necessary if(numElements == maxElements) doubleCapacity(); // Add element elements[numElements++] = e; return true; }
private class ArrayIterator<V> implements Iterator<V> { int nextIndex; ArrayIterator() { nextIndex = 0; } final public boolean hasNext() { return nextIndex < numElements; } @SuppressWarnings("unchecked") final public V next() throws NoSuchElementException { if(!(nextIndex < numElements)) throw new NoSuchElementException(); return (V) elements[nextIndex++]; } final public void remove() throws NoSuchElementException { if(nextIndex == 0) throw new NoSuchElementException(); else { removeElementAt(nextIndex - 1); nextIndex = nextIndex - 1; } } }
public boolean localsInterfere(Local l1, Local l2) { return localToLocals.get(l1).contains(l2); }
Local[] getInterferencesOf(Local l) { Object[] objects = localToLocals.get(l).toArray(); Local[] locals = new Local[objects.length]; for(int i = 0; i < objects.length; i++) locals[i] = (Local) objects[i]; return locals; } }
/** * Returns a list of possible targets for the given method and set of receiver types. */ public List<SootMethod> resolveAbstractDispatch(List<SootClass> classes, SootMethod m) { m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); Set<SootMethod> s = new ArraySet<SootMethod>(); for (SootClass sootClass : classes) { s.addAll(resolveAbstractDispatch(sootClass, m)); } return Collections.unmodifiableList(new ArrayList<SootMethod>(s)); }
/** Returns a list of possible targets for the given method and set of receiver types. */ public List resolveAbstractDispatch(List classes, SootMethod m) { m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); ArraySet s = new ArraySet(); Iterator classesIt = classes.iterator(); while (classesIt.hasNext()) s.addAll(resolveAbstractDispatch((SootClass)classesIt.next(), m)); List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
/** Given an abstract dispatch to an object of type c and a method m, gives * a list of possible receiver methods. */ public List resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Iterator<SootClass> classesIt = null; if (c.isInterface()) { classesIt = getImplementersOf(c).iterator(); HashSet<SootClass> classes = new HashSet<SootClass>(); while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next())); classesIt = classes.iterator(); } else classesIt = getSubclassesOfIncluding(c).iterator(); ArraySet s = new ArraySet(); while (classesIt.hasNext()) { SootClass cl = classesIt.next(); if( Modifier.isAbstract( cl.getModifiers() ) ) continue; s.add(resolveConcreteDispatch(cl, m)); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }