PoolChunk Class — netty Architecture
Architecture documentation for the PoolChunk class in PoolChunk.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 271be16e_fb25_9fe6_0749_cf5dd80dd903["PoolChunk"] 2aa4db81_8b9f_1ed0_a972_9b33f1fd2742["PoolChunk.java"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|defined in| 2aa4db81_8b9f_1ed0_a972_9b33f1fd2742 da669453_f4ef_44ec_3f52_421ec821d319["PoolChunk()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| da669453_f4ef_44ec_3f52_421ec821d319 e4d6cf66_a04d_42c0_c24f_7b5cd6cb4301["newRunsAvailqueueArray()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| e4d6cf66_a04d_42c0_c24f_7b5cd6cb4301 9adde7b9_78be_7351_d13f_4b1e178b71e5["insertAvailRun()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 9adde7b9_78be_7351_d13f_4b1e178b71e5 0dee12bf_6c47_f5bd_c342_b34c9fa131ae["insertAvailRun0()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 0dee12bf_6c47_f5bd_c342_b34c9fa131ae 7a27929c_739b_b7b7_3775_2a30a6eff48c["removeAvailRun()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 7a27929c_739b_b7b7_3775_2a30a6eff48c 8ccbb357_1d7a_1dbd_9f91_87a4fb202fea["removeAvailRun0()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 8ccbb357_1d7a_1dbd_9f91_87a4fb202fea cc1fdb4b_5e81_2b82_0c3f_bcbcc4bc08ad["lastPage()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| cc1fdb4b_5e81_2b82_0c3f_bcbcc4bc08ad a2a90b64_46c7_8d33_34bc_ad92c06e2eca["getAvailRunByOffset()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| a2a90b64_46c7_8d33_34bc_ad92c06e2eca 079c9504_20dd_6c51_bbda_add63dd3286e["usage()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 079c9504_20dd_6c51_bbda_add63dd3286e dc4b66ae_8f51_844d_74c5_b56fbafe898a["allocate()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| dc4b66ae_8f51_844d_74c5_b56fbafe898a ff51bcad_2a8e_9ef1_b286_8e676953d24e["allocateRun()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| ff51bcad_2a8e_9ef1_b286_8e676953d24e f05ef488_130c_6bae_ae66_5e07522e80f9["calculateRunSize()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| f05ef488_130c_6bae_ae66_5e07522e80f9 96d34a61_1614_0158_28ca_09dcdd88e7ba["runFirstBestFit()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903 -->|method| 96d34a61_1614_0158_28ca_09dcdd88e7ba
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/PoolChunk.java lines 138–739
final class PoolChunk<T> implements PoolChunkMetric, ChunkInfo {
private static final int SIZE_BIT_LENGTH = 15;
private static final int INUSED_BIT_LENGTH = 1;
private static final int SUBPAGE_BIT_LENGTH = 1;
private static final int BITMAP_IDX_BIT_LENGTH = 32;
private static final boolean trackPinnedMemory =
SystemPropertyUtil.getBoolean("io.netty.trackPinnedMemory", true);
static final int IS_SUBPAGE_SHIFT = BITMAP_IDX_BIT_LENGTH;
static final int IS_USED_SHIFT = SUBPAGE_BIT_LENGTH + IS_SUBPAGE_SHIFT;
static final int SIZE_SHIFT = INUSED_BIT_LENGTH + IS_USED_SHIFT;
static final int RUN_OFFSET_SHIFT = SIZE_BIT_LENGTH + SIZE_SHIFT;
final PoolArena<T> arena;
final CleanableDirectBuffer cleanable;
final Object base;
final T memory;
final boolean unpooled;
/**
* store the first page and last page of each avail run
*/
private final LongLongHashMap runsAvailMap;
/**
* manage all avail runs
*/
private final IntPriorityQueue[] runsAvail;
private final ReentrantLock runsAvailLock;
/**
* manage all subpages in this chunk
*/
private final PoolSubpage<T>[] subpages;
/**
* Accounting of pinned memory – memory that is currently in use by ByteBuf instances.
*/
private final LongAdder pinnedBytes;
final int pageSize;
final int pageShifts;
final int chunkSize;
final int maxPageIdx;
// Use as cache for ByteBuffer created from the memory. These are just duplicates and so are only a container
// around the memory itself. These are often needed for operations within the Pooled*ByteBuf and so
// may produce extra GC, which can be greatly reduced by caching the duplicates.
//
// This may be null if the PoolChunk is unpooled as pooling the ByteBuffer instances does not make any sense here.
private final Deque<ByteBuffer> cachedNioBuffers;
int freeBytes;
PoolChunkList<T> parent;
PoolChunk<T> prev;
PoolChunk<T> next;
@SuppressWarnings("unchecked")
PoolChunk(PoolArena<T> arena, CleanableDirectBuffer cleanable, Object base, T memory, int pageSize, int pageShifts,
int chunkSize, int maxPageIdx) {
unpooled = false;
this.arena = arena;
this.cleanable = cleanable;
this.base = base;
this.memory = memory;
this.pageSize = pageSize;
this.pageShifts = pageShifts;
this.chunkSize = chunkSize;
this.maxPageIdx = maxPageIdx;
freeBytes = chunkSize;
runsAvail = newRunsAvailqueueArray(maxPageIdx);
runsAvailLock = new ReentrantLock();
runsAvailMap = new LongLongHashMap(-1);
subpages = new PoolSubpage[chunkSize >> pageShifts];
//insert initial run, offset = 0, pages = chunkSize / pageSize
int pages = chunkSize >> pageShifts;
Source
Frequently Asked Questions
What is the PoolChunk class?
PoolChunk is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java.
Where is PoolChunk defined?
PoolChunk is defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java at line 138.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free