package io.netty.buffer;

import io.netty.util.internal.LongCounter;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
abstract class PoolArena<T> implements PoolArenaMetric {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    static final boolean HAS_UNSAFE = PlatformDependent.hasUnsafe();
    static final int numTinySubpagePools = 32;
    private long allocationsNormal;
    private final List<PoolChunkListMetric> chunkListMetrics;
    final int chunkSize;
    private long deallocationsNormal;
    private long deallocationsSmall;
    private long deallocationsTiny;
    private final int maxOrder;
    final int numSmallSubpagePools;
    final int pageShifts;
    final int pageSize;
    final PooledByteBufAllocator parent;
    private final PoolChunkList<T> q000;
    private final PoolChunkList<T> q025;
    private final PoolChunkList<T> q050;
    private final PoolChunkList<T> q075;
    private final PoolChunkList<T> q100;
    private final PoolChunkList<T> qInit;
    private final PoolSubpage<T>[] smallSubpagePools;
    final int subpageOverflowMask;
    private final LongCounter allocationsTiny = PlatformDependent.newLongCounter();
    private final LongCounter allocationsSmall = PlatformDependent.newLongCounter();
    private final LongCounter allocationsHuge = PlatformDependent.newLongCounter();
    private final LongCounter activeBytesHuge = PlatformDependent.newLongCounter();
    private final LongCounter deallocationsHuge = PlatformDependent.newLongCounter();
    final AtomicInteger numThreadCaches = new AtomicInteger();
    private final PoolSubpage<T>[] tinySubpagePools = newSubpagePoolArray(32);

    /* JADX INFO: renamed from: io.netty.buffer.PoolArena$1, reason: invalid class name */
    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$io$netty$buffer$PoolArena$SizeClass;

        static {
            int[] iArr = new int[SizeClass.values().length];
            $SwitchMap$io$netty$buffer$PoolArena$SizeClass = iArr;
            try {
                iArr[SizeClass.Normal.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$io$netty$buffer$PoolArena$SizeClass[SizeClass.Small.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$io$netty$buffer$PoolArena$SizeClass[SizeClass.Tiny.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    static final class DirectArena extends PoolArena<ByteBuffer> {
        DirectArena(PooledByteBufAllocator pooledByteBufAllocator, int i2, int i3, int i4, int i5) {
            super(pooledByteBufAllocator, i2, i3, i4, i5);
        }

        private static ByteBuffer allocateDirect(int i2) {
            return PlatformDependent.useDirectBufferNoCleaner() ? PlatformDependent.allocateDirectNoCleaner(i2) : ByteBuffer.allocateDirect(i2);
        }

        @Override // io.netty.buffer.PoolArena
        protected void destroyChunk(PoolChunk<ByteBuffer> poolChunk) {
            if (PlatformDependent.useDirectBufferNoCleaner()) {
                PlatformDependent.freeDirectNoCleaner(poolChunk.memory);
            } else {
                PlatformDependent.freeDirectBuffer(poolChunk.memory);
            }
        }

        @Override // io.netty.buffer.PoolArena
        boolean isDirect() {
            return true;
        }

        @Override // io.netty.buffer.PoolArena
        protected PooledByteBuf<ByteBuffer> newByteBuf(int i2) {
            return PoolArena.HAS_UNSAFE ? PooledUnsafeDirectByteBuf.newInstance(i2) : PooledDirectByteBuf.newInstance(i2);
        }

        @Override // io.netty.buffer.PoolArena
        protected PoolChunk<ByteBuffer> newChunk(int i2, int i3, int i4, int i5) {
            return new PoolChunk<>(this, allocateDirect(i5), i2, i3, i4, i5);
        }

        @Override // io.netty.buffer.PoolArena
        protected PoolChunk<ByteBuffer> newUnpooledChunk(int i2) {
            return new PoolChunk<>(this, allocateDirect(i2), i2);
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // io.netty.buffer.PoolArena
        public void memoryCopy(ByteBuffer byteBuffer, int i2, ByteBuffer byteBuffer2, int i3, int i4) {
            if (i4 == 0) {
                return;
            }
            if (PoolArena.HAS_UNSAFE) {
                PlatformDependent.copyMemory(PlatformDependent.directBufferAddress(byteBuffer) + ((long) i2), PlatformDependent.directBufferAddress(byteBuffer2) + ((long) i3), i4);
                return;
            }
            ByteBuffer byteBufferDuplicate = byteBuffer.duplicate();
            ByteBuffer byteBufferDuplicate2 = byteBuffer2.duplicate();
            byteBufferDuplicate.position(i2).limit(i2 + i4);
            byteBufferDuplicate2.position(i3);
            byteBufferDuplicate2.put(byteBufferDuplicate);
        }
    }

    static final class HeapArena extends PoolArena<byte[]> {
        HeapArena(PooledByteBufAllocator pooledByteBufAllocator, int i2, int i3, int i4, int i5) {
            super(pooledByteBufAllocator, i2, i3, i4, i5);
        }

        @Override // io.netty.buffer.PoolArena
        protected void destroyChunk(PoolChunk<byte[]> poolChunk) {
        }

        @Override // io.netty.buffer.PoolArena
        boolean isDirect() {
            return false;
        }

        @Override // io.netty.buffer.PoolArena
        protected PooledByteBuf<byte[]> newByteBuf(int i2) {
            return PoolArena.HAS_UNSAFE ? PooledUnsafeHeapByteBuf.newUnsafeInstance(i2) : PooledHeapByteBuf.newInstance(i2);
        }

        @Override // io.netty.buffer.PoolArena
        protected PoolChunk<byte[]> newChunk(int i2, int i3, int i4, int i5) {
            return new PoolChunk<>(this, new byte[i5], i2, i3, i4, i5);
        }

        @Override // io.netty.buffer.PoolArena
        protected PoolChunk<byte[]> newUnpooledChunk(int i2) {
            return new PoolChunk<>(this, new byte[i2], i2);
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // io.netty.buffer.PoolArena
        public void memoryCopy(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
            if (i4 == 0) {
                return;
            }
            System.arraycopy(bArr, i2, bArr2, i3, i4);
        }
    }

    enum SizeClass {
        Tiny,
        Small,
        Normal
    }

    protected PoolArena(PooledByteBufAllocator pooledByteBufAllocator, int i2, int i3, int i4, int i5) {
        this.parent = pooledByteBufAllocator;
        this.pageSize = i2;
        this.maxOrder = i3;
        this.pageShifts = i4;
        this.chunkSize = i5;
        this.subpageOverflowMask = ~(i2 - 1);
        int i6 = 0;
        int i7 = 0;
        while (true) {
            PoolSubpage<T>[] poolSubpageArr = this.tinySubpagePools;
            if (i7 >= poolSubpageArr.length) {
                break;
            }
            poolSubpageArr[i7] = newSubpagePoolHead(i2);
            i7++;
        }
        int i8 = i4 - 9;
        this.numSmallSubpagePools = i8;
        this.smallSubpagePools = newSubpagePoolArray(i8);
        while (true) {
            PoolSubpage<T>[] poolSubpageArr2 = this.smallSubpagePools;
            if (i6 >= poolSubpageArr2.length) {
                this.q100 = new PoolChunkList<>(null, 100, Integer.MAX_VALUE, i5);
                this.q075 = new PoolChunkList<>(this.q100, 75, 100, i5);
                this.q050 = new PoolChunkList<>(this.q075, 50, 100, i5);
                this.q025 = new PoolChunkList<>(this.q050, 25, 75, i5);
                this.q000 = new PoolChunkList<>(this.q025, 1, 50, i5);
                this.qInit = new PoolChunkList<>(this.q000, Integer.MIN_VALUE, 25, i5);
                this.q100.prevList(this.q075);
                this.q075.prevList(this.q050);
                this.q050.prevList(this.q025);
                this.q025.prevList(this.q000);
                this.q000.prevList(null);
                PoolChunkList<T> poolChunkList = this.qInit;
                poolChunkList.prevList(poolChunkList);
                ArrayList arrayList = new ArrayList(6);
                arrayList.add(this.qInit);
                arrayList.add(this.q000);
                arrayList.add(this.q025);
                arrayList.add(this.q050);
                arrayList.add(this.q075);
                arrayList.add(this.q100);
                this.chunkListMetrics = Collections.unmodifiableList(arrayList);
                return;
            }
            poolSubpageArr2[i6] = newSubpagePoolHead(i2);
            i6++;
        }
    }

    private void allocateHuge(PooledByteBuf<T> pooledByteBuf, int i2) {
        PoolChunk<T> poolChunkNewUnpooledChunk = newUnpooledChunk(i2);
        this.activeBytesHuge.add(poolChunkNewUnpooledChunk.chunkSize());
        pooledByteBuf.initUnpooled(poolChunkNewUnpooledChunk, i2);
        this.allocationsHuge.increment();
    }

    private synchronized void allocateNormal(PooledByteBuf<T> pooledByteBuf, int i2, int i3) {
        if (!this.q050.allocate(pooledByteBuf, i2, i3) && !this.q025.allocate(pooledByteBuf, i2, i3) && !this.q000.allocate(pooledByteBuf, i2, i3) && !this.qInit.allocate(pooledByteBuf, i2, i3) && !this.q075.allocate(pooledByteBuf, i2, i3)) {
            PoolChunk<T> poolChunkNewChunk = newChunk(this.pageSize, this.maxOrder, this.pageShifts, this.chunkSize);
            long jAllocate = poolChunkNewChunk.allocate(i3);
            this.allocationsNormal++;
            poolChunkNewChunk.initBuf(pooledByteBuf, jAllocate, i2);
            this.qInit.add(poolChunkNewChunk);
            return;
        }
        this.allocationsNormal++;
    }

    static boolean isTiny(int i2) {
        return (i2 & (-512)) == 0;
    }

    private PoolSubpage<T>[] newSubpagePoolArray(int i2) {
        return new PoolSubpage[i2];
    }

    private PoolSubpage<T> newSubpagePoolHead(int i2) {
        PoolSubpage<T> poolSubpage = new PoolSubpage<>(i2);
        poolSubpage.prev = poolSubpage;
        poolSubpage.next = poolSubpage;
        return poolSubpage;
    }

    private SizeClass sizeClass(int i2) {
        return !isTinyOrSmall(i2) ? SizeClass.Normal : isTiny(i2) ? SizeClass.Tiny : SizeClass.Small;
    }

    static int smallIdx(int i2) {
        int i3 = i2 >>> 10;
        int i4 = 0;
        while (i3 != 0) {
            i3 >>>= 1;
            i4++;
        }
        return i4;
    }

    private static List<PoolSubpageMetric> subPageMetricList(PoolSubpage<?>[] poolSubpageArr) {
        ArrayList arrayList = new ArrayList();
        for (int i2 = 1; i2 < poolSubpageArr.length; i2++) {
            PoolSubpage<?> poolSubpage = poolSubpageArr[i2];
            PoolSubpage poolSubpage2 = poolSubpage.next;
            if (poolSubpage2 != poolSubpage) {
                do {
                    arrayList.add(poolSubpage2);
                    poolSubpage2 = poolSubpage2.next;
                } while (poolSubpage2 != poolSubpage);
            }
        }
        return arrayList;
    }

    static int tinyIdx(int i2) {
        return i2 >>> 4;
    }

    PooledByteBuf<T> allocate(PoolThreadCache poolThreadCache, int i2, int i3) {
        PooledByteBuf<T> pooledByteBufNewByteBuf = newByteBuf(i3);
        allocate(poolThreadCache, pooledByteBufNewByteBuf, i2);
        return pooledByteBufNewByteBuf;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public List<PoolChunkListMetric> chunkLists() {
        return this.chunkListMetrics;
    }

    protected abstract void destroyChunk(PoolChunk<T> poolChunk);

    PoolSubpage<T> findSubpagePoolHead(int i2) {
        PoolSubpage<T>[] poolSubpageArr;
        int i3;
        if (isTiny(i2)) {
            i3 = i2 >>> 4;
            poolSubpageArr = this.tinySubpagePools;
        } else {
            int i4 = 0;
            int i5 = i2 >>> 10;
            while (i5 != 0) {
                i5 >>>= 1;
                i4++;
            }
            int i6 = i4;
            poolSubpageArr = this.smallSubpagePools;
            i3 = i6;
        }
        return poolSubpageArr[i3];
    }

    void free(PoolChunk<T> poolChunk, long j2, int i2, PoolThreadCache poolThreadCache) {
        if (poolChunk.unpooled) {
            int iChunkSize = poolChunk.chunkSize();
            destroyChunk(poolChunk);
            this.activeBytesHuge.add(-iChunkSize);
            this.deallocationsHuge.increment();
            return;
        }
        SizeClass sizeClass = sizeClass(i2);
        if (poolThreadCache == null || !poolThreadCache.add(this, poolChunk, j2, i2, sizeClass)) {
            freeChunk(poolChunk, j2, sizeClass);
        }
    }

    void freeChunk(PoolChunk<T> poolChunk, long j2, SizeClass sizeClass) {
        boolean z;
        synchronized (this) {
            int i2 = AnonymousClass1.$SwitchMap$io$netty$buffer$PoolArena$SizeClass[sizeClass.ordinal()];
            z = true;
            if (i2 == 1) {
                this.deallocationsNormal++;
            } else if (i2 == 2) {
                this.deallocationsSmall++;
            } else {
                if (i2 != 3) {
                    throw new Error();
                }
                this.deallocationsTiny++;
            }
            if (poolChunk.parent.free(poolChunk, j2)) {
                z = false;
            }
        }
        if (z) {
            destroyChunk(poolChunk);
        }
    }

    abstract boolean isDirect();

    boolean isTinyOrSmall(int i2) {
        return (i2 & this.subpageOverflowMask) == 0;
    }

    protected abstract void memoryCopy(T t, int i2, T t2, int i3, int i4);

    protected abstract PooledByteBuf<T> newByteBuf(int i2);

    protected abstract PoolChunk<T> newChunk(int i2, int i3, int i4, int i5);

    protected abstract PoolChunk<T> newUnpooledChunk(int i2);

    int normalizeCapacity(int i2) {
        if (i2 < 0) {
            throw new IllegalArgumentException("capacity: " + i2 + " (expected: 0+)");
        }
        if (i2 >= this.chunkSize) {
            return i2;
        }
        if (isTiny(i2)) {
            return (i2 & 15) == 0 ? i2 : (i2 & (-16)) + 16;
        }
        int i3 = i2 - 1;
        int i4 = i3 | (i3 >>> 1);
        int i5 = i4 | (i4 >>> 2);
        int i6 = i5 | (i5 >>> 4);
        int i7 = i6 | (i6 >>> 8);
        int i8 = (i7 | (i7 >>> 16)) + 1;
        return i8 < 0 ? i8 >>> 1 : i8;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveAllocations() {
        long j2;
        long jValue = ((this.allocationsTiny.value() + this.allocationsSmall.value()) + this.allocationsHuge.value()) - this.deallocationsHuge.value();
        synchronized (this) {
            j2 = jValue + (this.allocationsNormal - ((this.deallocationsTiny + this.deallocationsSmall) + this.deallocationsNormal));
        }
        return Math.max(j2, 0L);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveBytes() {
        long jValue = this.activeBytesHuge.value();
        synchronized (this) {
            for (int i2 = 0; i2 < this.chunkListMetrics.size(); i2++) {
                Iterator<PoolChunkMetric> it = this.chunkListMetrics.get(i2).iterator();
                while (it.hasNext()) {
                    jValue += (long) it.next().chunkSize();
                }
            }
        }
        return Math.max(0L, jValue);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveHugeAllocations() {
        return Math.max(numHugeAllocations() - numHugeDeallocations(), 0L);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveNormalAllocations() {
        long j2;
        synchronized (this) {
            j2 = this.allocationsNormal - this.deallocationsNormal;
        }
        return Math.max(j2, 0L);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveSmallAllocations() {
        return Math.max(numSmallAllocations() - numSmallDeallocations(), 0L);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numActiveTinyAllocations() {
        return Math.max(numTinyAllocations() - numTinyDeallocations(), 0L);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numAllocations() {
        long j2;
        synchronized (this) {
            j2 = this.allocationsNormal;
        }
        return this.allocationsTiny.value() + this.allocationsSmall.value() + j2 + this.allocationsHuge.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public int numChunkLists() {
        return this.chunkListMetrics.size();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numDeallocations() {
        long j2;
        synchronized (this) {
            j2 = this.deallocationsTiny + this.deallocationsSmall + this.deallocationsNormal;
        }
        return j2 + this.deallocationsHuge.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numHugeAllocations() {
        return this.allocationsHuge.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numHugeDeallocations() {
        return this.deallocationsHuge.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public synchronized long numNormalAllocations() {
        return this.allocationsNormal;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public synchronized long numNormalDeallocations() {
        return this.deallocationsNormal;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numSmallAllocations() {
        return this.allocationsSmall.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public synchronized long numSmallDeallocations() {
        return this.deallocationsSmall;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public int numSmallSubpages() {
        return this.smallSubpagePools.length;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public int numThreadCaches() {
        return this.numThreadCaches.get();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public long numTinyAllocations() {
        return this.allocationsTiny.value();
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public synchronized long numTinyDeallocations() {
        return this.deallocationsTiny;
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public int numTinySubpages() {
        return this.tinySubpagePools.length;
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0057  */
    /* JADX WARN: Removed duplicated region for block: B:25:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    void reallocate(io.netty.buffer.PooledByteBuf<T> r13, int r14, boolean r15) {
        /*
            r12 = this;
            if (r14 < 0) goto L61
            int r0 = r13.maxCapacity()
            if (r14 > r0) goto L61
            int r6 = r13.length
            if (r6 != r14) goto Ld
            return
        Ld:
            io.netty.buffer.PoolChunk<T> r7 = r13.chunk
            long r8 = r13.handle
            T r2 = r13.memory
            int r3 = r13.offset
            int r10 = r13.maxLength
            int r11 = r13.readerIndex()
            int r0 = r13.writerIndex()
            io.netty.buffer.PooledByteBufAllocator r1 = r12.parent
            io.netty.buffer.PoolThreadCache r1 = r1.threadCache()
            r12.allocate(r1, r13, r14)
            if (r14 <= r6) goto L33
            T r4 = r13.memory
            int r5 = r13.offset
            r1 = r12
            r1.memoryCopy(r2, r3, r4, r5, r6)
            goto L51
        L33:
            if (r14 >= r6) goto L51
            if (r11 >= r14) goto L4f
            if (r0 <= r14) goto L3a
            goto L3b
        L3a:
            r14 = r0
        L3b:
            int r3 = r3 + r11
            T r4 = r13.memory
            int r0 = r13.offset
            int r5 = r0 + r11
            int r6 = r14 - r11
            r0 = r12
            r1 = r2
            r2 = r3
            r3 = r4
            r4 = r5
            r5 = r6
            r0.memoryCopy(r1, r2, r3, r4, r5)
            r0 = r14
            goto L51
        L4f:
            r0 = r14
            goto L52
        L51:
            r14 = r11
        L52:
            r13.setIndex(r14, r0)
            if (r15 == 0) goto L60
            io.netty.buffer.PoolThreadCache r5 = r13.cache
            r0 = r12
            r1 = r7
            r2 = r8
            r4 = r10
            r0.free(r1, r2, r4, r5)
        L60:
            return
        L61:
            java.lang.IllegalArgumentException r13 = new java.lang.IllegalArgumentException
            java.lang.StringBuilder r15 = new java.lang.StringBuilder
            r15.<init>()
            java.lang.String r0 = "newCapacity: "
            r15.append(r0)
            r15.append(r14)
            java.lang.String r14 = r15.toString()
            r13.<init>(r14)
            throw r13
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.buffer.PoolArena.reallocate(io.netty.buffer.PooledByteBuf, int, boolean):void");
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public List<PoolSubpageMetric> smallSubpages() {
        return subPageMetricList(this.smallSubpagePools);
    }

    @Override // io.netty.buffer.PoolArenaMetric
    public List<PoolSubpageMetric> tinySubpages() {
        return subPageMetricList(this.tinySubpagePools);
    }

    public synchronized String toString() {
        StringBuilder sb;
        sb = new StringBuilder();
        sb.append("Chunk(s) at 0~25%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.qInit);
        sb.append(StringUtil.NEWLINE);
        sb.append("Chunk(s) at 0~50%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.q000);
        sb.append(StringUtil.NEWLINE);
        sb.append("Chunk(s) at 25~75%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.q025);
        sb.append(StringUtil.NEWLINE);
        sb.append("Chunk(s) at 50~100%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.q050);
        sb.append(StringUtil.NEWLINE);
        sb.append("Chunk(s) at 75~100%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.q075);
        sb.append(StringUtil.NEWLINE);
        sb.append("Chunk(s) at 100%:");
        sb.append(StringUtil.NEWLINE);
        sb.append(this.q100);
        sb.append(StringUtil.NEWLINE);
        sb.append("tiny subpages:");
        for (int i2 = 1; i2 < this.tinySubpagePools.length; i2++) {
            PoolSubpage<T> poolSubpage = this.tinySubpagePools[i2];
            if (poolSubpage.next != poolSubpage) {
                sb.append(StringUtil.NEWLINE);
                sb.append(i2);
                sb.append(": ");
                PoolSubpage<T> poolSubpage2 = poolSubpage.next;
                do {
                    sb.append(poolSubpage2);
                    poolSubpage2 = poolSubpage2.next;
                } while (poolSubpage2 != poolSubpage);
            }
        }
        sb.append(StringUtil.NEWLINE);
        sb.append("small subpages:");
        for (int i3 = 1; i3 < this.smallSubpagePools.length; i3++) {
            PoolSubpage<T> poolSubpage3 = this.smallSubpagePools[i3];
            if (poolSubpage3.next != poolSubpage3) {
                sb.append(StringUtil.NEWLINE);
                sb.append(i3);
                sb.append(": ");
                PoolSubpage<T> poolSubpage4 = poolSubpage3.next;
                do {
                    sb.append(poolSubpage4);
                    poolSubpage4 = poolSubpage4.next;
                } while (poolSubpage4 != poolSubpage3);
            }
        }
        sb.append(StringUtil.NEWLINE);
        return sb.toString();
    }

    private void allocate(PoolThreadCache poolThreadCache, PooledByteBuf<T> pooledByteBuf, int i2) {
        int iSmallIdx;
        PoolSubpage<T>[] poolSubpageArr;
        int iNormalizeCapacity = normalizeCapacity(i2);
        if (isTinyOrSmall(iNormalizeCapacity)) {
            boolean zIsTiny = isTiny(iNormalizeCapacity);
            if (zIsTiny) {
                if (poolThreadCache.allocateTiny(this, pooledByteBuf, i2, iNormalizeCapacity)) {
                    return;
                }
                iSmallIdx = tinyIdx(iNormalizeCapacity);
                poolSubpageArr = this.tinySubpagePools;
            } else {
                if (poolThreadCache.allocateSmall(this, pooledByteBuf, i2, iNormalizeCapacity)) {
                    return;
                }
                iSmallIdx = smallIdx(iNormalizeCapacity);
                poolSubpageArr = this.smallSubpagePools;
            }
            PoolSubpage<T> poolSubpage = poolSubpageArr[iSmallIdx];
            synchronized (poolSubpage) {
                PoolSubpage<T> poolSubpage2 = poolSubpage.next;
                if (poolSubpage2 != poolSubpage) {
                    poolSubpage2.chunk.initBufWithSubpage(pooledByteBuf, poolSubpage2.allocate(), i2);
                    if (zIsTiny) {
                        this.allocationsTiny.increment();
                    } else {
                        this.allocationsSmall.increment();
                    }
                    return;
                }
                allocateNormal(pooledByteBuf, i2, iNormalizeCapacity);
                return;
            }
        }
        if (iNormalizeCapacity <= this.chunkSize) {
            if (poolThreadCache.allocateNormal(this, pooledByteBuf, i2, iNormalizeCapacity)) {
                return;
            }
            allocateNormal(pooledByteBuf, i2, iNormalizeCapacity);
            return;
        }
        allocateHuge(pooledByteBuf, i2);
    }
}
