allocate() — netty Function Reference
Architecture documentation for the allocate() function in AdaptivePoolingAllocator.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b550a3a7_b98a_e36b_d58d_413aa6587ed4["allocate()"] 03ccb368_d6fc_bee6_64d5_0e674ae8c01f["Magazine"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|defined in| 03ccb368_d6fc_bee6_64d5_0e674ae8c01f 53fec213_35b7_be46_9b3d_b836bd574fc2["ByteBuf()"] 53fec213_35b7_be46_9b3d_b836bd574fc2 -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 546842cb_8674_f9d5_6751_ee84ff075ac8["AdaptiveByteBuf()"] 546842cb_8674_f9d5_6751_ee84ff075ac8 -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 1ffe8f20_ccfd_e36a_bc9a_a6eac8ef4ccf["reallocate()"] 1ffe8f20_ccfd_e36a_bc9a_a6eac8ef4ccf -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 080309e4_d57c_ce66_6f51_f105cc6f6710["AdaptiveByteBuf()"] 080309e4_d57c_ce66_6f51_f105cc6f6710 -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 d0801ddf_d578_d38b_f899_85d12408ceff["Chunk()"] d0801ddf_d578_d38b_f899_85d12408ceff -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 9e6dbf14_26ff_f501_00e5_f05f951e6c99["Chunk()"] 9e6dbf14_26ff_f501_00e5_f05f951e6c99 -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 4a58da3c_40d1_32f5_6976_57fdd64dc888["tryAllocate()"] 4a58da3c_40d1_32f5_6976_57fdd64dc888 -->|calls| b550a3a7_b98a_e36b_d58d_413aa6587ed4 33bb02aa_95f4_9821_7021_dcda1b551bd1["transferToNextInLineOrRelease()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| 33bb02aa_95f4_9821_7021_dcda1b551bd1 f4981826_99f5_bf62_b6e7_eb825c46476a["releaseFromMagazine()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| f4981826_99f5_bf62_b6e7_eb825c46476a 0a745cad_53b5_e976_8e80_cfe56a86673e["restoreMagazineFreed()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| 0a745cad_53b5_e976_8e80_cfe56a86673e 9d31fc3c_9011_6bf1_391a_b0388f8c5e8d["attachToMagazine()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| 9d31fc3c_9011_6bf1_391a_b0388f8c5e8d 4c60941e_e0a0_70ab_d9ff_1197fdd8f8d6["computeBufferCapacity()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| 4c60941e_e0a0_70ab_d9ff_1197fdd8f8d6 5b606370_5e08_94d5_b745_9c0ce73ce25a["readInitInto()"] b550a3a7_b98a_e36b_d58d_413aa6587ed4 -->|calls| 5b606370_5e08_94d5_b745_9c0ce73ce25a style b550a3a7_b98a_e36b_d58d_413aa6587ed4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java lines 898–995
private boolean allocate(int size, int maxCapacity, AdaptiveByteBuf buf, boolean reallocate) {
int startingCapacity = chunkController.computeBufferCapacity(size, maxCapacity, reallocate);
Chunk curr = current;
if (curr != null) {
boolean success = curr.readInitInto(buf, size, startingCapacity, maxCapacity);
int remainingCapacity = curr.remainingCapacity();
if (!success && remainingCapacity > 0) {
current = null;
transferToNextInLineOrRelease(curr);
} else if (remainingCapacity == 0) {
current = null;
curr.releaseFromMagazine();
}
if (success) {
return true;
}
}
assert current == null;
// The fast-path for allocations did not work.
//
// Try to fetch the next "Magazine local" Chunk first, if this fails because we don't have a
// next-in-line chunk available, we will poll our centralQueue.
// If this fails as well we will just allocate a new Chunk.
//
// In any case we will store the Chunk as the current so it will be used again for the next allocation and
// thus be "reserved" by this Magazine for exclusive usage.
curr = NEXT_IN_LINE.getAndSet(this, null);
if (curr != null) {
if (curr == MAGAZINE_FREED) {
// Allocation raced with a stripe-resize that freed this magazine.
restoreMagazineFreed();
return false;
}
int remainingCapacity = curr.remainingCapacity();
if (remainingCapacity > startingCapacity &&
curr.readInitInto(buf, size, startingCapacity, maxCapacity)) {
// We have a Chunk that has some space left.
current = curr;
return true;
}
try {
if (remainingCapacity >= size) {
// At this point we know that this will be the last time curr will be used, so directly set it
// to null and release it once we are done.
return curr.readInitInto(buf, size, remainingCapacity, maxCapacity);
}
} finally {
// Release in a finally block so even if readInitInto(...) would throw we would still correctly
// release the current chunk before null it out.
curr.releaseFromMagazine();
}
}
// Now try to poll from the central queue first
curr = group.pollChunk(size);
if (curr == null) {
curr = chunkController.newChunkAllocation(size, this);
} else {
curr.attachToMagazine(this);
int remainingCapacity = curr.remainingCapacity();
if (remainingCapacity == 0 || remainingCapacity < size) {
// Check if we either retain the chunk in the nextInLine cache or releasing it.
if (remainingCapacity < RETIRE_CAPACITY) {
curr.releaseFromMagazine();
} else {
// See if it makes sense to transfer the Chunk to the nextInLine cache for later usage.
// This method will release curr if this is not the case
transferToNextInLineOrRelease(curr);
}
curr = chunkController.newChunkAllocation(size, this);
}
}
current = curr;
boolean success;
try {
int remainingCapacity = curr.remainingCapacity();
Domain
Subdomains
Calls
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/AdaptivePoolingAllocator.java.
Where is allocate() defined?
allocate() is defined in buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java at line 898.
What does allocate() call?
allocate() calls 7 function(s): attachToMagazine, computeBufferCapacity, readInitInto, releaseFromMagazine, remainingCapacity, restoreMagazineFreed, transferToNextInLineOrRelease.
What calls allocate()?
allocate() is called by 7 function(s): AdaptiveByteBuf, AdaptiveByteBuf, ByteBuf, Chunk, Chunk, reallocate, tryAllocate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free