PoolSubpage Class — netty Architecture
Architecture documentation for the PoolSubpage class in PoolSubpage.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD a6a571ea_fcf9_6eda_c073_f8d61fa999a3["PoolSubpage"] a239d055_926c_d33f_83f1_6f597d773fd3["PoolSubpage.java"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|defined in| a239d055_926c_d33f_83f1_6f597d773fd3 d80c37e0_c3bb_6ddc_a97d_06bcb91a58c6["PoolSubpage()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| d80c37e0_c3bb_6ddc_a97d_06bcb91a58c6 a871ec93_3c33_5694_cdf3_d9e756a2556c["allocate()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| a871ec93_3c33_5694_cdf3_d9e756a2556c 83bbb0dd_3188_7350_8354_910efc6a1ada["free()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 83bbb0dd_3188_7350_8354_910efc6a1ada 895e2ccf_f556_7741_93ea_be5be86704c9["addToPool()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 895e2ccf_f556_7741_93ea_be5be86704c9 ece8cfac_ec12_b1cc_40c7_2768a79012a6["removeFromPool()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| ece8cfac_ec12_b1cc_40c7_2768a79012a6 07ec09d1_e1cf_ca36_7a53_0a853eb310f7["setNextAvail()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 07ec09d1_e1cf_ca36_7a53_0a853eb310f7 c43f611b_3492_7c52_e24a_c4a5fff99a83["getNextAvail()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| c43f611b_3492_7c52_e24a_c4a5fff99a83 7ba71002_dc60_923d_b085_8336a9b1e977["findNextAvail()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 7ba71002_dc60_923d_b085_8336a9b1e977 391a2edf_8e57_4225_0fef_8f7afedb4997["findNextAvail0()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 391a2edf_8e57_4225_0fef_8f7afedb4997 d5c6d0c4_a94d_8d37_d027_53b9442f2238["toHandle()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| d5c6d0c4_a94d_8d37_d027_53b9442f2238 5528af64_365b_cd85_1ea3_8d857070ee91["String()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 5528af64_365b_cd85_1ea3_8d857070ee91 e56c04c1_3557_0046_2772_a391a5fdde8d["maxNumElements()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| e56c04c1_3557_0046_2772_a391a5fdde8d 72308e0f_b202_7963_ba3d_96078a06bcd6["numAvailable()"] a6a571ea_fcf9_6eda_c073_f8d61fa999a3 -->|method| 72308e0f_b202_7963_ba3d_96078a06bcd6
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/PoolSubpage.java lines 26–300
final class PoolSubpage<T> implements PoolSubpageMetric {
final PoolChunk<T> chunk;
final int elemSize;
private final int pageShifts;
private final int runOffset;
private final int runSize;
private final long[] bitmap;
private final int bitmapLength;
private final int maxNumElems;
final int headIndex;
PoolSubpage<T> prev;
PoolSubpage<T> next;
boolean doNotDestroy;
private int nextAvail;
private int numAvail;
final ReentrantLock lock;
// TODO: Test if adding padding helps under contention
//private long pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7;
/** Special constructor that creates a linked list head */
PoolSubpage(int headIndex) {
chunk = null;
lock = new ReentrantLock();
pageShifts = -1;
runOffset = -1;
elemSize = -1;
runSize = -1;
bitmap = null;
bitmapLength = -1;
maxNumElems = 0;
this.headIndex = headIndex;
}
PoolSubpage(PoolSubpage<T> head, PoolChunk<T> chunk, int pageShifts, int runOffset, int runSize, int elemSize) {
this.headIndex = head.headIndex;
this.chunk = chunk;
this.pageShifts = pageShifts;
this.runOffset = runOffset;
this.runSize = runSize;
this.elemSize = elemSize;
doNotDestroy = true;
maxNumElems = numAvail = runSize / elemSize;
int bitmapLength = maxNumElems >>> 6;
if ((maxNumElems & 63) != 0) {
bitmapLength ++;
}
this.bitmapLength = bitmapLength;
bitmap = new long[bitmapLength];
nextAvail = 0;
lock = null;
addToPool(head);
}
/**
* Returns the bitmap index of the subpage allocation.
*/
long allocate() {
if (numAvail == 0 || !doNotDestroy) {
return -1;
}
final int bitmapIdx = getNextAvail();
if (bitmapIdx < 0) {
removeFromPool(); // Subpage appear to be in an invalid state. Remove to prevent repeated errors.
throw new AssertionError("No next available bitmap index found (bitmapIdx = " + bitmapIdx + "), " +
"even though there are supposed to be (numAvail = " + numAvail + ") " +
"out of (maxNumElems = " + maxNumElems + ") available indexes.");
}
int q = bitmapIdx >>> 6;
int r = bitmapIdx & 63;
assert (bitmap[q] >>> r & 1) == 0;
bitmap[q] |= 1L << r;
Source
Frequently Asked Questions
What is the PoolSubpage class?
PoolSubpage is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolSubpage.java.
Where is PoolSubpage defined?
PoolSubpage is defined in buffer/src/main/java/io/netty/buffer/PoolSubpage.java at line 26.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free