Class AdaptivePoolingAllocator.SharedSizeClassedChunkCache
- All Implemented Interfaces:
AdaptivePoolingAllocator.ChunkCache
- Enclosing class:
AdaptivePoolingAllocator
scanForCapacity — LRU preference with fallback:
fast path: head chunk has purgeEpoch == 0 and capacity → return O(1)
slow path: scan for epoch=0 chunk, hold first idle (epoch > 0) as fallback
queue: [E>0, E>0, E=0, E>0, ...]
skip skip ↑ return (put fallback back)
no epoch=0 found → use fallback, reset its epoch to 0
The LRU preference creates a natural separation: recently-used chunks (epoch=0,
returned via offerChunk(AdaptivePoolingAllocator.Chunk) after magazine use) cycle at the front. Idle chunks
(epoch > 0, aged by purge) are scanned past but never returned — they age undisturbed.
When no recently-used chunks exist, idle ones are reused (fallback) rather than
allocating new chunks.
All re-offered chunks are stamped with lastScanGeneration for cycle detection.
The >= check terminates the scan when encountering any chunk already processed
by this or a later scan, preventing livelock under concurrent access.
runPurgeScan (every AdaptivePoolingAllocator.CHUNK_PURGE_POLLS_SHARED polls):
drains the queue, ages full chunks (epoch++), resets non-full (epoch=0).
Non-candidate capacity chunks are re-offered inline. Eviction candidates (full,
epoch past threshold) and no-capacity chunks are deferred to a buffer. After the drain,
the buffer is walked with the known total: candidates are evicted while above
AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE, remainder re-offered. No selection — that is
scanForCapacity's job (called after purge via pollChunk).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final java.util.ArrayList<AdaptivePoolingAllocator.SizeClassedChunk> private final java.util.concurrent.atomic.AtomicLongprivate longprivate final java.util.Queue<AdaptivePoolingAllocator.SizeClassedChunk> private final java.util.concurrent.atomic.AtomicLongprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) AdaptivePoolingAllocator.SizeClassedChunkvoidfree()booleanisEmpty()booleanprivate booleanprivate booleanofferOrDeallocate(AdaptivePoolingAllocator.SizeClassedChunk chunk, long generation) pollChunk(int size) private voidscanForCapacitySlow(long generation, AdaptivePoolingAllocator.SizeClassedChunk fallback) Methods inherited from class AdaptivePoolingAllocator.SizeClassedChunkCache
createMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
SHARED_CACHE_CAPACITY
private static final int SHARED_CACHE_CAPACITY -
queue
-
purgeBudget
private final java.util.concurrent.atomic.AtomicLong purgeBudget -
deferredBuffer
-
purgeGeneration
private long purgeGeneration -
scanGeneration
private final java.util.concurrent.atomic.AtomicLong scanGeneration
-
-
Constructor Details
-
SharedSizeClassedChunkCache
SharedSizeClassedChunkCache()
-
-
Method Details
-
forcePurge
AdaptivePoolingAllocator.SizeClassedChunk forcePurge()- Specified by:
forcePurgein classAdaptivePoolingAllocator.SizeClassedChunkCache
-
pollChunk
- Specified by:
pollChunkin interfaceAdaptivePoolingAllocator.ChunkCache- Specified by:
pollChunkin classAdaptivePoolingAllocator.SizeClassedChunkCache
-
scanForCapacity
-
scanForCapacitySlow
private AdaptivePoolingAllocator.SizeClassedChunk scanForCapacitySlow(long generation, AdaptivePoolingAllocator.SizeClassedChunk fallback) -
offerOrDeallocate
-
offerOrDeallocate
-
runPurgeScan
private void runPurgeScan() -
offerChunk
-
free
public void free() -
isEmpty
public boolean isEmpty()
-