Home / Class/ AdaptiveByteBuf Class — netty Architecture

AdaptiveByteBuf Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a["AdaptiveByteBuf"]
  fee3fa6d_a7fb_30d6_ea34_49602c633a2c["AdaptivePoolingAllocator.java"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|defined in| fee3fa6d_a7fb_30d6_ea34_49602c633a2c
  aa8138f7_2d74_991a_f785_69f88ea479bb["AdaptiveByteBuf()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| aa8138f7_2d74_991a_f785_69f88ea479bb
  d2358321_df26_0835_b350_5f8d6d0f0433["init()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| d2358321_df26_0835_b350_5f8d6d0f0433
  70390be2_170e_126c_4c5b_331d9534d11e["AbstractByteBuf()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| 70390be2_170e_126c_4c5b_331d9534d11e
  c3242174_0c08_d505_32f3_01076e0f0871["capacity()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| c3242174_0c08_d505_32f3_01076e0f0871
  192c2fae_0079_c5d9_e84d_9e87b0ecd078["maxFastWritableBytes()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| 192c2fae_0079_c5d9_e84d_9e87b0ecd078
  9928adc3_c1c7_6145_dd14_c9c1e6101da8["ByteBuf()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| 9928adc3_c1c7_6145_dd14_c9c1e6101da8
  d3865de6_c6f8_f47a_70a3_0ee8fb6deb90["ByteBufAllocator()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| d3865de6_c6f8_f47a_70a3_0ee8fb6deb90
  734e231d_6ff0_9893_cb85_c85275a0b68f["ByteOrder()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| 734e231d_6ff0_9893_cb85_c85275a0b68f
  ecba1bb2_bbf5_e468_44f7_2b5fa5c584ce["isDirect()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| ecba1bb2_bbf5_e468_44f7_2b5fa5c584ce
  f5e45038_64d0_db04_aaa8_ec2c292f7325["arrayOffset()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| f5e45038_64d0_db04_aaa8_ec2c292f7325
  85622973_a705_fba7_fb36_bad3eacfa062["hasMemoryAddress()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| 85622973_a705_fba7_fb36_bad3eacfa062
  ae2bb0d5_82f1_a8d5_92e1_52813acfd746["memoryAddress()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| ae2bb0d5_82f1_a8d5_92e1_52813acfd746
  a4e45d31_3000_058e_499f_13a6196b5a7c["_memoryAddress()"]
  e9381b1a_dc06_843c_be7e_5e0eddee4a3a -->|method| a4e45d31_3000_058e_499f_13a6196b5a7c

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java lines 1536–2056

    static final class AdaptiveByteBuf extends AbstractReferenceCountedByteBuf {

        private final EnhancedHandle<AdaptiveByteBuf> handle;

        // this both act as adjustment and the start index for a free list segment allocation
        private int startIndex;
        private AbstractByteBuf rootParent;
        Chunk chunk;
        private int length;
        private int maxFastCapacity;
        private ByteBuffer tmpNioBuf;
        private boolean hasArray;
        private boolean hasMemoryAddress;

        AdaptiveByteBuf(EnhancedHandle<AdaptiveByteBuf> recyclerHandle) {
            super(0);
            handle = ObjectUtil.checkNotNull(recyclerHandle, "recyclerHandle");
        }

        void init(AbstractByteBuf unwrapped, Chunk wrapped, int readerIndex, int writerIndex,
                  int startIndex, int size, int capacity, int maxCapacity) {
            this.startIndex = startIndex;
            chunk = wrapped;
            length = size;
            maxFastCapacity = capacity;
            maxCapacity(maxCapacity);
            setIndex0(readerIndex, writerIndex);
            hasArray = unwrapped.hasArray();
            hasMemoryAddress = unwrapped.hasMemoryAddress();
            rootParent = unwrapped;
            tmpNioBuf = null;

            if (PlatformDependent.isJfrEnabled() && AllocateBufferEvent.isEventEnabled()) {
                AllocateBufferEvent event = new AllocateBufferEvent();
                if (event.shouldCommit()) {
                    event.fill(this, AdaptiveByteBufAllocator.class);
                    event.chunkPooled = wrapped.pooled;
                    Magazine m = wrapped.magazine;
                    event.chunkThreadLocal = m != null && m.allocationLock == null;
                    event.commit();
                }
            }
        }

        private AbstractByteBuf rootParent() {
            final AbstractByteBuf rootParent = this.rootParent;
            if (rootParent != null) {
                return rootParent;
            }
            throw new IllegalReferenceCountException();
        }

        @Override
        public int capacity() {
            return length;
        }

        @Override
        public int maxFastWritableBytes() {
            return Math.min(maxFastCapacity, maxCapacity()) - writerIndex;
        }

        @Override
        public ByteBuf capacity(int newCapacity) {
            if (length <= newCapacity && newCapacity <= maxFastCapacity) {
                ensureAccessible();
                length = newCapacity;
                return this;
            }
            checkNewCapacity(newCapacity);
            if (newCapacity < capacity()) {
                length = newCapacity;
                trimIndicesToCapacity(newCapacity);
                return this;
            }

            if (PlatformDependent.isJfrEnabled() && ReallocateBufferEvent.isEventEnabled()) {
                ReallocateBufferEvent event = new ReallocateBufferEvent();
                if (event.shouldCommit()) {
                    event.fill(this, AdaptiveByteBufAllocator.class);
                    event.newCapacity = newCapacity;

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free