Top Inners Fields Constructors Methods
io.netty.buffer

public Class PooledByteBufAllocator

extends AbstractByteBufAllocator
implements ByteBufAllocatorMetricProvider
Class Inheritance
All Implemented Interfaces
io.netty.buffer.ByteBufAllocatorMetricProvider
Static Imports
io.netty.util.internal.ObjectUtil.checkPositiveOrZero

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final int
private final int
public static final PooledByteBufAllocator
private static final int
private static final long
private static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final boolean
private final List<PoolArenaMetric>
private final PoolArena<ByteBuffer>[]
private final List<PoolArenaMetric>
private final PoolArena<byte[]>[]
private static final InternalLogger
private static final int
private final PooledByteBufAllocatorMetric
private static final int
private final int
private final int
private final PooledByteBufAllocator.PoolThreadLocalCache
private final Runnable
Inherited from io.netty.buffer.AbstractByteBufAllocator:
CALCULATE_THRESHOLDDEFAULT_INITIAL_CAPACITYDEFAULT_MAX_CAPACITYDEFAULT_MAX_COMPONENTS

Constructor Summary

AccessConstructor and Description
public
public
PooledByteBufAllocator(boolean preferDirect)

public
PooledByteBufAllocator(int nHeapArena, int nDirectArena, int pageSize, int maxOrder)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)

public
PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)

Method Summary

Modifier and TypeMethod and Description
public final int
chunkSize()

Return the chunk size for an arena.
public static int
defaultMaxOrder()

Default maximum order - System Property: io.netty.allocator.maxOrder - default 9

public static int
defaultNormalCacheSize()

Default normal cache size - System Property: io.netty.allocator.normalCacheSize - default 64

public static int
defaultNumDirectArena()

Default number of direct arenas - System Property: io.netty.allocator.numDirectArenas - default 2 * cores

public static int
defaultNumHeapArena()

Default number of heap arenas - System Property: io.netty.allocator.numHeapArenas - default 2 * cores

public static int
defaultPageSize()

Default buffer page size - System Property: io.netty.allocator.pageSize - default 8192

public static boolean
defaultPreferDirect()

Default prefer direct - System Property: io.netty.noPreferDirect - default false

public static int
defaultSmallCacheSize()

Default small cache size - System Property: io.netty.allocator.smallCacheSize - default 256

public static int
defaultTinyCacheSize()

Deprecated Tiny caches have been merged into small caches.
Default tiny cache size - default 0
public static boolean
defaultUseCacheForAllThreads()

Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default false

public List<PoolArenaMetric>
directArenas()

Return a List of all direct PoolArenaMetrics that are provided by this pool.
public String
dumpStats()

Returns the status of the allocator (which contains all metrics) as string.

public void
freeThreadLocalCache()

Deprecated will be removed Free all cached buffers for the calling Thread.
public boolean
hasThreadLocalCache()

Deprecated will be removed Returns true if the calling Thread has a ThreadLocal cache for the allocated buffers.
public List<PoolArenaMetric>
heapArenas()

Return a List of all heap PoolArenaMetrics that are provided by this pool.
public boolean
public static boolean
isDirectMemoryCacheAlignmentSupported()

Return true if direct memory cache alignment is supported, false otherwise.

public PooledByteBufAllocatorMetric
private static <T> PoolArena<T>[]
newArenaArray(int size)

protected ByteBuf
newDirectBuffer(int initialCapacity, int maxCapacity)

Implements abstract io.netty.buffer.AbstractByteBufAllocator.newDirectBuffer.

Create a direct ByteBuf with the given initialCapacity and maxCapacity.
protected ByteBuf
newHeapBuffer(int initialCapacity, int maxCapacity)

Implements abstract io.netty.buffer.AbstractByteBufAllocator.newHeapBuffer.

Create a heap ByteBuf with the given initialCapacity and maxCapacity.
public int
normalCacheSize()

Return the size of the normal cache.
public int
numDirectArenas()

Return the number of direct arenas.
public int
numHeapArenas()

Return the number of heap arenas.
public int
numThreadLocalCaches()

Return the number of thread local caches used by this PooledByteBufAllocator.
public final long
pinnedDirectMemory()

Returns the number of bytes of direct memory that is currently pinned to direct buffers allocated by a ByteBufAllocator, or -1 if unknown.

public final long
pinnedHeapMemory()

Returns the number of bytes of heap memory that is currently pinned to heap buffers allocated by a ByteBufAllocator, or -1 if unknown.

private static long
pinnedMemory(PoolArena<?>[] arenas)

public int
smallCacheSize()

Return the size of the small cache.
pack-priv final PoolThreadCache
public int
tinyCacheSize()

Return the size of the tiny cache.
public boolean
trimCurrentThreadCache()

Trim thread local cache for the current Thread, which will give back any cached memory that was not allocated frequently since the last trim operation.

pack-priv final long
pack-priv final long
private static long
usedMemory(PoolArena<?>[] arenas)

private static int
validateAndCalculateChunkSize(int pageSize, int maxOrder)

private static int
validateAndCalculatePageShifts(int pageSize, int alignment)

Inherited from io.netty.buffer.AbstractByteBufAllocator:
bufferbufferbuffercalculateNewCapacitycompositeBuffercompositeBuffercompositeDirectBuffercompositeDirectBuffercompositeHeapBuffercompositeHeapBufferdirectBufferdirectBufferdirectBufferheapBufferheapBufferheapBufferioBufferioBufferioBuffertoLeakAwareBuffertoLeakAwareBuffertoString

Field Detail

CACHE_NOT_USEDback to summary
private static final int CACHE_NOT_USED
chunkSizeback to summary
private final int chunkSize
DEFAULTback to summary
public static final PooledByteBufAllocator DEFAULT

Hides io.netty.buffer.ByteBufAllocator.DEFAULT.

DEFAULT_CACHE_TRIM_INTERVALback to summary
private static final int DEFAULT_CACHE_TRIM_INTERVAL
DEFAULT_CACHE_TRIM_INTERVAL_MILLISback to summary
private static final long DEFAULT_CACHE_TRIM_INTERVAL_MILLIS
DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENTback to summary
private static final int DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENT
DEFAULT_MAX_CACHED_BUFFER_CAPACITYback to summary
pack-priv static final int DEFAULT_MAX_CACHED_BUFFER_CAPACITY
DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNKback to summary
pack-priv static final int DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNK
DEFAULT_MAX_ORDERback to summary
private static final int DEFAULT_MAX_ORDER
DEFAULT_NORMAL_CACHE_SIZEback to summary
private static final int DEFAULT_NORMAL_CACHE_SIZE
DEFAULT_NUM_DIRECT_ARENAback to summary
private static final int DEFAULT_NUM_DIRECT_ARENA
DEFAULT_NUM_HEAP_ARENAback to summary
private static final int DEFAULT_NUM_HEAP_ARENA
DEFAULT_PAGE_SIZEback to summary
private static final int DEFAULT_PAGE_SIZE
DEFAULT_SMALL_CACHE_SIZEback to summary
private static final int DEFAULT_SMALL_CACHE_SIZE
DEFAULT_USE_CACHE_FOR_ALL_THREADSback to summary
private static final boolean DEFAULT_USE_CACHE_FOR_ALL_THREADS
directArenaMetricsback to summary
private final List<PoolArenaMetric> directArenaMetrics
directArenasback to summary
private final PoolArena<ByteBuffer>[] directArenas
heapArenaMetricsback to summary
private final List<PoolArenaMetric> heapArenaMetrics
heapArenasback to summary
private final PoolArena<byte[]>[] heapArenas
loggerback to summary
private static final InternalLogger logger
MAX_CHUNK_SIZEback to summary
private static final int MAX_CHUNK_SIZE
metricback to summary
private final PooledByteBufAllocatorMetric metric
MIN_PAGE_SIZEback to summary
private static final int MIN_PAGE_SIZE
normalCacheSizeback to summary
private final int normalCacheSize
smallCacheSizeback to summary
private final int smallCacheSize
threadCacheback to summary
private final PooledByteBufAllocator.PoolThreadLocalCache threadCache
trimTaskback to summary
private final Runnable trimTask

Constructor Detail

PooledByteBufAllocatorback to summary
public PooledByteBufAllocator()
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect)
Annotations
@SuppressWarnings:deprecation
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(int nHeapArena, int nDirectArena, int pageSize, int maxOrder)
Annotations
@SuppressWarnings:deprecation
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder)
Annotations
@Deprecated
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize)
Annotations
@Deprecated
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)
Annotations
@Deprecated
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads)
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)
Annotations
@Deprecated
PooledByteBufAllocatorback to summary
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)

Method Detail

chunkSizeback to summary
public final int chunkSize()

Return the chunk size for an arena.

Annotations
@Deprecated
defaultMaxOrderback to summary
public static int defaultMaxOrder()

Default maximum order - System Property: io.netty.allocator.maxOrder - default 9

defaultNormalCacheSizeback to summary
public static int defaultNormalCacheSize()

Default normal cache size - System Property: io.netty.allocator.normalCacheSize - default 64

defaultNumDirectArenaback to summary
public static int defaultNumDirectArena()

Default number of direct arenas - System Property: io.netty.allocator.numDirectArenas - default 2 * cores

defaultNumHeapArenaback to summary
public static int defaultNumHeapArena()

Default number of heap arenas - System Property: io.netty.allocator.numHeapArenas - default 2 * cores

defaultPageSizeback to summary
public static int defaultPageSize()

Default buffer page size - System Property: io.netty.allocator.pageSize - default 8192

defaultPreferDirectback to summary
public static boolean defaultPreferDirect()

Default prefer direct - System Property: io.netty.noPreferDirect - default false

defaultSmallCacheSizeback to summary
public static int defaultSmallCacheSize()

Default small cache size - System Property: io.netty.allocator.smallCacheSize - default 256

defaultTinyCacheSizeback to summary
public static int defaultTinyCacheSize()

Deprecated

Tiny caches have been merged into small caches.

Default tiny cache size - default 0

Annotations
@Deprecated
defaultUseCacheForAllThreadsback to summary
public static boolean defaultUseCacheForAllThreads()

Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default false

directArenasback to summary
public List<PoolArenaMetric> directArenas()

Return a List of all direct PoolArenaMetrics that are provided by this pool.

Annotations
@Deprecated
dumpStatsback to summary
public 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.

freeThreadLocalCacheback to summary
public void freeThreadLocalCache()

Deprecated

will be removed Free all cached buffers for the calling Thread.

Annotations
@Deprecated
hasThreadLocalCacheback to summary
public boolean hasThreadLocalCache()

Deprecated

will be removed Returns true if the calling Thread has a ThreadLocal cache for the allocated buffers.

Annotations
@Deprecated
heapArenasback to summary
public List<PoolArenaMetric> heapArenas()

Return a List of all heap PoolArenaMetrics that are provided by this pool.

Annotations
@Deprecated
isDirectBufferPooledback to summary
public boolean isDirectBufferPooled()

Implements io.netty.buffer.ByteBufAllocator.isDirectBufferPooled.

Doc from io.netty.buffer.ByteBufAllocator.isDirectBufferPooled.

Returns true if direct ByteBuf's are pooled

Annotations
@Override
isDirectMemoryCacheAlignmentSupportedback to summary
public static boolean isDirectMemoryCacheAlignmentSupported()

Return true if direct memory cache alignment is supported, false otherwise.

metricback to summary
public PooledByteBufAllocatorMetric metric()

Implements io.netty.buffer.ByteBufAllocatorMetricProvider.metric.

Doc from io.netty.buffer.ByteBufAllocatorMetricProvider.metric.

Returns a ByteBufAllocatorMetric for a ByteBufAllocator.

Annotations
@Override
newArenaArrayback to summary
private static <T> PoolArena<T>[] newArenaArray(int size)
Annotations
@SuppressWarnings:unchecked
newDirectBufferback to summary
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity)

Implements abstract io.netty.buffer.AbstractByteBufAllocator.newDirectBuffer.

Doc from io.netty.buffer.AbstractByteBufAllocator.newDirectBuffer.

Create a direct ByteBuf with the given initialCapacity and maxCapacity.

Annotations
@Override
newHeapBufferback to summary
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity)

Implements abstract io.netty.buffer.AbstractByteBufAllocator.newHeapBuffer.

Doc from io.netty.buffer.AbstractByteBufAllocator.newHeapBuffer.

Create a heap ByteBuf with the given initialCapacity and maxCapacity.

Annotations
@Override
normalCacheSizeback to summary
public int normalCacheSize()

Return the size of the normal cache.

Annotations
@Deprecated
numDirectArenasback to summary
public int numDirectArenas()

Return the number of direct arenas.

Annotations
@Deprecated
numHeapArenasback to summary
public int numHeapArenas()

Return the number of heap arenas.

Annotations
@Deprecated
numThreadLocalCachesback to summary
public int numThreadLocalCaches()

Return the number of thread local caches used by this PooledByteBufAllocator.

Annotations
@Deprecated
pinnedDirectMemoryback to summary
public final long pinnedDirectMemory()

Returns the number of bytes of direct memory that is currently pinned to direct buffers allocated by a ByteBufAllocator, or -1 if unknown. A buffer can pin more memory than its capacity might indicate, due to implementation details of the allocator.

pinnedHeapMemoryback to summary
public final long pinnedHeapMemory()

Returns the number of bytes of heap memory that is currently pinned to heap buffers allocated by a ByteBufAllocator, or -1 if unknown. A buffer can pin more memory than its capacity might indicate, due to implementation details of the allocator.

pinnedMemoryback to summary
private static long pinnedMemory(PoolArena<?>[] arenas)
smallCacheSizeback to summary
public int smallCacheSize()

Return the size of the small cache.

Annotations
@Deprecated
threadCacheback to summary
pack-priv final PoolThreadCache threadCache()
tinyCacheSizeback to summary
public int tinyCacheSize()

Return the size of the tiny cache.

Annotations
@Deprecated
trimCurrentThreadCacheback to summary
public boolean trimCurrentThreadCache()

Trim thread local cache for the current Thread, which will give back any cached memory that was not allocated frequently since the last trim operation. Returns true if a cache for the current Thread exists and so was trimmed, false otherwise.

usedDirectMemoryback to summary
pack-priv final long usedDirectMemory()
usedHeapMemoryback to summary
pack-priv final long usedHeapMemory()
usedMemoryback to summary
private static long usedMemory(PoolArena<?>[] arenas)
validateAndCalculateChunkSizeback to summary
private static int validateAndCalculateChunkSize(int pageSize, int maxOrder)
validateAndCalculatePageShiftsback to summary
private static int validateAndCalculatePageShifts(int pageSize, int alignment)
io.netty.buffer back to summary

private final Class PooledByteBufAllocator.PoolThreadLocalCache

extends FastThreadLocal<PoolThreadCache>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
PoolThreadLocalCache(boolean useCacheForAllThreads)

Method Summary

Modifier and TypeMethod and Description
protected synchronized PoolThreadCache
initialValue()

Overrides io.netty.util.concurrent.FastThreadLocal.initialValue.

Returns the initial value for this thread-local variable.
private <T> PoolArena<T>
protected void
onRemoval(PoolThreadCache threadCache)

Overrides io.netty.util.concurrent.FastThreadLocal.onRemoval.

Invoked when this thread local variable is removed by remove().
Inherited from io.netty.util.concurrent.FastThreadLocal:
destroygetgetgetIfExistsisSetisSetremoveremoveremoveAllsetsetsize

Field Detail

useCacheForAllThreadsback to summary
private final boolean useCacheForAllThreads

Constructor Detail

PoolThreadLocalCacheback to summary
pack-priv PoolThreadLocalCache(boolean useCacheForAllThreads)

Method Detail

initialValueback to summary
protected synchronized PoolThreadCache initialValue()

Overrides io.netty.util.concurrent.FastThreadLocal.initialValue.

Doc from io.netty.util.concurrent.FastThreadLocal.initialValue.

Returns the initial value for this thread-local variable.

Annotations
@Override
leastUsedArenaback to summary
private <T> PoolArena<T> leastUsedArena(PoolArena<T>[] arenas)
onRemovalback to summary
protected void onRemoval(PoolThreadCache threadCache)

Overrides io.netty.util.concurrent.FastThreadLocal.onRemoval.

Doc from io.netty.util.concurrent.FastThreadLocal.onRemoval.

Invoked when this thread local variable is removed by remove(). Be aware that remove() is not guaranteed to be called when the `Thread` completes which means you can not depend on this for cleanup of the resources in the case of `Thread` completion.

Annotations
@Override