Home / Class/ AlignedPooledByteBufAllocatorTest Class — netty Architecture

AlignedPooledByteBufAllocatorTest Class — netty Architecture

Architecture documentation for the AlignedPooledByteBufAllocatorTest class in AlignedPooledByteBufAllocatorTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c9134dc8_fd93_c39d_23b0_5a7607e27734["AlignedPooledByteBufAllocatorTest"]
  9a232f35_150e_d3a8_8af3_ffd32f408e34["AlignedPooledByteBufAllocatorTest.java"]
  c9134dc8_fd93_c39d_23b0_5a7607e27734 -->|defined in| 9a232f35_150e_d3a8_8af3_ffd32f408e34
  98e9fd03_54b3_2543_c93d_fcc6739e25e3["PooledByteBufAllocator()"]
  c9134dc8_fd93_c39d_23b0_5a7607e27734 -->|method| 98e9fd03_54b3_2543_c93d_fcc6739e25e3
  d83dc266_1c59_cff1_889e_aa5fd4449bbf["testCorrectElementSize()"]
  c9134dc8_fd93_c39d_23b0_5a7607e27734 -->|method| d83dc266_1c59_cff1_889e_aa5fd4449bbf
  894fa3c1_f240_ab16_8e00_0f1104ec04a9["testDirectSubpageReleaseLock()"]
  c9134dc8_fd93_c39d_23b0_5a7607e27734 -->|method| 894fa3c1_f240_ab16_8e00_0f1104ec04a9
  7544fc70_1ef8_cfbc_0e8a_918b0ce362ee["pooledByteBuf()"]
  c9134dc8_fd93_c39d_23b0_5a7607e27734 -->|method| 7544fc70_1ef8_cfbc_0e8a_918b0ce362ee

Relationship Graph

Source Code

buffer/src/test/java/io/netty/buffer/AlignedPooledByteBufAllocatorTest.java lines 27–136

public class AlignedPooledByteBufAllocatorTest extends PooledByteBufAllocatorTest {
    @Override
    protected PooledByteBufAllocator newAllocator(boolean preferDirect) {
        assumeTrue(PooledByteBufAllocator.isDirectMemoryCacheAlignmentSupported());
        int directMemoryCacheAlignment = 1;
        return new PooledByteBufAllocator(
                preferDirect,
                PooledByteBufAllocator.defaultNumHeapArena(),
                PooledByteBufAllocator.defaultNumDirectArena(),
                PooledByteBufAllocator.defaultPageSize(),
                11,
                PooledByteBufAllocator.defaultSmallCacheSize(),
                64,
                PooledByteBufAllocator.defaultUseCacheForAllThreads(),
                directMemoryCacheAlignment);
    }

    // https://github.com/netty/netty/issues/11955
    @Test
    public void testCorrectElementSize() {
        assumeTrue(PooledByteBufAllocator.isDirectMemoryCacheAlignmentSupported());
        ByteBufAllocator allocator = new PooledByteBufAllocator(
                true,
                PooledByteBufAllocator.defaultNumHeapArena(),
                PooledByteBufAllocator.defaultNumDirectArena(),
                PooledByteBufAllocator.defaultPageSize(),
                11,
                PooledByteBufAllocator.defaultSmallCacheSize(),
                64,
                PooledByteBufAllocator.defaultUseCacheForAllThreads(),
                64);

        ByteBuf a = allocator.directBuffer(0, 16384);
        ByteBuf b = allocator.directBuffer(0, 16384);
        a.capacity(16);
        assertEquals(16, a.capacity());
        b.capacity(16);
        assertEquals(16, b.capacity());
        a.capacity(17);
        assertEquals(17, a.capacity());
        b.capacity(18);
        assertEquals(18, b.capacity());
        assertTrue(a.release());
        assertTrue(b.release());
    }

    @Test
    public void testDirectSubpageReleaseLock() throws InterruptedException {
        assumeTrue(PooledByteBufAllocator.isDirectMemoryCacheAlignmentSupported());
        int initialCapacity = 0;
        int directMemoryCacheAlignment = 32;
        PooledByteBufAllocator allocator = new PooledByteBufAllocator(
                true,
                0,
                1,
                PooledByteBufAllocator.defaultPageSize(),
                PooledByteBufAllocator.defaultMaxOrder(),
                0,
                0,
                false,
                directMemoryCacheAlignment);

        final ByteBuf wrapper = allocator.directBuffer(initialCapacity, 16);
        PooledByteBuf<?> unwrapped = pooledByteBuf(wrapper);
        // Get the smallSubpagePools[] array in arena.
        @SuppressWarnings("unchecked")
        PoolSubpage<byte[]>[] smallSubpagePools = (PoolSubpage<byte[]>[]) unwrapped.chunk.arena.smallSubpagePools;
        PoolSubpage<byte[]> head = null;
        for (PoolSubpage<byte[]> subpage : smallSubpagePools) {
            if (subpage.next != subpage) {
                // Find the head subpage which the byteBuf belongs to.
                head = subpage;
                break;
            }
        }
        assertNotNull(head);
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                // Because the head subpage was already locked in the main thread, so this should hang and wait.
                wrapper.release();

Frequently Asked Questions

What is the AlignedPooledByteBufAllocatorTest class?
AlignedPooledByteBufAllocatorTest is a class in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/AlignedPooledByteBufAllocatorTest.java.
Where is AlignedPooledByteBufAllocatorTest defined?
AlignedPooledByteBufAllocatorTest is defined in buffer/src/test/java/io/netty/buffer/AlignedPooledByteBufAllocatorTest.java at line 27.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free