Class AdaptivePoolingAllocator.SharedSizeClassedChunkCache
- java.lang.Object
-
- io.netty.buffer.AdaptivePoolingAllocator.SizeClassedChunkCache
-
- io.netty.buffer.AdaptivePoolingAllocator.SharedSizeClassedChunkCache
-
- All Implemented Interfaces:
AdaptivePoolingAllocator.ChunkCache
- Enclosing class:
- AdaptivePoolingAllocator
static final class AdaptivePoolingAllocator.SharedSizeClassedChunkCache extends AdaptivePoolingAllocator.SizeClassedChunkCache
MPMC queue cache for shared (cross-thread) chunk reuse.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 0The LRU preference creates a natural separation: recently-used chunks (epoch=0, returned via
offerChunk(io.netty.buffer.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
lastScanGenerationfor 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_SHAREDpolls): 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 aboveAdaptivePoolingAllocator.CHUNK_REUSE_QUEUE, remainder re-offered. No selection — that isscanForCapacity's job (called after purge viapollChunk).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<AdaptivePoolingAllocator.SizeClassedChunk>deferredBufferprivate java.util.concurrent.atomic.AtomicLongpurgeBudgetprivate longpurgeGenerationprivate java.util.Queue<AdaptivePoolingAllocator.SizeClassedChunk>queueprivate java.util.concurrent.atomic.AtomicLongscanGenerationprivate static intSHARED_CACHE_CAPACITY
-
Constructor Summary
Constructors Constructor Description SharedSizeClassedChunkCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) AdaptivePoolingAllocator.SizeClassedChunkforcePurge()voidfree()booleanisEmpty()booleanofferChunk(AdaptivePoolingAllocator.Chunk chunk)private booleanofferOrDeallocate(AdaptivePoolingAllocator.SizeClassedChunk chunk)private booleanofferOrDeallocate(AdaptivePoolingAllocator.SizeClassedChunk chunk, long generation)AdaptivePoolingAllocator.SizeClassedChunkpollChunk(int size)private voidrunPurgeScan()private AdaptivePoolingAllocator.SizeClassedChunkscanForCapacity()private AdaptivePoolingAllocator.SizeClassedChunkscanForCapacitySlow(long generation, AdaptivePoolingAllocator.SizeClassedChunk fallback)-
Methods inherited from class io.netty.buffer.AdaptivePoolingAllocator.SizeClassedChunkCache
create
-
-
-
-
Field Detail
-
SHARED_CACHE_CAPACITY
private static final int SHARED_CACHE_CAPACITY
-
queue
private final java.util.Queue<AdaptivePoolingAllocator.SizeClassedChunk> queue
-
purgeBudget
private final java.util.concurrent.atomic.AtomicLong purgeBudget
-
deferredBuffer
private final java.util.ArrayList<AdaptivePoolingAllocator.SizeClassedChunk> deferredBuffer
-
purgeGeneration
private long purgeGeneration
-
scanGeneration
private final java.util.concurrent.atomic.AtomicLong scanGeneration
-
-
Method Detail
-
forcePurge
AdaptivePoolingAllocator.SizeClassedChunk forcePurge()
- Specified by:
forcePurgein classAdaptivePoolingAllocator.SizeClassedChunkCache
-
pollChunk
public AdaptivePoolingAllocator.SizeClassedChunk pollChunk(int size)
- Specified by:
pollChunkin interfaceAdaptivePoolingAllocator.ChunkCache- Specified by:
pollChunkin classAdaptivePoolingAllocator.SizeClassedChunkCache
-
scanForCapacity
private AdaptivePoolingAllocator.SizeClassedChunk scanForCapacity()
-
scanForCapacitySlow
private AdaptivePoolingAllocator.SizeClassedChunk scanForCapacitySlow(long generation, AdaptivePoolingAllocator.SizeClassedChunk fallback)
-
offerOrDeallocate
private boolean offerOrDeallocate(AdaptivePoolingAllocator.SizeClassedChunk chunk)
-
offerOrDeallocate
private boolean offerOrDeallocate(AdaptivePoolingAllocator.SizeClassedChunk chunk, long generation)
-
runPurgeScan
private void runPurgeScan()
-
offerChunk
public boolean offerChunk(AdaptivePoolingAllocator.Chunk chunk)
-
free
public void free()
-
isEmpty
public boolean isEmpty()
-
-