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