AdaptiveByteBufAllocatorTest Class — netty Architecture
Architecture documentation for the AdaptiveByteBufAllocatorTest class in AdaptiveByteBufAllocatorTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b5780ec9_74a4_594b_4225_0099765d71e7["AdaptiveByteBufAllocatorTest"] 1cd8d534_bda0_13ad_4392_96c505943760["AdaptiveByteBufAllocatorTest.java"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|defined in| 1cd8d534_bda0_13ad_4392_96c505943760 f95f6269_707a_cb2d_e5c5_1293cb0ec01f["AdaptiveByteBufAllocator()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| f95f6269_707a_cb2d_e5c5_1293cb0ec01f efbe94da_0929_2626_e102_bdd8e91c281e["expectedUsedMemory()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| efbe94da_0929_2626_e102_bdd8e91c281e 0c6f4960_dec2_ed0f_496f_ce693e4cdbcc["expectedUsedMemoryAfterRelease()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| 0c6f4960_dec2_ed0f_496f_ce693e4cdbcc 880ef827_5088_554d_27e9_eeca3a9e6c0f["testUnsafeHeapBufferAndUnsafeDirectBuffer()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| 880ef827_5088_554d_27e9_eeca3a9e6c0f 1267f842_fd0c_2eb6_4ff1_b6b119a959e5["testUsedDirectMemory()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| 1267f842_fd0c_2eb6_4ff1_b6b119a959e5 a091f3e6_8ded_0778_c8db_a8ebbf1d76e9["testUsedHeapMemory()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| a091f3e6_8ded_0778_c8db_a8ebbf1d76e9 6b6bca45_42b2_d4bd_281f_847fcd857657["adaptiveChunkMustDeallocateOrReuseWthBufferRelease()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| 6b6bca45_42b2_d4bd_281f_847fcd857657 f90ce327_7a4c_ac41_919d_902b37c99bc5["sliceOrDuplicateUnwrapLetNotEscapeRootParent()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| f90ce327_7a4c_ac41_919d_902b37c99bc5 a9a9e47f_2501_5fdc_9861_3d014f4150af["testAllocateWithoutLock()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| a9a9e47f_2501_5fdc_9861_3d014f4150af b68f5dee_3c15_32f9_3d78_784ccf32ba71["jfrChunkAllocation()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| b68f5dee_3c15_32f9_3d78_784ccf32ba71 026a186e_7bf8_082c_39cf_6bffbbc8bec2["shouldCreateTwoChunks()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| 026a186e_7bf8_082c_39cf_6bffbbc8bec2 eec3917f_11d3_089b_d880_7f82ed0cde5d["shouldReuseTheSameChunk()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| eec3917f_11d3_089b_d880_7f82ed0cde5d aa2d00a0_08fb_4254_a909_8d9e0e915b76["jfrBufferAllocation()"] b5780ec9_74a4_594b_4225_0099765d71e7 -->|method| aa2d00a0_08fb_4254_a909_8d9e0e915b76
Relationship Graph
Source Code
buffer/src/test/java/io/netty/buffer/AdaptiveByteBufAllocatorTest.java lines 52–459
public class AdaptiveByteBufAllocatorTest extends AbstractByteBufAllocatorTest<AdaptiveByteBufAllocator> {
@Override
protected AdaptiveByteBufAllocator newAllocator(boolean preferDirect) {
return new AdaptiveByteBufAllocator(preferDirect);
}
@Override
protected AdaptiveByteBufAllocator newUnpooledAllocator() {
return newAllocator(false);
}
@Override
protected long expectedUsedMemory(AdaptiveByteBufAllocator allocator, int capacity) {
return 128 * 1024; // Min chunk size
}
@Override
protected long expectedUsedMemoryAfterRelease(AdaptiveByteBufAllocator allocator, int capacity) {
return 128 * 1024; // Min chunk size
}
@Override
@Test
public void testUnsafeHeapBufferAndUnsafeDirectBuffer() {
AdaptiveByteBufAllocator allocator = newUnpooledAllocator();
ByteBuf directBuffer = allocator.directBuffer();
assertInstanceOf(directBuffer, AdaptivePoolingAllocator.AdaptiveByteBuf.class);
assertTrue(directBuffer.isDirect());
directBuffer.release();
ByteBuf heapBuffer = allocator.heapBuffer();
assertInstanceOf(heapBuffer, AdaptivePoolingAllocator.AdaptiveByteBuf.class);
assertFalse(heapBuffer.isDirect());
heapBuffer.release();
}
@Override
@Test
public void testUsedDirectMemory() {
AdaptiveByteBufAllocator allocator = newAllocator(true);
ByteBufAllocatorMetric metric = allocator.metric();
assertEquals(0, metric.usedDirectMemory());
ByteBuf buffer = allocator.directBuffer(1024, 4096);
int capacity = buffer.capacity();
assertEquals(expectedUsedMemory(allocator, capacity), metric.usedDirectMemory());
// Double the size of the buffer
buffer.capacity(capacity << 1);
capacity = buffer.capacity();
// This is a new size class, and a new magazine with a new chunk
assertEquals(2 * expectedUsedMemory(allocator, capacity), metric.usedDirectMemory(), buffer.toString());
buffer.release();
// Memory is still held by the magazines
assertEquals(2 * expectedUsedMemory(allocator, capacity), metric.usedDirectMemory());
}
@Override
@Test
public void testUsedHeapMemory() {
AdaptiveByteBufAllocator allocator = newAllocator(true);
ByteBufAllocatorMetric metric = allocator.metric();
assertEquals(0, metric.usedHeapMemory());
ByteBuf buffer = allocator.heapBuffer(1024, 4096);
int capacity = buffer.capacity();
assertEquals(expectedUsedMemory(allocator, capacity), metric.usedHeapMemory());
// Double the size of the buffer
buffer.capacity(capacity << 1);
capacity = buffer.capacity();
// This is a new size class, and a new magazine with a new chunk
assertEquals(2 * expectedUsedMemory(allocator, capacity), metric.usedHeapMemory(), buffer.toString());
buffer.release();
// Memory is still held by the magazines
assertEquals(2 * expectedUsedMemory(allocator, capacity), metric.usedHeapMemory());
}
@Test
void adaptiveChunkMustDeallocateOrReuseWthBufferRelease() throws Exception {
AdaptiveByteBufAllocator allocator = newAllocator(false);
Source
Frequently Asked Questions
What is the AdaptiveByteBufAllocatorTest class?
AdaptiveByteBufAllocatorTest is a class in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/AdaptiveByteBufAllocatorTest.java.
Where is AdaptiveByteBufAllocatorTest defined?
AdaptiveByteBufAllocatorTest is defined in buffer/src/test/java/io/netty/buffer/AdaptiveByteBufAllocatorTest.java at line 52.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free