abstract static class MapMakerInternalMap.Segment<K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>,S extends MapMakerInternalMap.Segment<K,V,E,S>>
extends java.util.concurrent.locks.ReentrantLock
Modifier and Type | Field and Description |
---|---|
(package private) int |
count
The number of live elements in this segment's region.
|
(package private) MapMakerInternalMap<K,V,E,S> |
map |
(package private) int |
maxSegmentSize
The maximum size of this map.
|
(package private) int |
modCount
Number of updates that alter the size of the table.
|
(package private) java.util.concurrent.atomic.AtomicInteger |
readCount
A counter of the number of reads since the last write, used to drain queues on a small
fraction of read operations.
|
(package private) java.util.concurrent.atomic.AtomicReferenceArray<E> |
table
The per-segment table.
|
(package private) int |
threshold
The table is expanded when its size exceeds this threshold.
|
Constructor and Description |
---|
Segment(MapMakerInternalMap<K,V,E,S> map,
int initialCapacity,
int maxSegmentSize) |
Modifier and Type | Method and Description |
---|---|
(package private) abstract E |
castForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafe cast of the given entry to
E , the type of the specific MapMakerInternalMap.InternalEntry
implementation type. |
(package private) void |
clear() |
(package private) <T> void |
clearReferenceQueue(java.lang.ref.ReferenceQueue<T> referenceQueue) |
(package private) boolean |
clearValueForTesting(K key,
int hash,
MapMakerInternalMap.WeakValueReference<K,V,? extends MapMakerInternalMap.InternalEntry<K,V,?>> valueReference)
Clears a value that has not yet been set, and thus does not require count to be modified.
|
(package private) boolean |
containsKey(java.lang.Object key,
int hash) |
(package private) boolean |
containsValue(java.lang.Object value)
This method is a convenience for testing.
|
(package private) E |
copyEntry(E original,
E newNext)
Returns a copy of the given
entry . |
(package private) E |
copyForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry,
MapMakerInternalMap.InternalEntry<K,V,?> newNext)
Unsafely returns a copy of the given entry.
|
(package private) void |
drainKeyReferenceQueue(java.lang.ref.ReferenceQueue<K> keyReferenceQueue) |
(package private) void |
drainValueReferenceQueue(java.lang.ref.ReferenceQueue<V> valueReferenceQueue) |
(package private) void |
expand()
Expands the table if possible.
|
(package private) V |
get(java.lang.Object key,
int hash) |
(package private) E |
getEntry(java.lang.Object key,
int hash) |
(package private) E |
getFirst(int hash)
Returns first entry of bin for given hash.
|
(package private) java.lang.ref.ReferenceQueue<K> |
getKeyReferenceQueueForTesting()
Unsafely extracts the key reference queue used by this segment.
|
(package private) E |
getLiveEntry(java.lang.Object key,
int hash) |
(package private) V |
getLiveValue(E entry)
Gets the value from an entry.
|
(package private) V |
getLiveValueForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafely returns the value of the given entry if it's still live, or
null otherwise. |
(package private) java.lang.ref.ReferenceQueue<V> |
getValueReferenceQueueForTesting()
Unsafely extracts the value reference queue used by this segment.
|
(package private) MapMakerInternalMap.WeakValueReference<K,V,E> |
getWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafely extracts the weak value reference inside of the given
entry . |
(package private) void |
initTable(java.util.concurrent.atomic.AtomicReferenceArray<E> newTable) |
(package private) static <K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>> |
isCollected(E entry)
Returns
true if the value has been partially collected, meaning that the value is
null. |
(package private) void |
maybeClearReferenceQueues()
Clears the reference queues used by this segment, if any.
|
(package private) void |
maybeDrainReferenceQueues()
Drains the reference queues used by this segment, if any.
|
(package private) java.util.concurrent.atomic.AtomicReferenceArray<E> |
newEntryArray(int size) |
(package private) E |
newEntryForTesting(K key,
int hash,
MapMakerInternalMap.InternalEntry<K,V,?> next)
Unsafely returns a fresh entry.
|
(package private) MapMakerInternalMap.WeakValueReference<K,V,E> |
newWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry,
V value)
Unsafely creates of a fresh
MapMakerInternalMap.WeakValueReference , referencing the given value ,
for the given entry |
(package private) void |
postReadCleanup()
Performs routine cleanup following a read.
|
(package private) void |
preWriteCleanup()
Performs routine cleanup prior to executing a write.
|
(package private) V |
put(K key,
int hash,
V value,
boolean onlyIfAbsent) |
(package private) boolean |
reclaimKey(E entry,
int hash)
Removes an entry whose key has been garbage collected.
|
(package private) boolean |
reclaimValue(K key,
int hash,
MapMakerInternalMap.WeakValueReference<K,V,E> valueReference)
Removes an entry whose value has been garbage collected.
|
(package private) V |
remove(java.lang.Object key,
int hash) |
(package private) boolean |
remove(java.lang.Object key,
int hash,
java.lang.Object value) |
(package private) boolean |
removeEntryForTesting(E entry) |
(package private) E |
removeFromChain(E first,
E entry)
Removes an entry from within a table.
|
(package private) E |
removeFromChainForTesting(MapMakerInternalMap.InternalEntry<K,V,?> first,
MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafely removes the given entry from the given chain in this segment's hash table.
|
(package private) boolean |
removeTableEntryForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafely removes the given entry from this segment's hash table.
|
(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 |
runCleanup() |
(package private) void |
runLockedCleanup() |
(package private) abstract S |
self()
|
(package private) void |
setTableEntryForTesting(int i,
MapMakerInternalMap.InternalEntry<K,V,?> entry)
Unsafely sets the given index of this segment's internal hash table to be the given entry.
|
(package private) void |
setValue(E entry,
V value)
Sets the value of the given
entry . |
(package private) void |
setValueForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry,
V value)
Unsafely sets the value of the given entry.
|
(package private) void |
setWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry,
MapMakerInternalMap.WeakValueReference<K,V,? extends MapMakerInternalMap.InternalEntry<K,V,?>> valueReference)
Unsafely sets the weak value reference inside the given
entry to be the given valueReference |
(package private) void |
tryDrainReferenceQueues()
Cleanup collected entries when the lock is available.
|
getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock
final MapMakerInternalMap<K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>,S extends MapMakerInternalMap.Segment<K,V,E,S>> map
volatile int count
int modCount
int threshold
(int) (capacity * 0.75)
.)volatile java.util.concurrent.atomic.AtomicReferenceArray<E extends MapMakerInternalMap.InternalEntry<K,V,E>> table
final int maxSegmentSize
final java.util.concurrent.atomic.AtomicInteger readCount
Segment(MapMakerInternalMap<K,V,E,S> map, int initialCapacity, int maxSegmentSize)
abstract S self()
this
up-casted to the specific MapMakerInternalMap.Segment
implementation type S
.
This method exists so that the MapMakerInternalMap.Segment
code can be generic in terms of S
,
the type of the concrete implementation.
void maybeDrainReferenceQueues()
void maybeClearReferenceQueues()
java.util.concurrent.atomic.AtomicReferenceArray<E> newEntryArray(int size)
void initTable(java.util.concurrent.atomic.AtomicReferenceArray<E> newTable)
abstract E castForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
E
, the type of the specific MapMakerInternalMap.InternalEntry
implementation type.
This method is provided as a convenience for tests. Otherwise they'd need to be knowledgable about all the implementation details of our type system trickery.
java.lang.ref.ReferenceQueue<K> getKeyReferenceQueueForTesting()
java.lang.ref.ReferenceQueue<V> getValueReferenceQueueForTesting()
MapMakerInternalMap.WeakValueReference<K,V,E> getWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
entry
.MapMakerInternalMap.WeakValueReference<K,V,E> newWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry, V value)
MapMakerInternalMap.WeakValueReference
, referencing the given value
,
for the given entry
void setWeakValueReferenceForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry, MapMakerInternalMap.WeakValueReference<K,V,? extends MapMakerInternalMap.InternalEntry<K,V,?>> valueReference)
entry
to be the given valueReference
void setTableEntryForTesting(int i, MapMakerInternalMap.InternalEntry<K,V,?> entry)
E copyForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry, MapMakerInternalMap.InternalEntry<K,V,?> newNext)
void setValueForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry, V value)
E newEntryForTesting(K key, int hash, MapMakerInternalMap.InternalEntry<K,V,?> next)
boolean removeTableEntryForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
E removeFromChainForTesting(MapMakerInternalMap.InternalEntry<K,V,?> first, MapMakerInternalMap.InternalEntry<K,V,?> entry)
V getLiveValueForTesting(MapMakerInternalMap.InternalEntry<K,V,?> entry)
null
otherwise.void tryDrainReferenceQueues()
void drainKeyReferenceQueue(java.lang.ref.ReferenceQueue<K> keyReferenceQueue)
void drainValueReferenceQueue(java.lang.ref.ReferenceQueue<V> valueReferenceQueue)
<T> void clearReferenceQueue(java.lang.ref.ReferenceQueue<T> referenceQueue)
E getFirst(int hash)
E getEntry(java.lang.Object key, int hash)
E getLiveEntry(java.lang.Object key, int hash)
V get(java.lang.Object key, int hash)
boolean containsKey(java.lang.Object key, int hash)
boolean containsValue(java.lang.Object value)
MapMakerInternalMap.containsValue(java.lang.Object)
directly.void expand()
V remove(java.lang.Object key, int hash)
boolean remove(java.lang.Object key, int hash, java.lang.Object value)
void clear()
E removeFromChain(E first, E entry)
This method does not decrement count for the removed entry, but does decrement count for all partially collected entries which are skipped. As such callers which are modifying count must re-read it after calling removeFromChain.
first
- the first entry of the tableentry
- the entry being removed from the tableboolean reclaimKey(E entry, int hash)
boolean reclaimValue(K key, int hash, MapMakerInternalMap.WeakValueReference<K,V,E> valueReference)
boolean clearValueForTesting(K key, int hash, MapMakerInternalMap.WeakValueReference<K,V,? extends MapMakerInternalMap.InternalEntry<K,V,?>> valueReference)
boolean removeEntryForTesting(E entry)
static <K,V,E extends MapMakerInternalMap.InternalEntry<K,V,E>> boolean isCollected(E entry)
true
if the value has been partially collected, meaning that the value is
null.V getLiveValue(E entry)
null
if the entry is invalid or
partially-collected.void postReadCleanup()
void preWriteCleanup()
void runCleanup()
void runLockedCleanup()