Top Description Inners Fields Constructors Methods
io.netty5.buffer.pool

pack-priv final Class PoolThreadCache

extends Object
Class Inheritance
Imports
io.netty5.buffer.pool.PoolArena.SizeClass, io.netty5.util.internal.MathUtil, .ObjectPool, .ObjectPool.Handle, .PlatformDependent, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.ArrayList, .List, .Queue, java.util.concurrent.atomic.AtomicInteger

Acts a Thread cache for allocations. This implementation is modelled after jemalloc and the described techniques of Scalable memory allocation using jemalloc.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
PoolThreadCache.NormalMemoryRegionCache

Cache used for buffers which are backed by NORMAL size.

private static class
PoolThreadCache.SubPageMemoryRegionCache

Cache used for buffers which are backed by SMALL size.

Field Summary

Modifier and TypeField and Description
private int
private final PoolArena
pack-priv final AtomicInteger
private final int
private static final int
private static final InternalLogger
private final PoolThreadCache.MemoryRegionCache[]
private final PoolThreadCache.MemoryRegionCache[]

Constructor Summary

AccessConstructor and Description
pack-priv
PoolThreadCache(PoolArena arena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
add(PoolArena area, PoolChunk chunk, long handle, int normCapacity, PoolArena.SizeClass sizeClass)

Add PoolChunk and handle to the cache if there is enough room.

private UntetheredMemory
pack-priv UntetheredMemory
allocateNormal(PoolArena area, int size, int sizeIdx)

Try to allocate a normal buffer out of the cache.

pack-priv UntetheredMemory
allocateSmall(int size, int sizeIdx)

Try to allocate a small buffer out of the cache.

private PoolThreadCache.MemoryRegionCache
cache(PoolArena area, int sizeIdx, PoolArena.SizeClass sizeClass)

private static PoolThreadCache.MemoryRegionCache
cache(PoolThreadCache.MemoryRegionCache[] cache, int sizeIdx)

private PoolThreadCache.MemoryRegionCache
cacheForNormal(PoolArena area, int sizeIdx)

private PoolThreadCache.MemoryRegionCache
cacheForSmall(int sizeIdx)

private static PoolThreadCache.MemoryRegionCache[]
createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena area)

private static PoolThreadCache.MemoryRegionCache[]
createSubPageCaches(int cacheSize, int numCaches)

pack-priv void
free()

Should be called if the Thread that uses this cache is about to exist to release resources out of the cache

private static int
private static int
pack-priv PoolArena
pack-priv static int
log2(int val)

pack-priv void
trim()

private static void
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationsback to summary
private int allocations
arenaback to summary
private final PoolArena arena
arenaReferenceCounterback to summary
pack-priv final AtomicInteger arenaReferenceCounter
freeSweepAllocationThresholdback to summary
private final int freeSweepAllocationThreshold
INTEGER_SIZE_MINUS_ONEback to summary
private static final int INTEGER_SIZE_MINUS_ONE
loggerback to summary
private static final InternalLogger logger
normalCachesback to summary
private final PoolThreadCache.MemoryRegionCache[] normalCaches
smallSubPageCachesback to summary
private final PoolThreadCache.MemoryRegionCache[] smallSubPageCaches

Constructor Detail

PoolThreadCacheback to summary
pack-priv PoolThreadCache(PoolArena arena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold)

Method Detail

addback to summary
pack-priv boolean add(PoolArena area, PoolChunk chunk, long handle, int normCapacity, PoolArena.SizeClass sizeClass)

Add PoolChunk and handle to the cache if there is enough room. Returns true if it fit into the cache false otherwise.

allocateback to summary
private UntetheredMemory allocate(PoolThreadCache.MemoryRegionCache cache, int size)
allocateNormalback to summary
pack-priv UntetheredMemory allocateNormal(PoolArena area, int size, int sizeIdx)

Try to allocate a normal buffer out of the cache. Returns true if successful false otherwise

allocateSmallback to summary
pack-priv UntetheredMemory allocateSmall(int size, int sizeIdx)

Try to allocate a small buffer out of the cache. Returns true if successful false otherwise

cacheback to summary
private PoolThreadCache.MemoryRegionCache cache(PoolArena area, int sizeIdx, PoolArena.SizeClass sizeClass)
cacheback to summary
private static PoolThreadCache.MemoryRegionCache cache(PoolThreadCache.MemoryRegionCache[] cache, int sizeIdx)
cacheForNormalback to summary
private PoolThreadCache.MemoryRegionCache cacheForNormal(PoolArena area, int sizeIdx)
cacheForSmallback to summary
private PoolThreadCache.MemoryRegionCache cacheForSmall(int sizeIdx)
createNormalCachesback to summary
private static PoolThreadCache.MemoryRegionCache[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena area)
createSubPageCachesback to summary
private static PoolThreadCache.MemoryRegionCache[] createSubPageCaches(int cacheSize, int numCaches)
freeback to summary
pack-priv void free()

Should be called if the Thread that uses this cache is about to exist to release resources out of the cache

freeback to summary
private static int free(PoolThreadCache.MemoryRegionCache[] caches)
freeback to summary
private static int free(PoolThreadCache.MemoryRegionCache cache)
getArenaback to summary
pack-priv PoolArena getArena()
log2back to summary
pack-priv static int log2(int val)
trimback to summary
pack-priv void trim()
trimback to summary
private static void trim(PoolThreadCache.MemoryRegionCache[] caches)
trimback to summary
private static void trim(PoolThreadCache.MemoryRegionCache cache)
io.netty5.buffer.pool back to summary

private abstract Class PoolThreadCache.MemoryRegionCache

extends Object
Class Inheritance
Known Direct Subclasses
io.netty5.buffer.pool.PoolThreadCache.SubPageMemoryRegionCache, io.netty5.buffer.pool.PoolThreadCache.NormalMemoryRegionCache

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private int
private final Queue<PoolThreadCache.MemoryRegionCache.Entry>
private static final ObjectPool<PoolThreadCache.MemoryRegionCache.Entry>
private final int
private final PoolArena.SizeClass

Constructor Summary

AccessConstructor and Description
pack-priv
MemoryRegionCache(int size, PoolArena.SizeClass sizeClass)

Method Summary

Modifier and TypeMethod and Description
public final boolean
add(PoolChunk chunk, long handle, int normCapacity)

Add to cache if not already full.

public final UntetheredMemory
allocate(int size, PoolThreadCache threadCache)

Allocate something out of the cache if possible and remove the entry from the cache.

protected abstract UntetheredMemory
allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.

public final int
free()

Clear out this cache and free up all previous cached PoolChunks and handles.

private int
free(int max)

private void
private static PoolThreadCache.MemoryRegionCache.Entry
newEntry(PoolChunk chunk, long handle, int normCapacity)

public final void
trim()

Free up cached PoolChunks if not allocated frequently enough.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationsback to summary
private int allocations
queueback to summary
private final Queue<PoolThreadCache.MemoryRegionCache.Entry> queue
RECYCLERback to summary
private static final ObjectPool<PoolThreadCache.MemoryRegionCache.Entry> RECYCLER
sizeback to summary
private final int size
sizeClassback to summary
private final PoolArena.SizeClass sizeClass

Constructor Detail

MemoryRegionCacheback to summary
pack-priv MemoryRegionCache(int size, PoolArena.SizeClass sizeClass)

Method Detail

addback to summary
public final boolean add(PoolChunk chunk, long handle, int normCapacity)

Add to cache if not already full.

allocateback to summary
public final UntetheredMemory allocate(int size, PoolThreadCache threadCache)

Allocate something out of the cache if possible and remove the entry from the cache.

allocBufback to summary
protected abstract UntetheredMemory allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.

freeback to summary
public final int free()

Clear out this cache and free up all previous cached PoolChunks and handles.

freeback to summary
private int free(int max)
freeEntryback to summary
private void freeEntry(PoolThreadCache.MemoryRegionCache.Entry entry)
newEntryback to summary
private static PoolThreadCache.MemoryRegionCache.Entry newEntry(PoolChunk chunk, long handle, int normCapacity)
trimback to summary
public final void trim()

Free up cached PoolChunks if not allocated frequently enough.

io.netty5.buffer.pool back to summary

pack-priv final Class PoolThreadCache.MemoryRegionCache.Entry

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.Entry

Field Summary

Modifier and TypeField and Description
pack-priv PoolChunk
pack-priv long
pack-priv int
pack-priv final ObjectPool.Handle<PoolThreadCache.MemoryRegionCache.Entry>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkback to summary
pack-priv PoolChunk chunk
handleback to summary
pack-priv long handle
normCapacityback to summary
pack-priv int normCapacity
recyclerHandleback to summary
pack-priv final ObjectPool.Handle<PoolThreadCache.MemoryRegionCache.Entry> recyclerHandle

Constructor Detail

Entryback to summary
pack-priv Entry(ObjectPool.Handle<PoolThreadCache.MemoryRegionCache.Entry> recyclerHandle)

Method Detail

recycleback to summary
pack-priv void recycle()
io.netty5.buffer.pool back to summary

private final Class PoolThreadCache.NormalMemoryRegionCache

extends MemoryRegionCache
Class Inheritance

Cache used for buffers which are backed by NORMAL size.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected UntetheredMemory
allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Implements abstract io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.
Inherited from io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache:
addallocatefreetrim

Constructor Detail

NormalMemoryRegionCacheback to summary
pack-priv NormalMemoryRegionCache(int size)

Method Detail

allocBufback to summary
protected UntetheredMemory allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Implements abstract io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Doc from io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.

Annotations
@Override
io.netty5.buffer.pool back to summary

private final Class PoolThreadCache.SubPageMemoryRegionCache

extends MemoryRegionCache
Class Inheritance

Cache used for buffers which are backed by SMALL size.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected UntetheredMemory
allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Implements abstract io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.
Inherited from io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache:
addallocatefreetrim

Constructor Detail

SubPageMemoryRegionCacheback to summary
pack-priv SubPageMemoryRegionCache(int size)

Method Detail

allocBufback to summary
protected UntetheredMemory allocBuf(PoolChunk chunk, long handle, int size, PoolThreadCache threadCache)

Implements abstract io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Doc from io.netty5.buffer.pool.PoolThreadCache.MemoryRegionCache.allocBuf.

Allocate a new UntetheredMemory using the provided chunk and handle with the capacity restrictions.

Annotations
@Override