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.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 intfreeSweepAllocationThreshold(package private) PoolArena<byte[]>heapArenaprivate static intINTEGER_SIZE_MINUS_ONEprivate static InternalLoggerloggerprivate PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]normalDirectCachesprivate PoolThreadCache.MemoryRegionCache<byte[]>[]normalHeapCachesprivate intnumShiftsNormalDirectprivate intnumShiftsNormalHeapprivate PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]smallSubPageDirectCachesprivate PoolThreadCache.MemoryRegionCache<byte[]>[]smallSubPageHeapCachesprivate PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]tinySubPageDirectCachesprivate PoolThreadCache.MemoryRegionCache<byte[]>[]tinySubPageHeapCaches
-
Constructor Summary
Constructors Constructor Description PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<java.nio.ByteBuffer> directArena, int tinyCacheSize, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold)
-
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 normCapacity)Try to allocate a small buffer out of the cache.(package private) booleanallocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)Try to allocate a small buffer out of the cache.(package private) booleanallocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)Try to allocate a tiny buffer out of the cache.private PoolThreadCache.MemoryRegionCache<?>cache(PoolArena<?> area, int normCapacity, PoolArena.SizeClass sizeClass)private static <T> PoolThreadCache.MemoryRegionCache<T>cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int idx)private PoolThreadCache.MemoryRegionCache<?>cacheForNormal(PoolArena<?> area, int normCapacity)private PoolThreadCache.MemoryRegionCache<?>cacheForSmall(PoolArena<?> area, int normCapacity)private PoolThreadCache.MemoryRegionCache<?>cacheForTiny(PoolArena<?> area, int normCapacity)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, PoolArena.SizeClass sizeClass)protected voidfinalize()(package private) voidfree(boolean finalizer)Should be called if the Thread that uses this cache is about to exist to release resources out of the cacheprivate static intfree(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)private static intfree(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)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
-
tinySubPageHeapCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] tinySubPageHeapCaches
-
smallSubPageHeapCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] smallSubPageHeapCaches
-
tinySubPageDirectCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] tinySubPageDirectCaches
-
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
-
numShiftsNormalDirect
private final int numShiftsNormalDirect
-
numShiftsNormalHeap
private final int numShiftsNormalHeap
-
freeSweepAllocationThreshold
private final int freeSweepAllocationThreshold
-
freed
private final java.util.concurrent.atomic.AtomicBoolean freed
-
allocations
private int allocations
-
-
Method Detail
-
createSubPageCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createSubPageCaches(int cacheSize, int numCaches, PoolArena.SizeClass sizeClass)
-
createNormalCaches
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)
-
log2
private static int log2(int val)
-
allocateTiny
boolean allocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
Try to allocate a tiny buffer out of the cache. Returnstrueif successfulfalseotherwise
-
allocateSmall
boolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
Try to allocate a small buffer out of the cache. Returnstrueif successfulfalseotherwise
-
allocateNormal
boolean allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
Try to allocate a small 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 normCapacity, PoolArena.SizeClass sizeClass)
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
free
void free(boolean finalizer)
Should be called if the Thread that uses this cache is about to exist 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)
-
cacheForTiny
private PoolThreadCache.MemoryRegionCache<?> cacheForTiny(PoolArena<?> area, int normCapacity)
-
cacheForSmall
private PoolThreadCache.MemoryRegionCache<?> cacheForSmall(PoolArena<?> area, int normCapacity)
-
cacheForNormal
private PoolThreadCache.MemoryRegionCache<?> cacheForNormal(PoolArena<?> area, int normCapacity)
-
cache
private static <T> PoolThreadCache.MemoryRegionCache<T> cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int idx)
-
-