Class MapMakerInternalMap.Segment<K,​V,​E extends MapMakerInternalMap.InternalEntry<K,​V,​E>,​S extends MapMakerInternalMap.Segment<K,​V,​E,​S>>

    • Field Detail

      • count

        volatile int count
        The number of live elements in this segment's region. This does not include unset elements which are awaiting cleanup.
      • modCount

        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

        int threshold
        The table is expanded when its size exceeds this threshold. (The value of this field is always (int) (capacity * 0.75).)
      • maxSegmentSize

        final int maxSegmentSize
        The maximum size of this map. MapMaker.UNSET_INT if there is no maximum.
      • readCount

        final 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.
    • Constructor Detail

    • Method Detail

      • maybeDrainReferenceQueues

        void maybeDrainReferenceQueues()
        Drains the reference queues used by this segment, if any.
      • maybeClearReferenceQueues

        void maybeClearReferenceQueues()
        Clears the reference queues used by this segment, if any.
      • setValue

        void setValue​(E entry,
                      V value)
        Sets the value of the given entry.
      • copyEntry

        E copyEntry​(E original,
                    E newNext)
        Returns a copy of the given entry.
      • newEntryArray

        java.util.concurrent.atomic.AtomicReferenceArray<E> newEntryArray​(int size)
      • initTable

        void initTable​(java.util.concurrent.atomic.AtomicReferenceArray<E> newTable)
      • castForTesting

        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.

        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.

      • getKeyReferenceQueueForTesting

        java.lang.ref.ReferenceQueue<K> getKeyReferenceQueueForTesting()
        Unsafely extracts the key reference queue used by this segment.
      • getValueReferenceQueueForTesting

        java.lang.ref.ReferenceQueue<V> getValueReferenceQueueForTesting()
        Unsafely extracts the value reference queue used by this segment.
      • setTableEntryForTesting

        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.
      • removeTableEntryForTesting

        boolean removeTableEntryForTesting​(MapMakerInternalMap.InternalEntry<K,​V,​?> entry)
        Unsafely removes the given entry from this segment's hash table.
      • getLiveValueForTesting

        @Nullable
        V getLiveValueForTesting​(MapMakerInternalMap.InternalEntry<K,​V,​?> entry)
        Unsafely returns the value of the given entry if it's still live, or null otherwise.
      • tryDrainReferenceQueues

        void tryDrainReferenceQueues()
        Cleanup collected entries when the lock is available.
      • drainKeyReferenceQueue

        void drainKeyReferenceQueue​(java.lang.ref.ReferenceQueue<K> keyReferenceQueue)
      • drainValueReferenceQueue

        void drainValueReferenceQueue​(java.lang.ref.ReferenceQueue<V> valueReferenceQueue)
      • clearReferenceQueue

        <T> void clearReferenceQueue​(java.lang.ref.ReferenceQueue<T> referenceQueue)
      • getFirst

        E getFirst​(int hash)
        Returns first entry of bin for given hash.
      • getEntry

        E getEntry​(java.lang.Object key,
                   int hash)
      • getLiveEntry

        E getLiveEntry​(java.lang.Object key,
                       int hash)
      • get

        V get​(java.lang.Object key,
              int hash)
      • containsKey

        boolean containsKey​(java.lang.Object key,
                            int hash)
      • put

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

        void expand()
        Expands the table if possible.
      • replace

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

        V replace​(K key,
                  int hash,
                  V newValue)
      • remove

        V remove​(java.lang.Object key,
                 int hash)
      • remove

        boolean remove​(java.lang.Object key,
                       int hash,
                       java.lang.Object value)
      • clear

        void clear()
      • removeFromChain

        E removeFromChain​(E first,
                          E entry)
        Removes an entry from within a table. All entries following the removed node can stay, but all preceding ones need to be cloned.

        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.

        Parameters:
        first - the first entry of the table
        entry - the entry being removed from the table
        Returns:
        the new first entry for the table
      • reclaimKey

        boolean reclaimKey​(E entry,
                           int hash)
        Removes an entry whose key has been garbage collected.
      • removeEntryForTesting

        boolean removeEntryForTesting​(E entry)
      • isCollected

        static <K,​V,​E extends MapMakerInternalMap.InternalEntry<K,​V,​E>> boolean isCollected​(E entry)
        Returns true if the value has been partially collected, meaning that the value is null.
      • getLiveValue

        @Nullable
        V getLiveValue​(E entry)
        Gets the value from an entry. Returns null if the entry is invalid or partially-collected.
      • postReadCleanup

        void postReadCleanup()
        Performs routine cleanup following a read. Normally cleanup happens during writes, or from the cleanupExecutor. If cleanup is not observed after a sufficient number of reads, try cleaning up from the read thread.
      • preWriteCleanup

        void preWriteCleanup()
        Performs routine cleanup prior to executing a write. This should be called every time a write thread acquires the segment lock, immediately after acquiring the lock.
      • runCleanup

        void runCleanup()
      • runLockedCleanup

        void runLockedCleanup()