PooledByteBufAllocator Class — netty Architecture
Architecture documentation for the PooledByteBufAllocator class in PooledByteBufAllocator.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a["PooledByteBufAllocator"] 07bd0cf0_220d_d51e_1919_92a58786c6c3["PooledByteBufAllocator.java"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|defined in| 07bd0cf0_220d_d51e_1919_92a58786c6c3 fd5b10b7_1fc6_6bf3_f94d_1c41e0794e60["PooledByteBufAllocator()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| fd5b10b7_1fc6_6bf3_f94d_1c41e0794e60 e956d2b7_55be_a178_cdd6_d78499ff2aae["newArenaArray()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| e956d2b7_55be_a178_cdd6_d78499ff2aae 138d7a28_a452_624b_555e_672c231e03df["validateAndCalculatePageShifts()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 138d7a28_a452_624b_555e_672c231e03df f7d2fc1b_621e_f2d6_a105_854aba5e1426["validateAndCalculateChunkSize()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| f7d2fc1b_621e_f2d6_a105_854aba5e1426 fac02def_c33a_d305_e617_e397f5a9d596["ByteBuf()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| fac02def_c33a_d305_e617_e397f5a9d596 90d2f6e7_fa1a_d172_29c4_d559bf706f34["defaultNumHeapArena()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 90d2f6e7_fa1a_d172_29c4_d559bf706f34 9215ca6c_ab51_c8e6_7dac_a0f0581271e6["defaultNumDirectArena()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 9215ca6c_ab51_c8e6_7dac_a0f0581271e6 6e3f3faa_46ba_17e4_1373_060c91d58963["defaultPageSize()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 6e3f3faa_46ba_17e4_1373_060c91d58963 157a00c9_4e15_2d72_0b8a_c7d050c5fed3["defaultMaxOrder()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 157a00c9_4e15_2d72_0b8a_c7d050c5fed3 c7d38000_cb45_ca26_163c_70a79bb1408b["defaultDisableCacheFinalizersForFastThreadLocalThreads()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| c7d38000_cb45_ca26_163c_70a79bb1408b 1b08329e_6a8d_f940_65d4_bac23f1b8318["defaultUseCacheForAllThreads()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 1b08329e_6a8d_f940_65d4_bac23f1b8318 18016bc9_ddd3_c60c_542a_ebd2372df802["defaultPreferDirect()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 18016bc9_ddd3_c60c_542a_ebd2372df802 043c7760_d2c7_370c_9aaa_be5f36baf7f5["defaultTinyCacheSize()"] f5ea31b4_1e4c_94f0_32cf_d4ab3e538b0a -->|method| 043c7760_d2c7_370c_9aaa_be5f36baf7f5
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java lines 38–859
public class PooledByteBufAllocator extends AbstractByteBufAllocator implements ByteBufAllocatorMetricProvider {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(PooledByteBufAllocator.class);
private static final int DEFAULT_NUM_HEAP_ARENA;
private static final int DEFAULT_NUM_DIRECT_ARENA;
private static final int DEFAULT_PAGE_SIZE;
private static final int DEFAULT_MAX_ORDER; // 8192 << 9 = 4 MiB per chunk
private static final int DEFAULT_SMALL_CACHE_SIZE;
private static final int DEFAULT_NORMAL_CACHE_SIZE;
static final int DEFAULT_MAX_CACHED_BUFFER_CAPACITY;
private static final int DEFAULT_CACHE_TRIM_INTERVAL;
private static final long DEFAULT_CACHE_TRIM_INTERVAL_MILLIS;
private static final boolean DEFAULT_USE_CACHE_FOR_ALL_THREADS;
private static final int DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENT;
static final int DEFAULT_MAX_CACHED_BYTEBUFFERS_PER_CHUNK;
private static final boolean DEFAULT_DISABLE_CACHE_FINALIZERS_FOR_FAST_THREAD_LOCAL_THREADS;
private static final int MIN_PAGE_SIZE = 4096;
private static final int MAX_CHUNK_SIZE = (int) (((long) Integer.MAX_VALUE + 1) / 2);
private static final int CACHE_NOT_USED = 0;
private final Runnable trimTask = new Runnable() {
@Override
public void run() {
PooledByteBufAllocator.this.trimCurrentThreadCache();
}
};
static {
int defaultAlignment = SystemPropertyUtil.getInt(
"io.netty.allocator.directMemoryCacheAlignment", 0);
int defaultPageSize = SystemPropertyUtil.getInt("io.netty.allocator.pageSize", 8192);
Throwable pageSizeFallbackCause = null;
try {
validateAndCalculatePageShifts(defaultPageSize, defaultAlignment);
} catch (Throwable t) {
pageSizeFallbackCause = t;
defaultPageSize = 8192;
defaultAlignment = 0;
}
DEFAULT_PAGE_SIZE = defaultPageSize;
DEFAULT_DIRECT_MEMORY_CACHE_ALIGNMENT = defaultAlignment;
int defaultMaxOrder = SystemPropertyUtil.getInt("io.netty.allocator.maxOrder", 9);
Throwable maxOrderFallbackCause = null;
try {
validateAndCalculateChunkSize(DEFAULT_PAGE_SIZE, defaultMaxOrder);
} catch (Throwable t) {
maxOrderFallbackCause = t;
defaultMaxOrder = 9;
}
DEFAULT_MAX_ORDER = defaultMaxOrder;
// Determine reasonable default for nHeapArena and nDirectArena.
// Assuming each arena has 3 chunks, the pool should not consume more than 50% of max memory.
final Runtime runtime = Runtime.getRuntime();
/*
* We use 2 * available processors by default to reduce contention as we use 2 * available processors for the
* number of EventLoops in NIO and EPOLL as well. If we choose a smaller number we will run into hot spots as
* allocation and de-allocation needs to be synchronized on the PoolArena.
*
* See https://github.com/netty/netty/issues/3888.
*/
final int defaultMinNumArena = NettyRuntime.availableProcessors() * 2;
final int defaultChunkSize = DEFAULT_PAGE_SIZE << DEFAULT_MAX_ORDER;
DEFAULT_NUM_HEAP_ARENA = Math.max(0,
SystemPropertyUtil.getInt(
"io.netty.allocator.numHeapArenas",
(int) Math.min(
defaultMinNumArena,
runtime.maxMemory() / defaultChunkSize / 2 / 3)));
DEFAULT_NUM_DIRECT_ARENA = Math.max(0,
SystemPropertyUtil.getInt(
"io.netty.allocator.numDirectArenas",
(int) Math.min(
defaultMinNumArena,
PlatformDependent.maxDirectMemory() / defaultChunkSize / 2 / 3)));
Source
Frequently Asked Questions
What is the PooledByteBufAllocator class?
PooledByteBufAllocator is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java.
Where is PooledByteBufAllocator defined?
PooledByteBufAllocator is defined in buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java at line 38.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free