org.aspectbench.tm.runtime.internal
Class WeakKeyIdentityHashMap

java.lang.Object
  extended by org.aspectbench.tm.runtime.internal.IdentityHashMap
      extended by org.aspectbench.tm.runtime.internal.WeakKeyIdentityHashMap
All Implemented Interfaces:
java.util.Map

public class WeakKeyIdentityHashMap
extends IdentityHashMap

Part of the Indexing Data Structure implementation. This is a HashMap-like data structure that uses key identity as the basis for comparison. It isn't quite conformant to the java.util.Map interface, since its hasNext() method is (by design) unreliable. Instead, next() should be called and the return value checked for non-nullness. This class uses weak references for its keys, but does *not* drop a mapping after a key expires -- it is still iterable. Only the methods of the Map interface that are required by the IDS are implemented, all others just throw an exception.

Author:
Pavel Avgustinov

Nested Class Summary
 class WeakKeyIdentityHashMap.HashEntry
          HashEntrys for this kind of map return the object if getKey() is called and the object is alive.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.aspectbench.tm.runtime.internal.IdentityHashMap
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, loadFactor, MAXIMUM_CAPACITY, modCount, size, threshold
 
Constructor Summary
WeakKeyIdentityHashMap()
           
WeakKeyIdentityHashMap(int initialCapacity)
           
WeakKeyIdentityHashMap(int initialCapacity, float loadFactor)
           
WeakKeyIdentityHashMap(int initialCapacity, float loadFactor, int threshold)
           
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          
static java.lang.Object getMarker(java.lang.Object key)
          If the given object is already a Marker, it is returned unchanged.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          
 java.lang.Object remove(java.lang.Object key)
          
 java.lang.Object safeRemove(java.lang.Object key)
          Removes the key/value pair corresponding to the hidden key in a "safe" way.
 
Methods inherited from class org.aspectbench.tm.runtime.internal.IdentityHashMap
calculateNewCapacity, calculateThreshold, checkCapacity, clear, containsKey, containsValue, entryIterator, entrySet, hashIndex, hashIndex, hashIndexFromCode, hashIndexFromCode, isEmpty, keyIterator, keySet, putAll, rebalance, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

WeakKeyIdentityHashMap

public WeakKeyIdentityHashMap()

WeakKeyIdentityHashMap

public WeakKeyIdentityHashMap(int initialCapacity,
                              float loadFactor,
                              int threshold)

WeakKeyIdentityHashMap

public WeakKeyIdentityHashMap(int initialCapacity,
                              float loadFactor)

WeakKeyIdentityHashMap

public WeakKeyIdentityHashMap(int initialCapacity)
Method Detail

getMarker

public static java.lang.Object getMarker(java.lang.Object key)
If the given object is already a Marker, it is returned unchanged. Otherwise, the Marker representing that particular object is (constructed, if necessary, and) returned. Actually, the marker object scheme is deprecated in favour of persistent weakrefs.


get

public java.lang.Object get(java.lang.Object key)

Specified by:
get in interface java.util.Map
Overrides:
get in class IdentityHashMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Specified by:
put in interface java.util.Map
Overrides:
put in class IdentityHashMap

remove

public java.lang.Object remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map
Overrides:
remove in class IdentityHashMap

safeRemove

public java.lang.Object safeRemove(java.lang.Object key)
Removes the key/value pair corresponding to the hidden key in a "safe" way. What this means is that it doesn't update the modCount. It's intended for this method to be called when automatically purging values from the map. In this way, we allow removal of values while iterating over the keyset, but still catch "non-safe", i.e. user-initiated, removals.

Overrides:
safeRemove in class IdentityHashMap