src/share/classes/sun/misc/Cache.java

Print this page

        

@@ -23,23 +23,38 @@
  * questions.
  */
 
 package sun.misc;
 
+import java.lang.ref.SoftReference;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
 
 /**
  * Caches the collision list.
  */
-class CacheEntry extends Ref {
+class CacheEntry {
     int hash;
     Object key;
     CacheEntry next;
-    public Object reconstitute() {
-        return null;
+    SoftReference<Object> value;
+
+    public CacheEntry() {
+        value = null;
+    }
+
+    public CacheEntry(Object o) {
+        value = new SoftReference<>(o);
+    }
+
+    public Object get() {
+        return value.get();
+    }
+
+    public void setThing(Object thing) {
+        value = new SoftReference<>(thing);
     }
 }
 
 /**
  * The Cache class. Maps keys to values. Any object can be used as

@@ -190,11 +205,11 @@
         CacheEntry tab[] = table;
         int hash = key.hashCode();
         int index = (hash & 0x7FFFFFFF) % tab.length;
         for (CacheEntry e = tab[index]; e != null; e = e.next) {
             if ((e.hash == hash) && e.key.equals(key)) {
-                return e.check();
+                return e.get();
             }
         }
         return null;
     }
 

@@ -218,11 +233,11 @@
 
         for (int i = oldCapacity; i-- > 0;) {
             for (CacheEntry old = oldTable[i]; old != null;) {
                 CacheEntry e = old;
                 old = old.next;
-                if (e.check() != null) {
+                if (e.get() != null) {
                     int index = (e.hash & 0x7FFFFFFF) % newCapacity;
                     e.next = newTable[index];
                     newTable[index] = e;
                 } else
                     count--;    /* remove entries that have disappeared */

@@ -251,14 +266,14 @@
         int hash = key.hashCode();
         int index = (hash & 0x7FFFFFFF) % tab.length;
         CacheEntry ne = null;
         for (CacheEntry e = tab[index]; e != null; e = e.next) {
             if ((e.hash == hash) && e.key.equals(key)) {
-                Object old = e.check();
+                Object old = e.get();
                 e.setThing(value);
                 return old;
-            } else if (e.check() == null)
+            } else if (e.get() == null)
                 ne = e;         /* reuse old flushed value */
         }
 
         if (count >= threshold) {
             // Rehash the table if the threshold is exceeded

@@ -294,11 +309,11 @@
                     prev.next = e.next;
                 } else {
                     tab[index] = e.next;
                 }
                 count--;
-                return e.check();
+                return e.get();
             }
         }
         return null;
     }
 }

@@ -320,11 +335,11 @@
     }
 
     public boolean hasMoreElements() {
         while (index >= 0) {
             while (entry != null)
-                if (entry.check() != null)
+                if (entry.get() != null)
                     return true;
                 else
                     entry = entry.next;
             while (--index >= 0 && (entry = table[index]) == null) ;
         }

@@ -336,12 +351,12 @@
             if (entry == null)
                 while (--index >= 0 && (entry = table[index]) == null) ;
             if (entry != null) {
                 CacheEntry e = entry;
                 entry = e.next;
-                if (e.check() != null)
-                    return keys ? e.key : e.check();
+                if (e.get() != null)
+                    return keys ? e.key : e.get();
             }
         }
         throw new NoSuchElementException("CacheEnumerator");
     }