final class PoolThreadCache
extends java.lang.Object
Modifier and Type | Class and 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.
|
Modifier and Type | Field and Description |
---|---|
private int |
allocations |
(package private) PoolArena<java.nio.ByteBuffer> |
directArena |
private int |
freeSweepAllocationThreshold |
private java.lang.Runnable |
freeTask |
(package private) PoolArena<byte[]> |
heapArena |
private static InternalLogger |
logger |
private PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] |
normalDirectCaches |
private PoolThreadCache.MemoryRegionCache<byte[]>[] |
normalHeapCaches |
private int |
numShiftsNormalDirect |
private int |
numShiftsNormalHeap |
private PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] |
smallSubPageDirectCaches |
private PoolThreadCache.MemoryRegionCache<byte[]>[] |
smallSubPageHeapCaches |
private java.lang.Thread |
thread |
private PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] |
tinySubPageDirectCaches |
private PoolThreadCache.MemoryRegionCache<byte[]>[] |
tinySubPageHeapCaches |
Constructor and Description |
---|
PoolThreadCache(PoolArena<byte[]> heapArena,
PoolArena<java.nio.ByteBuffer> directArena,
int tinyCacheSize,
int smallCacheSize,
int normalCacheSize,
int maxCachedBufferCapacity,
int freeSweepAllocationThreshold) |
Modifier and Type | Method and Description |
---|---|
(package private) 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 boolean |
allocate(PoolThreadCache.MemoryRegionCache<?> cache,
PooledByteBuf buf,
int reqCapacity) |
(package private) boolean |
allocateNormal(PoolArena<?> area,
PooledByteBuf<?> buf,
int reqCapacity,
int normCapacity)
Try to allocate a small buffer out of the cache.
|
(package private) boolean |
allocateSmall(PoolArena<?> area,
PooledByteBuf<?> buf,
int reqCapacity,
int normCapacity)
Try to allocate a small buffer out of the cache.
|
(package private) boolean |
allocateTiny(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) |
(package private) 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 |
free(PoolThreadCache.MemoryRegionCache<?> cache) |
private static int |
free(PoolThreadCache.MemoryRegionCache<?>[] caches) |
private void |
free0() |
private static int |
log2(int val) |
(package private) void |
trim() |
private static void |
trim(PoolThreadCache.MemoryRegionCache<?> cache) |
private static void |
trim(PoolThreadCache.MemoryRegionCache<?>[] caches) |
private static final InternalLogger logger
final PoolArena<byte[]> heapArena
final PoolArena<java.nio.ByteBuffer> directArena
private final PoolThreadCache.MemoryRegionCache<byte[]>[] tinySubPageHeapCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] smallSubPageHeapCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] tinySubPageDirectCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] smallSubPageDirectCaches
private final PoolThreadCache.MemoryRegionCache<byte[]>[] normalHeapCaches
private final PoolThreadCache.MemoryRegionCache<java.nio.ByteBuffer>[] normalDirectCaches
private final int numShiftsNormalDirect
private final int numShiftsNormalHeap
private final int freeSweepAllocationThreshold
private int allocations
private final java.lang.Thread thread
private final java.lang.Runnable freeTask
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createSubPageCaches(int cacheSize, int numCaches, PoolArena.SizeClass sizeClass)
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)
private static int log2(int val)
boolean allocateTiny(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
true
if successful false
otherwiseboolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
true
if successful false
otherwiseboolean allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int normCapacity)
true
if successful false
otherwiseprivate boolean allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf buf, int reqCapacity)
boolean add(PoolArena<?> area, PoolChunk chunk, long handle, int normCapacity, PoolArena.SizeClass sizeClass)
PoolChunk
and handle
to the cache if there is enough room.
Returns true
if it fit into the cache false
otherwise.private PoolThreadCache.MemoryRegionCache<?> cache(PoolArena<?> area, int normCapacity, PoolArena.SizeClass sizeClass)
void free()
private void free0()
private static int free(PoolThreadCache.MemoryRegionCache<?>[] caches)
private static int free(PoolThreadCache.MemoryRegionCache<?> cache)
void trim()
private static void trim(PoolThreadCache.MemoryRegionCache<?>[] caches)
private static void trim(PoolThreadCache.MemoryRegionCache<?> cache)
private PoolThreadCache.MemoryRegionCache<?> cacheForTiny(PoolArena<?> area, int normCapacity)
private PoolThreadCache.MemoryRegionCache<?> cacheForSmall(PoolArena<?> area, int normCapacity)
private PoolThreadCache.MemoryRegionCache<?> cacheForNormal(PoolArena<?> area, int normCapacity)
private static <T> PoolThreadCache.MemoryRegionCache<T> cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int idx)