allocate() — netty Function Reference
Architecture documentation for the allocate() function in PoolChunk.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD dc4b66ae_8f51_844d_74c5_b56fbafe898a["allocate()"] 271be16e_fb25_9fe6_0749_cf5dd80dd903["PoolChunk"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|defined in| 271be16e_fb25_9fe6_0749_cf5dd80dd903 de510c10_913b_9792_3aa7_159e623d5dd8["allocateSubpage()"] de510c10_913b_9792_3aa7_159e623d5dd8 -->|calls| dc4b66ae_8f51_844d_74c5_b56fbafe898a 84c148a2_d160_9465_4de0_96875dcb9627["isSubpage()"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|calls| 84c148a2_d160_9465_4de0_96875dcb9627 0a6285e7_f5a0_2309_9441_672954c343b9["initBufWithSubpage()"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|calls| 0a6285e7_f5a0_2309_9441_672954c343b9 de510c10_913b_9792_3aa7_159e623d5dd8["allocateSubpage()"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|calls| de510c10_913b_9792_3aa7_159e623d5dd8 ff51bcad_2a8e_9ef1_b286_8e676953d24e["allocateRun()"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|calls| ff51bcad_2a8e_9ef1_b286_8e676953d24e 6dc0c69f_ef55_2ceb_be1e_ae840dbf3fed["initBuf()"] dc4b66ae_8f51_844d_74c5_b56fbafe898a -->|calls| 6dc0c69f_ef55_2ceb_be1e_ae840dbf3fed style dc4b66ae_8f51_844d_74c5_b56fbafe898a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/PoolChunk.java lines 325–368
boolean allocate(PooledByteBuf<T> buf, int reqCapacity, int sizeIdx, PoolThreadCache cache) {
final long handle;
if (sizeIdx <= arena.sizeClass.smallMaxSizeIdx) {
final PoolSubpage<T> nextSub;
// small
// Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it.
// This is need as we may add it back and so alter the linked-list structure.
PoolSubpage<T> head = arena.smallSubpagePools[sizeIdx];
head.lock();
try {
nextSub = head.next;
if (nextSub != head) {
assert nextSub.doNotDestroy && nextSub.elemSize == arena.sizeClass.sizeIdx2size(sizeIdx) :
"doNotDestroy=" + nextSub.doNotDestroy + ", elemSize=" + nextSub.elemSize + ", sizeIdx=" +
sizeIdx;
handle = nextSub.allocate();
assert handle >= 0;
assert isSubpage(handle);
nextSub.chunk.initBufWithSubpage(buf, null, handle, reqCapacity, cache, false);
return true;
}
handle = allocateSubpage(sizeIdx, head);
if (handle < 0) {
return false;
}
assert isSubpage(handle);
} finally {
head.unlock();
}
} else {
// normal
// runSize must be multiple of pageSize
int runSize = arena.sizeClass.sizeIdx2size(sizeIdx);
handle = allocateRun(runSize);
if (handle < 0) {
return false;
}
assert !isSubpage(handle);
}
ByteBuffer nioBuffer = cachedNioBuffers != null? cachedNioBuffers.pollLast() : null;
initBuf(buf, nioBuffer, handle, reqCapacity, cache, false);
return true;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does allocate() do?
allocate() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java.
Where is allocate() defined?
allocate() is defined in buffer/src/main/java/io/netty/buffer/PoolChunk.java at line 325.
What does allocate() call?
allocate() calls 5 function(s): allocateRun, allocateSubpage, initBuf, initBufWithSubpage, isSubpage.
What calls allocate()?
allocate() is called by 1 function(s): allocateSubpage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free