reallocate() — netty Function Reference
Architecture documentation for the reallocate() function in PoolArena.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd["reallocate()"] de926ba9_75e3_c416_27fc_3623234991a8["PoolArena"] 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd -->|defined in| de926ba9_75e3_c416_27fc_3623234991a8 2476a64f_8776_d678_76d8_c4cd7055f5df["allocate()"] 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd -->|calls| 2476a64f_8776_d678_76d8_c4cd7055f5df 1eb7867b_3257_ad29_cda0_1b8484056b67["free()"] 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd -->|calls| 1eb7867b_3257_ad29_cda0_1b8484056b67 8355ca1b_dc45_7413_2560_d7dae2ffa914["memoryCopy()"] 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd -->|calls| 8355ca1b_dc45_7413_2560_d7dae2ffa914 style 41f1f758_db84_9e73_7e23_6c7d6ad2b5dd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
buffer/src/main/java/io/netty/buffer/PoolArena.java lines 292–339
void reallocate(PooledByteBuf<T> buf, int newCapacity) {
assert newCapacity >= 0 && newCapacity <= buf.maxCapacity();
final int oldCapacity;
final PoolChunk<T> oldChunk;
final ByteBuffer oldNioBuffer;
final long oldHandle;
final T oldMemory;
final int oldOffset;
final int oldMaxLength;
final PoolThreadCache oldCache;
// We synchronize on the ByteBuf itself to ensure there is no "concurrent" reallocations for the same buffer.
// We do this to ensure the ByteBuf internal fields that are used to allocate / free are not accessed
// concurrently. This is important as otherwise we might end up corrupting our internal state of our data
// structures.
//
// Also note we don't use a Lock here but just synchronized even tho this might seem like a bad choice for Loom.
// This is done to minimize the overhead per ByteBuf. The time this would block another thread should be
// relative small and so not be a problem for Loom.
// See https://github.com/netty/netty/issues/13467
synchronized (buf) {
oldCapacity = buf.length;
if (oldCapacity == newCapacity) {
return;
}
oldChunk = buf.chunk;
oldNioBuffer = buf.tmpNioBuf;
oldHandle = buf.handle;
oldMemory = buf.memory;
oldOffset = buf.offset;
oldMaxLength = buf.maxLength;
oldCache = buf.cache;
// This does not touch buf's reader/writer indices
allocate(parent.threadCache(), buf, newCapacity);
}
int bytesToCopy;
if (newCapacity > oldCapacity) {
bytesToCopy = oldCapacity;
} else {
buf.trimIndicesToCapacity(newCapacity);
bytesToCopy = newCapacity;
}
memoryCopy(oldMemory, oldOffset, buf, bytesToCopy);
free(oldChunk, oldNioBuffer, oldHandle, oldMaxLength, oldCache);
}
Domain
Subdomains
Source
Frequently Asked Questions
What does reallocate() do?
reallocate() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolArena.java.
Where is reallocate() defined?
reallocate() is defined in buffer/src/main/java/io/netty/buffer/PoolArena.java at line 292.
What does reallocate() call?
reallocate() calls 3 function(s): allocate, free, memoryCopy.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free