comments and generics

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3512 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-04-22 17:17:23 +00:00
parent 243b7e53a0
commit abe6b548e6
1 changed files with 19 additions and 27 deletions

View File

@ -28,21 +28,17 @@ import com.ibm.wala.util.ref.CacheReference;
* *
* A mapping from (IMethod,Context) -> SSAOptions -> SoftReference -> something * A mapping from (IMethod,Context) -> SSAOptions -> SoftReference -> something
* *
* This doesn't work very well ... GCs don't do such a great job with * This doesn't work very well ... GCs don't do such a great job with SoftReferences ... revamp it.
* SoftReferences ... revamp it.
*
* @author sfink
*/ */
public class AuxiliaryCache { public class AuxiliaryCache {
/** /**
* A mapping from IMethod -> SSAOptions -> SoftReference -> IR * A mapping from IMethod -> SSAOptions -> SoftReference -> IR
*/ */
private HashMap<Pair, Map<SSAOptions,Object>> dictionary = HashMapFactory.make(); private HashMap<Pair<IMethod, Context>, Map<SSAOptions, Object>> dictionary = HashMapFactory.make();
/** /**
* Help out the garbage collector: clear this cache when * Help out the garbage collector: clear this cache when the number of items is > RESET_THRESHOLD
* the number of items is > RESET_THRESHOLD
*/ */
final private static int RESET_THRESHOLD = 2000; final private static int RESET_THRESHOLD = 2000;
@ -63,12 +59,13 @@ public class AuxiliaryCache {
* clear out things from which no IR is reachable * clear out things from which no IR is reachable
*/ */
private void reset() { private void reset() {
Map<Pair, Map<SSAOptions,Object>> oldDictionary = dictionary; Map<Pair<IMethod, Context>, Map<SSAOptions, Object>> oldDictionary = dictionary;
dictionary = HashMapFactory.make(); dictionary = HashMapFactory.make();
nItems = 0; nItems = 0;
for (Iterator<Map.Entry<Pair,Map<SSAOptions,Object>>> it = oldDictionary.entrySet().iterator(); it.hasNext();) { for (Iterator<Map.Entry<Pair<IMethod, Context>, Map<SSAOptions, Object>>> it = oldDictionary.entrySet().iterator(); it
Map.Entry<Pair,Map<SSAOptions,Object>> e = it.next(); .hasNext();) {
Map.Entry<Pair<IMethod, Context>, Map<SSAOptions, Object>> e = it.next();
Map<SSAOptions, Object> m = e.getValue(); Map<SSAOptions, Object> m = e.getValue();
HashSet<Object> toRemove = HashSetFactory.make(); HashSet<Object> toRemove = HashSetFactory.make();
for (Iterator it2 = m.entrySet().iterator(); it2.hasNext();) { for (Iterator it2 = m.entrySet().iterator(); it2.hasNext();) {
@ -89,15 +86,13 @@ public class AuxiliaryCache {
} }
/** /**
* @param m * @param m a method
* a method * @param options options governing ssa construction
* @param options
* options governing ssa construction
* @return the object cached for m, or null if none found * @return the object cached for m, or null if none found
*/ */
public synchronized Object find(IMethod m, Context C, SSAOptions options) { public synchronized Object find(IMethod m, Context c, SSAOptions options) {
// methodMap: SSAOptions -> SoftReference // methodMap: SSAOptions -> SoftReference
Pair p = Pair.make(m,C); Pair<IMethod, Context> p = Pair.make(m, c);
Map methodMap = MapUtil.findOrCreateMap(dictionary, p); Map methodMap = MapUtil.findOrCreateMap(dictionary, p);
Object ref = methodMap.get(options); Object ref = methodMap.get(options);
if (ref == null || CacheReference.get(ref) == null) { if (ref == null || CacheReference.get(ref) == null) {
@ -110,18 +105,16 @@ public class AuxiliaryCache {
/** /**
* cache new auxiliary information for an <m,options> pair * cache new auxiliary information for an <m,options> pair
* *
* @param m * @param m a method
* a method * @param options options governing ssa construction
* @param options
* options governing ssa construction
*/ */
public synchronized void cache(IMethod m, Context C, SSAOptions options, Object aux) { public synchronized void cache(IMethod m, Context c, SSAOptions options, Object aux) {
nItems++; nItems++;
if (nItems > RESET_THRESHOLD) { if (nItems > RESET_THRESHOLD) {
reset(); reset();
} }
Pair p = Pair.make(m,C); Pair<IMethod, Context> p = Pair.make(m, c);
// methodMap: SSAOptions -> SoftReference // methodMap: SSAOptions -> SoftReference
Map<SSAOptions, Object> methodMap = MapUtil.findOrCreateMap(dictionary, p); Map<SSAOptions, Object> methodMap = MapUtil.findOrCreateMap(dictionary, p);
Object ref = CacheReference.make(aux); Object ref = CacheReference.make(aux);
@ -130,9 +123,8 @@ public class AuxiliaryCache {
/** /**
* invalidate all cached information about a method * invalidate all cached information about a method
* @param method
*/ */
public void invalidate(IMethod method, Context C) { public void invalidate(IMethod method, Context c) {
dictionary.remove(Pair.make(method,C)); dictionary.remove(Pair.make(method, c));
} }
} }