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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private final int
static final PooledByteBufAllocator
private static final int
private static final long
private static final int
private static final boolean
(package private) static final int
(package 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 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
Fields inherited from class io.netty.buffer.AbstractByteBufAllocator
CALCULATE_THRESHOLD, DEFAULT_INITIAL_CAPACITY, DEFAULT_MAX_CAPACITY, DEFAULT_MAX_COMPONENTS
-
Constructor Summary
ConstructorsConstructorDescriptionPooledByteBufAllocator
(boolean preferDirect) PooledByteBufAllocator
(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder) Deprecated.PooledByteBufAllocator
(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads) PooledByteBufAllocator
(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment) 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
Modifier and TypeMethodDescriptionfinal int
Deprecated.static boolean
Default control creation of PoolThreadCache finalizers for FastThreadLocalThreads - System Property: io.netty.allocator.disableCacheFinalizersForFastThreadLocalThreads - default falsestatic int
Default maximum order - System Property: io.netty.allocator.maxOrder - default 9static int
Default normal cache size - System Property: io.netty.allocator.normalCacheSize - default 64static int
Default number of direct arenas - System Property: io.netty.allocator.numDirectArenas - default 2 * coresstatic int
Default number of heap arenas - System Property: io.netty.allocator.numHeapArenas - default 2 * coresstatic int
Default buffer page size - System Property: io.netty.allocator.pageSize - default 8192static boolean
Default prefer direct - System Property: io.netty.noPreferDirect - default falsestatic int
Default small cache size - System Property: io.netty.allocator.smallCacheSize - default 256static int
Deprecated.Tiny caches have been merged into small caches.static boolean
Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default falseDeprecated.Returns the status of the allocator (which contains all metrics) as string.void
Deprecated.will be removed Free all cached buffers for the callingThread
.boolean
Deprecated.will be removed Returnstrue
if the callingThread
has aThreadLocal
cache for the allocated buffers.Deprecated.boolean
Returnstrue
if directByteBuf
's are pooledstatic boolean
Returntrue
if direct memory cache alignment is supported,false
otherwise.metric()
Returns aByteBufAllocatorMetric
for aByteBufAllocator
.private static <T> PoolArena<T>[]
newArenaArray
(int size) protected ByteBuf
newDirectBuffer
(int initialCapacity, int maxCapacity) Create a directByteBuf
with the given initialCapacity and maxCapacity.protected ByteBuf
newHeapBuffer
(int initialCapacity, int maxCapacity) Create a heapByteBuf
with the given initialCapacity and maxCapacity.int
Deprecated.int
Deprecated.int
Deprecated.int
Deprecated.private static int
numThreadLocalCaches
(PoolArena<?>[] arenas) final long
Returns the number of bytes of direct memory that is currently pinned to direct buffers allocated by aByteBufAllocator
, or-1
if unknown.final long
Returns the number of bytes of heap memory that is currently pinned to heap buffers allocated by aByteBufAllocator
, or-1
if unknown.private static long
pinnedMemory
(PoolArena<?>[] arenas) int
Deprecated.(package private) final PoolThreadCache
int
Deprecated.boolean
Trim thread local cache for the currentThread
, which will give back any cached memory that was not allocated frequently since the last trim operation.private static boolean
useCacheFinalizers
(Thread current) (package private) final long
(package private) final long
private static long
usedMemory
(PoolArena<?>[] arenas) private static int
validateAndCalculateChunkSize
(int pageSize, int maxOrder) private static int
validateAndCalculatePageShifts
(int pageSize, int alignment) 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 Details
-
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_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
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 -
DEFAULT_DISABLE_CACHE_FINALIZERS_FOR_FAST_THREAD_LOCAL_THREADS
private static final boolean DEFAULT_DISABLE_CACHE_FINALIZERS_FOR_FAST_THREAD_LOCAL_THREADS -
MIN_PAGE_SIZE
private static final int MIN_PAGE_SIZE- See Also:
-
MAX_CHUNK_SIZE
private static final int MAX_CHUNK_SIZE- See Also:
-
CACHE_NOT_USED
private static final int CACHE_NOT_USED- See Also:
-
trimTask
-
DEFAULT
-
heapArenas
-
directArenas
-
smallCacheSize
private final int smallCacheSize -
normalCacheSize
private final int normalCacheSize -
heapArenaMetrics
-
directArenaMetrics
-
threadCache
-
chunkSize
private final int chunkSize -
metric
-
-
Constructor Details
-
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
@Deprecated 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 smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads) -
PooledByteBufAllocator
@Deprecated public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int tinyCacheSize, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment) -
PooledByteBufAllocator
public PooledByteBufAllocator(boolean preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder, int smallCacheSize, int normalCacheSize, boolean useCacheForAllThreads, int directMemoryCacheAlignment)
-
-
Method Details
-
newArenaArray
-
validateAndCalculatePageShifts
private static int validateAndCalculatePageShifts(int pageSize, int alignment) -
validateAndCalculateChunkSize
private static int validateAndCalculateChunkSize(int pageSize, int maxOrder) -
newHeapBuffer
Description copied from class:AbstractByteBufAllocator
Create a heapByteBuf
with the given initialCapacity and maxCapacity.- Specified by:
newHeapBuffer
in classAbstractByteBufAllocator
-
newDirectBuffer
Description copied from class:AbstractByteBufAllocator
Create a directByteBuf
with the given initialCapacity and maxCapacity.- Specified by:
newDirectBuffer
in 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 9 -
defaultDisableCacheFinalizersForFastThreadLocalThreads
public static boolean defaultDisableCacheFinalizersForFastThreadLocalThreads()Default control creation of PoolThreadCache finalizers for FastThreadLocalThreads - System Property: io.netty.allocator.disableCacheFinalizersForFastThreadLocalThreads - default false -
defaultUseCacheForAllThreads
public static boolean defaultUseCacheForAllThreads()Default thread caching behavior - System Property: io.netty.allocator.useCacheForAllThreads - default false -
defaultPreferDirect
public static boolean defaultPreferDirect()Default prefer direct - System Property: io.netty.noPreferDirect - default false -
defaultTinyCacheSize
Deprecated.Tiny caches have been merged into small caches.Default tiny cache size - default 0 -
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()Returntrue
if direct memory cache alignment is supported,false
otherwise. -
isDirectBufferPooled
public boolean isDirectBufferPooled()Description copied from interface:ByteBufAllocator
Returnstrue
if directByteBuf
's are pooled- Specified by:
isDirectBufferPooled
in interfaceByteBufAllocator
-
hasThreadLocalCache
Deprecated.will be removed Returnstrue
if the callingThread
has aThreadLocal
cache for the allocated buffers. -
freeThreadLocalCache
Deprecated.will be removed Free all cached buffers for the callingThread
. -
useCacheFinalizers
-
metric
Description copied from interface:ByteBufAllocatorMetricProvider
Returns aByteBufAllocatorMetric
for aByteBufAllocator
.- Specified by:
metric
in interfaceByteBufAllocatorMetricProvider
-
numHeapArenas
Deprecated.Return the number of heap arenas. -
numDirectArenas
Deprecated.Return the number of direct arenas. -
heapArenas
Deprecated.Return aList
of all heapPoolArenaMetric
s that are provided by this pool. -
directArenas
Deprecated.Return aList
of all directPoolArenaMetric
s that are provided by this pool. -
numThreadLocalCaches
Deprecated.Return the number of thread local caches used by thisPooledByteBufAllocator
. -
numThreadLocalCaches
-
tinyCacheSize
Deprecated.Return the size of the tiny cache. -
smallCacheSize
Deprecated.Return the size of the small cache. -
normalCacheSize
Deprecated.Return the size of the normal cache. -
chunkSize
Deprecated.Return the chunk size for an arena. -
usedHeapMemory
final long usedHeapMemory() -
usedDirectMemory
final long usedDirectMemory() -
usedMemory
-
pinnedHeapMemory
public final long pinnedHeapMemory()Returns the number of bytes of heap memory that is currently pinned to heap buffers allocated by aByteBufAllocator
, or-1
if unknown. A buffer can pin more memory than its capacity might indicate, due to implementation details of the allocator. -
pinnedDirectMemory
public final long pinnedDirectMemory()Returns the number of bytes of direct memory that is currently pinned to direct buffers allocated by aByteBufAllocator
, or-1
if unknown. A buffer can pin more memory than its capacity might indicate, due to implementation details of the allocator. -
pinnedMemory
-
threadCache
-
trimCurrentThreadCache
public boolean trimCurrentThreadCache() -
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.
-
PooledByteBufAllocator(boolean, int, int, int, int, int, int, boolean)