Home / Class/ Chunk Class — netty Architecture

Chunk Class — netty Architecture

Architecture documentation for the Chunk class in AdaptivePoolingAllocator.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d["Chunk"]
  fee3fa6d_a7fb_30d6_ea34_49602c633a2c["AdaptivePoolingAllocator.java"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|defined in| fee3fa6d_a7fb_30d6_ea34_49602c633a2c
  8d275038_0e05_3918_af0f_1e8f488cf0f2["Chunk()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 8d275038_0e05_3918_af0f_1e8f488cf0f2
  ddfbec96_493f_520d_562e_a4b724ac0c9b["Magazine()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| ddfbec96_493f_520d_562e_a4b724ac0c9b
  40e0c619_bcae_13c7_854d_c6e52c72f951["detachFromMagazine()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 40e0c619_bcae_13c7_854d_c6e52c72f951
  9d31fc3c_9011_6bf1_391a_b0388f8c5e8d["attachToMagazine()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 9d31fc3c_9011_6bf1_391a_b0388f8c5e8d
  f4981826_99f5_bf62_b6e7_eb825c46476a["releaseFromMagazine()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| f4981826_99f5_bf62_b6e7_eb825c46476a
  aa4d5650_6a83_e39b_3f24_f23c1cb66883["releaseSegment()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| aa4d5650_6a83_e39b_3f24_f23c1cb66883
  d9980d84_8510_b798_28d8_a0722eb609cd["retain()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| d9980d84_8510_b798_28d8_a0722eb609cd
  59c1d0ae_e507_0c96_51fa_359fe1b6411f["release()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 59c1d0ae_e507_0c96_51fa_359fe1b6411f
  98785a74_86ed_ffcc_d613_fd55a1cb34e4["deallocate()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 98785a74_86ed_ffcc_d613_fd55a1cb34e4
  a02995fd_2479_0eaa_4f06_b3f208a28799["onRelease()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| a02995fd_2479_0eaa_4f06_b3f208a28799
  5b606370_5e08_94d5_b745_9c0ce73ce25a["readInitInto()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 5b606370_5e08_94d5_b745_9c0ce73ce25a
  aa355cc9_0be7_7204_fd7f_51edca001d83["remainingCapacity()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| aa355cc9_0be7_7204_fd7f_51edca001d83
  0f685070_2339_973b_3d62_758991d1b2a9["hasUnprocessedFreelistEntries()"]
  f1cdd349_c4cb_5c01_45cf_5cb7bb37814d -->|method| 0f685070_2339_973b_3d62_758991d1b2a9

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java lines 1070–1220

    private static class Chunk implements ChunkInfo {
        protected final AbstractByteBuf delegate;
        protected Magazine magazine;
        private final AdaptivePoolingAllocator allocator;
        // Always populate the refCnt field, so HotSpot doesn't emit `null` checks.
        // This is safe to do even on native-image.
        private final RefCnt refCnt = new RefCnt();
        private final int capacity;
        private final boolean pooled;
        protected int allocatedBytes;

        Chunk() {
            // Constructor only used by the MAGAZINE_FREED sentinel.
            delegate = null;
            magazine = null;
            allocator = null;
            capacity = 0;
            pooled = false;
        }

        Chunk(AbstractByteBuf delegate, Magazine magazine, boolean pooled) {
            this.delegate = delegate;
            this.pooled = pooled;
            capacity = delegate.capacity();
            attachToMagazine(magazine);

            // We need the top-level allocator so ByteBuf.capacity(int) can call reallocate()
            allocator = magazine.group.allocator;

            if (PlatformDependent.isJfrEnabled() && AllocateChunkEvent.isEventEnabled()) {
                AllocateChunkEvent event = new AllocateChunkEvent();
                if (event.shouldCommit()) {
                    event.fill(this, AdaptiveByteBufAllocator.class);
                    event.pooled = pooled;
                    event.threadLocal = magazine.allocationLock == null;
                    event.commit();
                }
            }
        }

        Magazine currentMagazine()  {
            return magazine;
        }

        void detachFromMagazine() {
            if (magazine != null) {
                magazine = null;
            }
        }

        void attachToMagazine(Magazine magazine) {
            assert this.magazine == null;
            this.magazine = magazine;
        }

        /**
         * Called when a magazine is done using this chunk, probably because it was emptied.
         */
        boolean releaseFromMagazine() {
            // Chunks can be reused before they become empty.
            // We can therefor put them in the shared queue as soon as the magazine is done with this chunk.
            Magazine mag = magazine;
            detachFromMagazine();
            if (!mag.offerToQueue(this)) {
                return release();
            }
            return false;
        }

        /**
         * Called when a ByteBuf is done using its allocation in this chunk.
         */
        void releaseSegment(int ignoredSegmentId, int size) {
            release();
        }

        private void retain() {
                RefCnt.retain(refCnt);
        }

        protected boolean release() {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free