static class MapMakerInternalMap.Segment<K,V>
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) java.util.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> |
evictionQueue
A queue of elements currently in the map, ordered by access time.
|
(package private) java.util.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> |
expirationQueue
A queue of elements currently in the map, ordered by expiration time (either access or write
time).
|
(package private) java.lang.ref.ReferenceQueue<K> |
keyReferenceQueue
The key reference queue contains entries whose keys have been garbage collected, and which
need to be cleaned up internally.
|
(package private) MapMakerInternalMap<K,V> |
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.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> |
recencyQueue
The recency queue is used to record which entries were accessed for updating the eviction
list's ordering.
|
(package private) java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> |
table
The per-segment table.
|
(package private) int |
threshold
The table is expanded when its size exceeds this threshold.
|
(package private) java.lang.ref.ReferenceQueue<V> |
valueReferenceQueue
The value reference queue contains value references whose values have been garbage collected,
and which need to be cleaned up internally.
|
Constructor and Description |
---|
Segment(MapMakerInternalMap<K,V> map,
int initialCapacity,
int maxSegmentSize) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
clear() |
(package private) void |
clearKeyReferenceQueue() |
(package private) void |
clearReferenceQueues()
Clears all entries from the key and value reference queues.
|
(package private) boolean |
clearValue(K key,
int hash,
MapMakerInternalMap.ValueReference<K,V> valueReference)
Clears a value that has not yet been set, and thus does not require count to be modified.
|
(package private) void |
clearValueReferenceQueue() |
(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) MapMakerInternalMap.ReferenceEntry<K,V> |
copyEntry(MapMakerInternalMap.ReferenceEntry<K,V> original,
MapMakerInternalMap.ReferenceEntry<K,V> newNext)
Copies
original into a new entry chained to newNext . |
(package private) void |
drainKeyReferenceQueue() |
(package private) void |
drainRecencyQueue()
Drains the recency queue, updating eviction metadata that the entries therein were read in
the specified relative order.
|
(package private) void |
drainReferenceQueues()
Drain the key and value reference queues, cleaning up internal entries containing garbage
collected keys or values.
|
(package private) void |
drainValueReferenceQueue() |
(package private) void |
enqueueNotification(K key,
int hash,
V value,
MapMaker.RemovalCause cause) |
(package private) void |
enqueueNotification(MapMakerInternalMap.ReferenceEntry<K,V> entry,
MapMaker.RemovalCause cause) |
(package private) boolean |
evictEntries()
Performs eviction if the segment is full.
|
(package private) void |
expand()
Expands the table if possible.
|
(package private) void |
expireEntries() |
(package private) V |
get(java.lang.Object key,
int hash) |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
getEntry(java.lang.Object key,
int hash) |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
getFirst(int hash)
Returns first entry of bin for given hash.
|
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
getLiveEntry(java.lang.Object key,
int hash) |
(package private) V |
getLiveValue(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Gets the value from an entry.
|
(package private) void |
initTable(java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> newTable) |
(package private) boolean |
isCollected(MapMakerInternalMap.ValueReference<K,V> valueReference)
Returns
true if the value has been partially collected, meaning that the value is
null and it is not computing. |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
newEntry(K key,
int hash,
MapMakerInternalMap.ReferenceEntry<K,V> next) |
(package private) java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> |
newEntryArray(int size) |
(package private) void |
postReadCleanup()
Performs routine cleanup following a read.
|
(package private) void |
postWriteCleanup()
Performs routine cleanup following a write.
|
(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(MapMakerInternalMap.ReferenceEntry<K,V> entry,
int hash)
Removes an entry whose key has been garbage collected.
|
(package private) boolean |
reclaimValue(K key,
int hash,
MapMakerInternalMap.ValueReference<K,V> valueReference)
Removes an entry whose value has been garbage collected.
|
(package private) void |
recordExpirationTime(MapMakerInternalMap.ReferenceEntry<K,V> entry,
long expirationNanos) |
(package private) void |
recordLockedRead(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Updates the eviction metadata that
entry was just read. |
(package private) void |
recordRead(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Records the relative order in which this read was performed by adding
entry to the
recency queue. |
(package private) void |
recordWrite(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Updates eviction metadata that
entry was just written. |
(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) void |
removeCollectedEntry(MapMakerInternalMap.ReferenceEntry<K,V> entry) |
(package private) boolean |
removeEntry(MapMakerInternalMap.ReferenceEntry<K,V> entry,
int hash,
MapMaker.RemovalCause cause) |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
removeFromChain(MapMakerInternalMap.ReferenceEntry<K,V> first,
MapMakerInternalMap.ReferenceEntry<K,V> entry)
Removes an entry from within a 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) void |
runUnlockedCleanup() |
(package private) void |
setValue(MapMakerInternalMap.ReferenceEntry<K,V> entry,
V value)
Sets a new value of an entry.
|
(package private) void |
tryDrainReferenceQueues()
Cleanup collected entries when the lock is available.
|
(package private) void |
tryExpireEntries()
Cleanup expired 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> map
volatile int count
int modCount
int threshold
(int) (capacity * 0.75)
.)volatile java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> table
final int maxSegmentSize
final java.lang.ref.ReferenceQueue<K> keyReferenceQueue
final java.lang.ref.ReferenceQueue<V> valueReferenceQueue
final java.util.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> recencyQueue
final java.util.concurrent.atomic.AtomicInteger readCount
final java.util.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> evictionQueue
final java.util.Queue<MapMakerInternalMap.ReferenceEntry<K,V>> expirationQueue
Segment(MapMakerInternalMap<K,V> map, int initialCapacity, int maxSegmentSize)
java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> newEntryArray(int size)
void initTable(java.util.concurrent.atomic.AtomicReferenceArray<MapMakerInternalMap.ReferenceEntry<K,V>> newTable)
MapMakerInternalMap.ReferenceEntry<K,V> newEntry(K key, int hash, @Nullable MapMakerInternalMap.ReferenceEntry<K,V> next)
MapMakerInternalMap.ReferenceEntry<K,V> copyEntry(MapMakerInternalMap.ReferenceEntry<K,V> original, MapMakerInternalMap.ReferenceEntry<K,V> newNext)
original
into a new entry chained to newNext
. Returns the new entry,
or null
if original
was already garbage collected.void setValue(MapMakerInternalMap.ReferenceEntry<K,V> entry, V value)
void tryDrainReferenceQueues()
void drainReferenceQueues()
void drainKeyReferenceQueue()
void drainValueReferenceQueue()
void clearReferenceQueues()
void clearKeyReferenceQueue()
void clearValueReferenceQueue()
void recordRead(MapMakerInternalMap.ReferenceEntry<K,V> entry)
entry
to the
recency queue. At write-time, or when the queue is full past the threshold, the queue will
be drained and the entries therein processed.
Note: locked reads should use recordLockedRead(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
.
void recordLockedRead(MapMakerInternalMap.ReferenceEntry<K,V> entry)
entry
was just read. This currently amounts to
adding entry
to relevant eviction lists.
Note: this method should only be called under lock, as it directly manipulates the
eviction queues. Unlocked reads should use recordRead(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
.
void recordWrite(MapMakerInternalMap.ReferenceEntry<K,V> entry)
entry
was just written. This currently amounts to
adding entry
to relevant eviction lists.void drainRecencyQueue()
void recordExpirationTime(MapMakerInternalMap.ReferenceEntry<K,V> entry, long expirationNanos)
void tryExpireEntries()
void expireEntries()
void enqueueNotification(MapMakerInternalMap.ReferenceEntry<K,V> entry, MapMaker.RemovalCause cause)
void enqueueNotification(@Nullable K key, int hash, @Nullable V value, MapMaker.RemovalCause cause)
boolean evictEntries()
count
.true
if eviction occurredMapMakerInternalMap.ReferenceEntry<K,V> getFirst(int hash)
MapMakerInternalMap.ReferenceEntry<K,V> getEntry(java.lang.Object key, int hash)
MapMakerInternalMap.ReferenceEntry<K,V> 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()
MapMakerInternalMap.ReferenceEntry<K,V> removeFromChain(MapMakerInternalMap.ReferenceEntry<K,V> first, MapMakerInternalMap.ReferenceEntry<K,V> 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 tablevoid removeCollectedEntry(MapMakerInternalMap.ReferenceEntry<K,V> entry)
boolean reclaimKey(MapMakerInternalMap.ReferenceEntry<K,V> entry, int hash)
boolean reclaimValue(K key, int hash, MapMakerInternalMap.ValueReference<K,V> valueReference)
boolean clearValue(K key, int hash, MapMakerInternalMap.ValueReference<K,V> valueReference)
boolean removeEntry(MapMakerInternalMap.ReferenceEntry<K,V> entry, int hash, MapMaker.RemovalCause cause)
boolean isCollected(MapMakerInternalMap.ValueReference<K,V> valueReference)
true
if the value has been partially collected, meaning that the value is
null and it is not computing.V getLiveValue(MapMakerInternalMap.ReferenceEntry<K,V> entry)
null
if the entry is invalid,
partially-collected, computing, or expired.void postReadCleanup()
void preWriteCleanup()
Post-condition: expireEntries has been run.
void postWriteCleanup()
void runCleanup()
void runLockedCleanup()
void runUnlockedCleanup()