Home / Class/ PoolArena Class — netty Architecture

PoolArena Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  de926ba9_75e3_c416_27fc_3623234991a8["PoolArena"]
  22b08479_a3b8_e618_f86f_ad3544d470e6["PoolArena.java"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|defined in| 22b08479_a3b8_e618_f86f_ad3544d470e6
  17b79010_1dee_e435_b063_90886c597d99["PoolArena()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 17b79010_1dee_e435_b063_90886c597d99
  679689ff_c4d8_2796_d7c8_3eab9837e8d1["newSubpagePoolHead()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 679689ff_c4d8_2796_d7c8_3eab9837e8d1
  42db709d_8bab_ffd6_4e33_603bab3b591a["newSubpagePoolArray()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 42db709d_8bab_ffd6_4e33_603bab3b591a
  802c13ed_8807_41f7_3cd5_7ba40059ceae["isDirect()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 802c13ed_8807_41f7_3cd5_7ba40059ceae
  2476a64f_8776_d678_76d8_c4cd7055f5df["allocate()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 2476a64f_8776_d678_76d8_c4cd7055f5df
  027331c1_1487_71f3_a618_b8048be0dc49["tcacheAllocateSmall()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 027331c1_1487_71f3_a618_b8048be0dc49
  9d7444f8_13af_6f9e_5d68_ab65ea53497c["tcacheAllocateNormal()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 9d7444f8_13af_6f9e_5d68_ab65ea53497c
  b23f2b6f_d095_a24d_02b5_3cce432b929b["allocateNormal()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| b23f2b6f_d095_a24d_02b5_3cce432b929b
  c0b7dab6_60ff_7674_6101_0df52eb07a6e["incSmallAllocation()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| c0b7dab6_60ff_7674_6101_0df52eb07a6e
  81898fd1_55d8_5bc5_5801_519a79cdea60["allocateHuge()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 81898fd1_55d8_5bc5_5801_519a79cdea60
  1eb7867b_3257_ad29_cda0_1b8484056b67["free()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 1eb7867b_3257_ad29_cda0_1b8484056b67
  719de5da_0e62_dac3_9464_3a0bd62e2e85["SizeClass()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 719de5da_0e62_dac3_9464_3a0bd62e2e85
  49dbf789_be1b_69c7_042a_27d74a8c475d["freeChunk()"]
  de926ba9_75e3_c416_27fc_3623234991a8 -->|method| 49dbf789_be1b_69c7_042a_27d74a8c475d

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/PoolArena.java lines 35–853

abstract class PoolArena<T> implements PoolArenaMetric {
    private static final boolean HAS_UNSAFE = PlatformDependent.hasUnsafe();

    enum SizeClass {
        Small,
        Normal
    }

    final PooledByteBufAllocator parent;

    final PoolSubpage<T>[] smallSubpagePools;

    private final PoolChunkList<T> q050;
    private final PoolChunkList<T> q025;
    private final PoolChunkList<T> q000;
    private final PoolChunkList<T> qInit;
    private final PoolChunkList<T> q075;
    private final PoolChunkList<T> q100;

    private final List<PoolChunkListMetric> chunkListMetrics;

    // Metrics for allocations and deallocations
    private long allocationsNormal;
    // We need to use the LongCounter here as this is not guarded via synchronized block.
    private final LongAdder allocationsSmall = new LongAdder();
    private final LongAdder allocationsHuge = new LongAdder();
    private final LongAdder activeBytesHuge = new LongAdder();

    private long deallocationsSmall;
    private long deallocationsNormal;

    private long pooledChunkAllocations;
    private long pooledChunkDeallocations;

    // We need to use the LongCounter here as this is not guarded via synchronized block.
    private final LongAdder deallocationsHuge = new LongAdder();

    // Number of thread caches backed by this arena.
    final AtomicInteger numThreadCaches = new AtomicInteger();

    // TODO: Test if adding padding helps under contention
    //private long pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7;

    private final ReentrantLock lock = new ReentrantLock();

    final SizeClasses sizeClass;

    protected PoolArena(PooledByteBufAllocator parent, SizeClasses sizeClass) {
        assert null != sizeClass;
        this.parent = parent;
        this.sizeClass = sizeClass;
        smallSubpagePools = newSubpagePoolArray(sizeClass.nSubpages);
        for (int i = 0; i < smallSubpagePools.length; i ++) {
            smallSubpagePools[i] = newSubpagePoolHead(i);
        }

        q100 = new PoolChunkList<T>(this, null, 100, Integer.MAX_VALUE, sizeClass.chunkSize);
        q075 = new PoolChunkList<T>(this, q100, 75, 100, sizeClass.chunkSize);
        q050 = new PoolChunkList<T>(this, q100, 50, 100, sizeClass.chunkSize);
        q025 = new PoolChunkList<T>(this, q050, 25, 75, sizeClass.chunkSize);
        q000 = new PoolChunkList<T>(this, q025, 1, 50, sizeClass.chunkSize);
        qInit = new PoolChunkList<T>(this, q000, Integer.MIN_VALUE, 25, sizeClass.chunkSize);

        q100.prevList(q075);
        q075.prevList(q050);
        q050.prevList(q025);
        q025.prevList(q000);
        q000.prevList(null);
        qInit.prevList(qInit);

        List<PoolChunkListMetric> metrics = new ArrayList<PoolChunkListMetric>(6);
        metrics.add(qInit);
        metrics.add(q000);
        metrics.add(q025);
        metrics.add(q050);
        metrics.add(q075);
        metrics.add(q100);
        chunkListMetrics = Collections.unmodifiableList(metrics);
    }

    private PoolSubpage<T> newSubpagePoolHead(int index) {

Frequently Asked Questions

What is the PoolArena class?
PoolArena is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/PoolArena.java.
Where is PoolArena defined?
PoolArena is defined in buffer/src/main/java/io/netty/buffer/PoolArena.java at line 35.

Analyze Your Own Codebase

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

Try Supermodel Free