Package io.netty.buffer
Class PoolThreadCache
- java.lang.Object
-
- io.netty.buffer.PoolArenasCache
-
- io.netty.buffer.PoolThreadCache
-
final class PoolThreadCache extends PoolArenasCache
Acts 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 class
PoolThreadCache.MemoryRegionCache<T>
private static class
PoolThreadCache.NormalMemoryRegionCache<T>
Cache used for buffers which are backed by NORMAL size.private static class
PoolThreadCache.SubPageMemoryRegionCache<T>
Cache used for buffers which are backed by TINY or SMALL size.
-
Field Summary
Fields Modifier and Type Field Description private int
allocations
private java.util.concurrent.atomic.AtomicBoolean
freed
private int
freeSweepAllocationThreshold
private static InternalLogger
logger
private PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]
normalDirectCaches
private PoolThreadCache.MemoryRegionCache<byte[]>[]
normalHeapCaches
private PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[]
smallSubPageDirectCaches
private PoolThreadCache.MemoryRegionCache<byte[]>[]
smallSubPageHeapCaches
-
Fields inherited from class io.netty.buffer.PoolArenasCache
directArena, heapArena
-
-
Constructor Summary
Constructors Constructor Description PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<java.nio.ByteBuffer> directArena, 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) boolean
add(PoolArena<?> area, PoolChunk chunk, java.nio.ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass)
AddPoolChunk
andhandle
to the cache if there is enough room.private boolean
allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity)
(package private) boolean
allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)
Try to allocate a normal buffer out of the cache.(package private) boolean
allocateSmall(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 void
checkCacheMayLeak(PoolThreadCache.MemoryRegionCache<?>[] caches, java.lang.String type)
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)
protected void
finalize()
(package private) void
free(boolean finalizer)
Should be called if the Thread that uses this cache is about to exist to release resources out of the cacheprivate static int
free(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)
private static int
free(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)
(package private) void
trim()
private static void
trim(PoolThreadCache.MemoryRegionCache<?> cache)
private static void
trim(PoolThreadCache.MemoryRegionCache<?>[] caches)
-
Methods inherited from class io.netty.buffer.PoolArenasCache
log2
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
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
-
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)
-
allocateSmall
boolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)
Try to allocate a small buffer out of the cache. Returnstrue
if successfulfalse
otherwise- Overrides:
allocateSmall
in classPoolArenasCache
-
allocateNormal
boolean allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)
Try to allocate a normal buffer out of the cache. Returnstrue
if successfulfalse
otherwise- Overrides:
allocateNormal
in classPoolArenasCache
-
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)
AddPoolChunk
andhandle
to the cache if there is enough room. Returnstrue
if it fit into the cachefalse
otherwise.- Overrides:
add
in classPoolArenasCache
-
cache
private PoolThreadCache.MemoryRegionCache<?> cache(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass)
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in 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- Overrides:
free
in classPoolArenasCache
-
checkCacheMayLeak
private static void checkCacheMayLeak(PoolThreadCache.MemoryRegionCache<?>[] caches, java.lang.String type)
-
free
private static int free(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)
-
free
private static int free(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)
-
trim
void trim()
- Overrides:
trim
in classPoolArenasCache
-
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)
-
-