Package io.netty.buffer
Class PooledByteBufAllocator
- java.lang.Object
-
- io.netty.buffer.AbstractByteBufAllocator
-
- io.netty.buffer.PooledByteBufAllocator
-
- All Implemented Interfaces:
ByteBufAllocator,ByteBufAllocatorMetricProvider
public class PooledByteBufAllocator extends AbstractByteBufAllocator implements ByteBufAllocatorMetricProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classPooledByteBufAllocator.PoolThreadLocalCache
-
Field Summary
-
Fields inherited from class io.netty.buffer.AbstractByteBufAllocator
CALCULATE_THRESHOLD, DEFAULT_INITIAL_CAPACITY, DEFAULT_MAX_CAPACITY, DEFAULT_MAX_COMPONENTS
-
-
Constructor Summary
Constructors Constructor Description PooledByteBufAllocator()PooledByteBufAllocator(boolean preferDirect)PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder)PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize)PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)PooledByteBufAllocator(int nHeapArena, int nDirectArena, int pageSize, int maxOrder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intchunkSize()Deprecated.static intdefaultMaxOrder()Default maximum order - System Property: io.netty.allocator.maxOrder - default 11static intdefaultNormalCacheSize()Default normal cache size - System Property: io.netty.allocator.normalCacheSize - default 64static intdefaultNumDirectArena()Default number of direct arenas - System Property: io.netty.allocator.numDirectArenas - default 2 * coresstatic intdefaultNumHeapArena()Default number of heap arenas - System Property: io.netty.allocator.numHeapArenas - default 2 * coresstatic intdefaultPageSize()Default buffer page size - System Property: io.netty.allocator.pageSize - default 8192static booleandefaultPreferDirect()Default prefer direct - System Property: io.netty.noPreferDirect - default falsestatic intdefaultSmallCacheSize()Default small cache size - System Property: io.netty.allocator.smallCacheSize - default 256static intdefaultTinyCacheSize()Default tiny cache size - System Property: io.netty.allocator.tinyCacheSize - default 512static booleandefaultUseCacheForAllThreads()Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default truejava.util.List<PoolArenaMetric>directArenas()Deprecated.java.lang.StringdumpStats()Returns the status of the allocator (which contains all metrics) as string.voidfreeThreadLocalCache()Deprecated.booleanhasThreadLocalCache()Deprecated.java.util.List<PoolArenaMetric>heapArenas()Deprecated.booleanisDirectBufferPooled()Returnstrueif directByteBuf's are pooledstatic booleanisDirectMemoryCacheAlignmentSupported()Returntrueif direct memory cache alignment is supported,falseotherwise.PooledByteBufAllocatorMetricmetric()Returns aByteBufAllocatorMetricfor aByteBufAllocator.private static <T> PoolArena<T>[]newArenaArray(int size)protected ByteBufnewDirectBuffer(int initialCapacity, int maxCapacity)Create a directByteBufwith the given initialCapacity and maxCapacity.protected ByteBufnewHeapBuffer(int initialCapacity, int maxCapacity)Create a heapByteBufwith the given initialCapacity and maxCapacity.intnormalCacheSize()Deprecated.intnumDirectArenas()Deprecated.intnumHeapArenas()Deprecated.intnumThreadLocalCaches()Deprecated.intsmallCacheSize()Deprecated.(package private) PoolThreadCachethreadCache()inttinyCacheSize()Deprecated.booleantrimCurrentThreadCache()Trim thread local cache for the currentThread, which will give back any cached memory that was not allocated frequently since the last trim operation.(package private) longusedDirectMemory()(package private) longusedHeapMemory()private static longusedMemory(PoolArena<?>[] arenas)private static intvalidateAndCalculateChunkSize(int pageSize, int maxOrder)private static intvalidateAndCalculatePageShifts(int pageSize)-
Methods inherited from class io.netty.buffer.AbstractByteBufAllocator
buffer, buffer, buffer, calculateNewCapacity, compositeBuffer, compositeBuffer, compositeDirectBuffer, compositeDirectBuffer, compositeHeapBuffer, compositeHeapBuffer, directBuffer, directBuffer, directBuffer, heapBuffer, heapBuffer, heapBuffer, ioBuffer, ioBuffer, ioBuffer, toLeakAwareBuffer, toLeakAwareBuffer, toString
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
DEFAULT_NUM_HEAP_ARENA
private static final int DEFAULT_NUM_HEAP_ARENA
-
DEFAULT_NUM_DIRECT_ARENA
private static final int DEFAULT_NUM_DIRECT_ARENA
-
DEFAULT_PAGE_SIZE
private static final int DEFAULT_PAGE_SIZE
-
DEFAULT_MAX_ORDER
private static final int DEFAULT_MAX_ORDER
-
DEFAULT_TINY_CACHE_SIZE
private static final int DEFAULT_TINY_CACHE_SIZE
-
DEFAULT_SMALL_CACHE_SIZE
private static final int DEFAULT_SMALL_CACHE_SIZE
-
DEFAULT_NORMAL_CACHE_SIZE
private static final int DEFAULT_NORMAL_CACHE_SIZE
-
DEFAULT_MAX_CACHED_BUFFER_CAPACITY
private static final int DEFAULT_MAX_CACHED_BUFFER_CAPACITY
-
DEFAULT_CACHE_TRIM_INTERVAL
private static final int DEFAULT_CACHE_TRIM_INTERVAL
-
DEFAULT_CACHE_TRIM_INTERVAL_MILLIS
private static final long DEFAULT_CACHE_TRIM_INTERVAL_MILLIS
-
DEFAULT_USE_CACHE_FOR_ALL_THREADS
private static final boolean DEFAULT_USE_CACHE_FOR_ALL_THREADS
-
DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENT
private static final int DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENT
-
DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNK
static final int DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNK
-
MIN_PAGE_SIZE
private static final int MIN_PAGE_SIZE
- See Also:
- Constant Field Values
-
MAX_CHUNK_SIZE
private static final int MAX_CHUNK_SIZE
- See Also:
- Constant Field Values
-
trimTask
private final java.lang.Runnable trimTask
-
DEFAULT
public static final PooledByteBufAllocator DEFAULT
-
heapArenas
private final PoolArena<byte[]>[] heapArenas
-
directArenas
private final PoolArena<java.nio.ByteBuffer>[] directArenas
-
tinyCacheSize
private final int tinyCacheSize
-
smallCacheSize
private final int smallCacheSize
-
normalCacheSize
private final int normalCacheSize
-
heapArenaMetrics
private final java.util.List<PoolArenaMetric> heapArenaMetrics
-
directArenaMetrics
private final java.util.List<PoolArenaMetric> directArenaMetrics
-
threadCache
private final PooledByteBufAllocator.PoolThreadLocalCache threadCache
-
chunkSize
private final int chunkSize
-
metric
private final PooledByteBufAllocatorMetric metric
-
-
Constructor Detail
-
PooledByteBufAllocator
public PooledByteBufAllocator()
-
PooledByteBufAllocator
public PooledByteBufAllocator(boolean preferDirect)
-
PooledByteBufAllocator
public PooledByteBufAllocator(int nHeapArena, int nDirectArena, int pageSize, int maxOrder)
-
PooledByteBufAllocator
@Deprecated public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder)
-
PooledByteBufAllocator
@Deprecated public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize)
-
PooledByteBufAllocator
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)
-
PooledByteBufAllocator
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)
-
-
Method Detail
-
newArenaArray
private static <T> PoolArena<T>[] newArenaArray(int size)
-
validateAndCalculatePageShifts
private static int validateAndCalculatePageShifts(int pageSize)
-
validateAndCalculateChunkSize
private static int validateAndCalculateChunkSize(int pageSize, int maxOrder)
-
newHeapBuffer
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity)
Description copied from class:AbstractByteBufAllocatorCreate a heapByteBufwith the given initialCapacity and maxCapacity.- Specified by:
newHeapBufferin classAbstractByteBufAllocator
-
newDirectBuffer
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity)
Description copied from class:AbstractByteBufAllocatorCreate a directByteBufwith the given initialCapacity and maxCapacity.- Specified by:
newDirectBufferin classAbstractByteBufAllocator
-
defaultNumHeapArena
public static int defaultNumHeapArena()
Default number of heap arenas - System Property: io.netty.allocator.numHeapArenas - default 2 * cores
-
defaultNumDirectArena
public static int defaultNumDirectArena()
Default number of direct arenas - System Property: io.netty.allocator.numDirectArenas - default 2 * cores
-
defaultPageSize
public static int defaultPageSize()
Default buffer page size - System Property: io.netty.allocator.pageSize - default 8192
-
defaultMaxOrder
public static int defaultMaxOrder()
Default maximum order - System Property: io.netty.allocator.maxOrder - default 11
-
defaultUseCacheForAllThreads
public static boolean defaultUseCacheForAllThreads()
Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default true
-
defaultPreferDirect
public static boolean defaultPreferDirect()
Default prefer direct - System Property: io.netty.noPreferDirect - default false
-
defaultTinyCacheSize
public static int defaultTinyCacheSize()
Default tiny cache size - System Property: io.netty.allocator.tinyCacheSize - default 512
-
defaultSmallCacheSize
public static int defaultSmallCacheSize()
Default small cache size - System Property: io.netty.allocator.smallCacheSize - default 256
-
defaultNormalCacheSize
public static int defaultNormalCacheSize()
Default normal cache size - System Property: io.netty.allocator.normalCacheSize - default 64
-
isDirectMemoryCacheAlignmentSupported
public static boolean isDirectMemoryCacheAlignmentSupported()
Returntrueif direct memory cache alignment is supported,falseotherwise.
-
isDirectBufferPooled
public boolean isDirectBufferPooled()
Description copied from interface:ByteBufAllocatorReturnstrueif directByteBuf's are pooled- Specified by:
isDirectBufferPooledin interfaceByteBufAllocator
-
hasThreadLocalCache
@Deprecated public boolean hasThreadLocalCache()
Deprecated.Returnstrueif the callingThreadhas aThreadLocalcache for the allocated buffers.
-
freeThreadLocalCache
@Deprecated public void freeThreadLocalCache()
Deprecated.Free all cached buffers for the callingThread.
-
metric
public PooledByteBufAllocatorMetric metric()
Description copied from interface:ByteBufAllocatorMetricProviderReturns aByteBufAllocatorMetricfor aByteBufAllocator.- Specified by:
metricin interfaceByteBufAllocatorMetricProvider
-
numHeapArenas
@Deprecated public int numHeapArenas()
Deprecated.Return the number of heap arenas.
-
numDirectArenas
@Deprecated public int numDirectArenas()
Deprecated.Return the number of direct arenas.
-
heapArenas
@Deprecated public java.util.List<PoolArenaMetric> heapArenas()
Deprecated.Return aListof all heapPoolArenaMetrics that are provided by this pool.
-
directArenas
@Deprecated public java.util.List<PoolArenaMetric> directArenas()
Deprecated.Return aListof all directPoolArenaMetrics that are provided by this pool.
-
numThreadLocalCaches
@Deprecated public int numThreadLocalCaches()
Deprecated.Return the number of thread local caches used by thisPooledByteBufAllocator.
-
tinyCacheSize
@Deprecated public int tinyCacheSize()
Deprecated.Return the size of the tiny cache.
-
smallCacheSize
@Deprecated public int smallCacheSize()
Deprecated.Return the size of the small cache.
-
normalCacheSize
@Deprecated public int normalCacheSize()
Deprecated.Return the size of the normal cache.
-
chunkSize
@Deprecated public final int chunkSize()
Deprecated.Return the chunk size for an arena.
-
usedHeapMemory
final long usedHeapMemory()
-
usedDirectMemory
final long usedDirectMemory()
-
usedMemory
private static long usedMemory(PoolArena<?>[] arenas)
-
threadCache
final PoolThreadCache threadCache()
-
trimCurrentThreadCache
public boolean trimCurrentThreadCache()
Trim thread local cache for the currentThread, which will give back any cached memory that was not allocated frequently since the last trim operation. Returnstrueif a cache for the currentThreadexists and so was trimmed, false otherwise.
-
dumpStats
public java.lang.String dumpStats()
Returns the status of the allocator (which contains all metrics) as string. Be aware this may be expensive and so should not called too frequently.
-
-