Package org.jboss.util.collection
Class ConcurrentReferenceHashMap.Segment<K,V>
- java.lang.Object
-
- java.util.concurrent.locks.ReentrantLock
-
- org.jboss.util.collection.ConcurrentReferenceHashMap.Segment<K,V>
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.concurrent.locks.Lock
- Enclosing class:
- ConcurrentReferenceHashMap<K,V>
static final class ConcurrentReferenceHashMap.Segment<K,V> extends java.util.concurrent.locks.ReentrantLock implements java.io.Serializable
Segments are specialized versions of hash tables. This subclasses from ReentrantLock opportunistically, just to simplify some locking and avoid separate construction.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
count
The number of elements in this segment's region.(package private) boolean
identityComparisons
(package private) ConcurrentReferenceHashMap.ReferenceType
keyType
(package private) float
loadFactor
The load factor for the hash table.(package private) int
modCount
Number of updates that alter the size of the table.(package private) java.lang.ref.ReferenceQueue<java.lang.Object>
refQueue
The collected weak-key reference queue for this segment.private static long
serialVersionUID
(package private) ConcurrentReferenceHashMap.HashEntry<K,V>[]
table
The per-segment table.(package private) int
threshold
The table is rehashed when its size exceeds this threshold.(package private) ConcurrentReferenceHashMap.ReferenceType
valueType
-
Constructor Summary
Constructors Constructor Description Segment(int initialCapacity, float lf, ConcurrentReferenceHashMap.ReferenceType keyType, ConcurrentReferenceHashMap.ReferenceType valueType, boolean identityComparisons)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
clear()
(package private) boolean
containsKey(java.lang.Object key, int hash)
(package private) boolean
containsValue(java.lang.Object value)
(package private) V
get(java.lang.Object key, int hash)
(package private) ConcurrentReferenceHashMap.HashEntry<K,V>
getFirst(int hash)
Returns properly casted first entry of bin for given hash.private boolean
keyEq(java.lang.Object src, java.lang.Object dest)
(package private) static <K,V>
ConcurrentReferenceHashMap.Segment<K,V>[]newArray(int i)
(package private) ConcurrentReferenceHashMap.HashEntry<K,V>
newHashEntry(K key, int hash, ConcurrentReferenceHashMap.HashEntry<K,V> next, V value)
(package private) V
put(K key, int hash, V value, boolean onlyIfAbsent)
(package private) V
readValueUnderLock(ConcurrentReferenceHashMap.HashEntry<K,V> e)
Reads value field of an entry under lock.(package private) int
rehash()
(package private) V
remove(java.lang.Object key, int hash, java.lang.Object value, boolean refRemove)
Remove; match on key only if value null, else match both.(package private) void
removeStale()
(package private) V
replace(K key, int hash, V newValue)
(package private) boolean
replace(K key, int hash, V oldValue, V newValue)
(package private) void
setTable(ConcurrentReferenceHashMap.HashEntry<K,V>[] newTable)
Sets table to new HashEntry array.-
Methods inherited from class java.util.concurrent.locks.ReentrantLock
getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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 ConcurrentReferenceHashMap.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 java.lang.ref.ReferenceQueue<java.lang.Object> refQueue
The collected weak-key reference queue for this segment. This should be (re)initialized whenever table is assigned,
-
keyType
final ConcurrentReferenceHashMap.ReferenceType keyType
-
valueType
final ConcurrentReferenceHashMap.ReferenceType valueType
-
identityComparisons
final boolean identityComparisons
-
-
Constructor Detail
-
Segment
Segment(int initialCapacity, float lf, ConcurrentReferenceHashMap.ReferenceType keyType, ConcurrentReferenceHashMap.ReferenceType valueType, boolean identityComparisons)
-
-
Method Detail
-
newArray
static final <K,V> ConcurrentReferenceHashMap.Segment<K,V>[] newArray(int i)
-
keyEq
private boolean keyEq(java.lang.Object src, java.lang.Object dest)
-
setTable
void setTable(ConcurrentReferenceHashMap.HashEntry<K,V>[] newTable)
Sets table to new HashEntry array. Call only while holding lock or in constructor.
-
getFirst
ConcurrentReferenceHashMap.HashEntry<K,V> getFirst(int hash)
Returns properly casted first entry of bin for given hash.
-
newHashEntry
ConcurrentReferenceHashMap.HashEntry<K,V> newHashEntry(K key, int hash, ConcurrentReferenceHashMap.HashEntry<K,V> next, V value)
-
readValueUnderLock
V readValueUnderLock(ConcurrentReferenceHashMap.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(java.lang.Object key, int hash)
-
containsKey
boolean containsKey(java.lang.Object key, int hash)
-
containsValue
boolean containsValue(java.lang.Object value)
-
rehash
int rehash()
-
remove
V remove(java.lang.Object key, int hash, java.lang.Object value, boolean refRemove)
Remove; match on key only if value null, else match both.
-
removeStale
final void removeStale()
-
clear
void clear()
-
-