Class ConcurrentWeakHashMap.Segment<K,V>

java.lang.Object
java.util.concurrent.locks.ReentrantLock
gw.util.concurrent.ConcurrentWeakHashMap.Segment<K,V>
All Implemented Interfaces:
Serializable, Lock
Enclosing class:
ConcurrentWeakHashMap<K,V>

static final class ConcurrentWeakHashMap.Segment<K,V> extends ReentrantLock implements Serializable
Segments are specialized versions of hash tables. This subclasses from ReentrantLock opportunistically, just to simplify some locking and avoid separate construction.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • count

      transient volatile int count
      The number of elements in this segment's region.
    • modCount

      transient int modCount
      Number of updates that alter the size of the table. This is used during bulk-read methods to make sure they see a consistent snapshot: If modCounts change during a traversal of segments computing size or checking containsValue, then we might have an inconsistent view of state so (usually) must retry.
    • threshold

      transient int threshold
      The table is rehashed when its size exceeds this threshold. (The value of this field is always (int)(capacity * loadFactor).)
    • table

      transient volatile ConcurrentWeakHashMap.HashEntry<K,V>[] table
      The per-segment table.
    • loadFactor

      final float loadFactor
      The load factor for the hash table. Even though this value is same for all segments, it is replicated to avoid needing links to outer object.
    • refQueue

      transient volatile ReferenceQueue<K> refQueue
      The collected weak-key reference queue for this segment. This should be (re)initialized whenever table is assigned,
  • Constructor Details

    • Segment

      Segment(int initialCapacity, float lf)
  • Method Details

    • newArray

      static final <K, V> ConcurrentWeakHashMap.Segment<K,V>[] newArray(int i)
    • setTable

      void setTable(ConcurrentWeakHashMap.HashEntry<K,V>[] newTable)
      Sets table to new HashEntry array. Call only while holding lock or in constructor.
    • getFirst

      ConcurrentWeakHashMap.HashEntry<K,V> getFirst(int hash)
      Returns properly casted first entry of bin for given hash.
    • readValueUnderLock

      V readValueUnderLock(ConcurrentWeakHashMap.HashEntry<K,V> e)
      Reads value field of an entry under lock. Called if value field ever appears to be null. This is possible only if a compiler happens to reorder a HashEntry initialization with its table assignment, which is legal under memory model but is not known to ever occur.
    • get

      V get(Object key, int hash)
    • containsKey

      boolean containsKey(Object key, int hash)
    • containsValue

      boolean containsValue(Object value)
    • replace

      boolean replace(K key, int hash, V oldValue, V newValue)
    • replace

      V replace(K key, int hash, V newValue)
    • put

      V put(K key, int hash, V value, boolean onlyIfAbsent)
    • rehash

      int rehash()
    • remove

      V remove(Object key, int hash, Object value, boolean weakRemove)
      Remove; match on key only if value null, else match both.
    • removeStale

      void removeStale()
    • clear

      void clear()