Package io.netty.buffer
Class PoolThreadCache
- java.lang.Object
-
- io.netty.buffer.PoolThreadCache
-
final class PoolThreadCache extends java.lang.ObjectActs a Thread cache for allocations. This implementation is moduled after jemalloc and the descripted technics of Scalable memory allocation using jemalloc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPoolThreadCache.FreeOnFinalizeprivate static classPoolThreadCache.MemoryRegionCache<T>private static classPoolThreadCache.NormalMemoryRegionCache<T>Cache used for buffers which are backed by NORMAL size.private static classPoolThreadCache.SubPageMemoryRegionCache<T>Cache used for buffers which are backed by TINY or SMALL size.
-
Field Summary
Fields Modifier and Type Field Description private intallocations(package private) PoolArena<java.nio.ByteBuffer>directArenaprivate java.util.concurrent.atomic.AtomicBooleanfreedprivate PoolThreadCache.FreeOnFinalizefreeOnFinalizeprivate intfreeSweepAllocationThreshold(package private) PoolArena<byte[]>heapArenaprivate static intINTEGER_SIZE_MINUS_ONEprivate static InternalLoggerloggerprivate PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]normalDirectCachesprivate PoolThreadCache.MemoryRegionCache<byte[]>[]normalHeapCachesprivate PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]smallSubPageDirectCachesprivate PoolThreadCache.MemoryRegionCache<byte[]>[]smallSubPageHeapCaches
-
Constructor Summary
Constructors Constructor Description PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<java.nio.ByteBuffer> directArena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold, boolean useFinalizer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanadd(PoolArena<?> area, PoolChunk chunk, java.nio.ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass)AddPoolChunkandhandleto the cache if there is enough room.private booleanallocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity)(package private) booleanallocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)Try to allocate a normal buffer out of the cache.(package private) booleanallocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, 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 <T> PoolThreadCache.MemoryRegionCache<T>cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx)private PoolThreadCache.MemoryRegionCache<?>cacheForNormal(PoolArena<?> area, int sizeIdx)private PoolThreadCache.MemoryRegionCache<?>cacheForSmall(PoolArena<?> area, int sizeIdx)private static <T> PoolThreadCache.MemoryRegionCache<T>[]createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)private static <T> PoolThreadCache.MemoryRegionCache<T>[]createSubPageCaches(int cacheSize, int numCaches)(package private) voidfree(boolean finalizer)Should be called if the Thread that uses this cache is about to exit to release resources out of the cacheprivate static intfree(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)private static intfree(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)(package private) static intlog2(int val)(package private) voidtrim()private static voidtrim(PoolThreadCache.MemoryRegionCache<?> cache)private static voidtrim(PoolThreadCache.MemoryRegionCache<?>[] caches)
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
INTEGER_SIZE_MINUS_ONE
private static final int INTEGER_SIZE_MINUS_ONE
- See Also:
- Constant Field Values
-
heapArena
final PoolArena<byte[]> heapArena
-
directArena
final PoolArena<java.nio.ByteBuffer> directArena
-
smallSubPageHeapCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] smallSubPageHeapCaches
-
smallSubPageDirectCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] smallSubPageDirectCaches
-
normalHeapCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] normalHeapCaches
-
normalDirectCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] normalDirectCaches
-
freeSweepAllocationThreshold
private final int freeSweepAllocationThreshold
-
freed
private final java.util.concurrent.atomic.AtomicBoolean freed
-
freeOnFinalize
private final PoolThreadCache.FreeOnFinalize freeOnFinalize
-
allocations
private int allocations
-
-
Method Detail
-
createSubPageCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createSubPageCaches(int cacheSize, int numCaches)
-
createNormalCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)
-
log2
static int log2(int val)
-
allocateSmall
boolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)
Try to allocate a small buffer out of the cache. Returnstrueif successfulfalseotherwise
-
allocateNormal
boolean allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)
Try to allocate a normal buffer out of the cache. Returnstrueif successfulfalseotherwise
-
allocate
private boolean allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity)
-
add
boolean add(PoolArena<?> area, PoolChunk chunk, java.nio.ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass)
AddPoolChunkandhandleto the cache if there is enough room. Returnstrueif it fit into the cachefalseotherwise.
-
cache
private PoolThreadCache.MemoryRegionCache<?> cache(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass)
-
free
void free(boolean finalizer)
Should be called if the Thread that uses this cache is about to exit to release resources out of the cache
-
free
private static int free(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)
-
free
private static int free(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)
-
trim
void trim()
-
trim
private static void trim(PoolThreadCache.MemoryRegionCache<?>[] caches)
-
trim
private static void trim(PoolThreadCache.MemoryRegionCache<?> cache)
-
cacheForSmall
private PoolThreadCache.MemoryRegionCache<?> cacheForSmall(PoolArena<?> area, int sizeIdx)
-
cacheForNormal
private PoolThreadCache.MemoryRegionCache<?> cacheForNormal(PoolArena<?> area, int sizeIdx)
-
cache
private static <T> PoolThreadCache.MemoryRegionCache<T> cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx)
-
-