package io.netty.buffer;

import g.a.a.a.a;
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 */
public abstract class PoolArena<T> implements PoolArenaMetric {
    public static final /* synthetic */ boolean $assertionsDisabled = false;
    public static final boolean HAS_UNSAFE = PlatformDependent.hasUnsafe();
    public static final int numTinySubpagePools = 32;
    private long allocationsNormal;
    private final List<PoolChunkListMetric> chunkListMetrics;
    public final int chunkSize;
    private long deallocationsNormal;
    private long deallocationsSmall;
    private long deallocationsTiny;
    public final int directMemoryCacheAlignment;
    public final int directMemoryCacheAlignmentMask;
    private final int maxOrder;
    public final int numSmallSubpagePools;
    public final int pageShifts;
    public final int pageSize;
    public 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;
    public 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();
    public 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 */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$io$netty$buffer$PoolArena$SizeClass;

        static {
            SizeClass.values();
            int[] iArr = new int[3];
            $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) {
            }
        }
    }

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

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

        private int offsetCacheLine(ByteBuffer byteBuffer) {
            if (PoolArena.HAS_UNSAFE) {
                return (int) (PlatformDependent.directBufferAddress(byteBuffer) & ((long) this.directMemoryCacheAlignmentMask));
            }
            return 0;
        }

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

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

        @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);
        }

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

        @Override // io.netty.buffer.PoolArena
        public PoolChunk<ByteBuffer> newChunk(int i2, int i3, int i4, int i5) {
            int i6 = this.directMemoryCacheAlignment;
            if (i6 == 0) {
                return new PoolChunk<>(this, allocateDirect(i5), i2, i3, i4, i5, 0);
            }
            ByteBuffer byteBufferAllocateDirect = allocateDirect(i6 + i5);
            return new PoolChunk<>(this, byteBufferAllocateDirect, i2, i3, i4, i5, offsetCacheLine(byteBufferAllocateDirect));
        }

        @Override // io.netty.buffer.PoolArena
        public PoolChunk<ByteBuffer> newUnpooledChunk(int i2) {
            int i3 = this.directMemoryCacheAlignment;
            if (i3 == 0) {
                return new PoolChunk<>(this, allocateDirect(i2), i2, 0);
            }
            ByteBuffer byteBufferAllocateDirect = allocateDirect(i3 + i2);
            return new PoolChunk<>(this, byteBufferAllocateDirect, i2, offsetCacheLine(byteBufferAllocateDirect));
        }
    }

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

        private static byte[] newByteArray(int i2) {
            return PlatformDependent.allocateUninitializedArray(i2);
        }

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

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

        @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);
        }

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

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

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

    public enum SizeClass {
        Tiny,
        Small,
        Normal
    }

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

    private void allocate(PoolThreadCache poolThreadCache, PooledByteBuf<T> pooledByteBuf, int i2) {
        int iSmallIdx;
        PoolSubpage<T>[] poolSubpageArr;
        int iNormalizeCapacity = normalizeCapacity(i2);
        if (!isTinyOrSmall(iNormalizeCapacity)) {
            if (iNormalizeCapacity > this.chunkSize) {
                allocateHuge(pooledByteBuf, i2);
                return;
            } else {
                if (poolThreadCache.allocateNormal(this, pooledByteBuf, i2, iNormalizeCapacity)) {
                    return;
                }
                synchronized (this) {
                    allocateNormal(pooledByteBuf, i2, iNormalizeCapacity);
                    this.allocationsNormal++;
                }
                return;
            }
        }
        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);
                incTinySmallAllocation(zIsTiny);
            } else {
                synchronized (this) {
                    allocateNormal(pooledByteBuf, i2, iNormalizeCapacity);
                }
                incTinySmallAllocation(zIsTiny);
            }
        }
    }

    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 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)) {
            return;
        }
        PoolChunk<T> poolChunkNewChunk = newChunk(this.pageSize, this.maxOrder, this.pageShifts, this.chunkSize);
        poolChunkNewChunk.initBuf(pooledByteBuf, poolChunkNewChunk.allocate(i3), i2);
        this.qInit.add(poolChunkNewChunk);
    }

    private static void appendPoolSubPages(StringBuilder sb, PoolSubpage<?>[] poolSubpageArr) {
        for (int i2 = 0; i2 < poolSubpageArr.length; i2++) {
            PoolSubpage<?> poolSubpage = poolSubpageArr[i2];
            if (poolSubpage.next != poolSubpage) {
                sb.append(StringUtil.NEWLINE);
                sb.append(i2);
                sb.append(": ");
                PoolSubpage poolSubpage2 = poolSubpage.next;
                do {
                    sb.append(poolSubpage2);
                    poolSubpage2 = poolSubpage2.next;
                } while (poolSubpage2 != poolSubpage);
            }
        }
    }

    private void destroyPoolChunkLists(PoolChunkList<T>... poolChunkListArr) {
        for (PoolChunkList<T> poolChunkList : poolChunkListArr) {
            poolChunkList.destroy(this);
        }
    }

    private static void destroyPoolSubPages(PoolSubpage<?>[] poolSubpageArr) {
        for (PoolSubpage<?> poolSubpage : poolSubpageArr) {
            poolSubpage.destroy();
        }
    }

    private void incTinySmallAllocation(boolean z2) {
        (z2 ? this.allocationsTiny : this.allocationsSmall).increment();
    }

    public 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;
    }

    public 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 (PoolSubpage<?> poolSubpage : poolSubpageArr) {
            PoolSubpage poolSubpage2 = poolSubpage.next;
            if (poolSubpage2 != poolSubpage) {
                do {
                    arrayList.add(poolSubpage2);
                    poolSubpage2 = poolSubpage2.next;
                } while (poolSubpage2 != poolSubpage);
            }
        }
        return arrayList;
    }

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

    public int alignCapacity(int i2) {
        int i3 = this.directMemoryCacheAlignmentMask & i2;
        return i3 == 0 ? i2 : (i2 + this.directMemoryCacheAlignment) - i3;
    }

    public 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;
    }

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

    public final void finalize() {
        try {
            super.finalize();
            destroyPoolSubPages(this.smallSubpagePools);
            destroyPoolSubPages(this.tinySubpagePools);
            destroyPoolChunkLists(this.qInit, this.q000, this.q025, this.q050, this.q075, this.q100);
        } catch (Throwable th) {
            destroyPoolSubPages(this.smallSubpagePools);
            destroyPoolSubPages(this.tinySubpagePools);
            destroyPoolChunkLists(this.qInit, this.q000, this.q025, this.q050, this.q075, this.q100);
            throw th;
        }
    }

    public 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];
    }

    public 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);
        }
    }

    public void freeChunk(PoolChunk<T> poolChunk, long j2, SizeClass sizeClass) {
        boolean z2;
        synchronized (this) {
            int iOrdinal = sizeClass.ordinal();
            z2 = true;
            if (iOrdinal == 0) {
                this.deallocationsTiny++;
            } else if (iOrdinal == 1) {
                this.deallocationsSmall++;
            } else {
                if (iOrdinal != 2) {
                    throw new Error();
                }
                this.deallocationsNormal++;
            }
            if (poolChunk.parent.free(poolChunk, j2)) {
                z2 = false;
            }
        }
        if (z2) {
            destroyChunk(poolChunk);
        }
    }

    public abstract boolean isDirect();

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

    public abstract void memoryCopy(T t2, int i2, T t3, int i3, int i4);

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

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

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

    public int normalizeCapacity(int i2) {
        if (i2 < 0) {
            throw new IllegalArgumentException(a.n("capacity: ", i2, " (expected: 0+)"));
        }
        if (i2 >= this.chunkSize) {
            return this.directMemoryCacheAlignment == 0 ? i2 : alignCapacity(i2);
        }
        if (isTiny(i2)) {
            return this.directMemoryCacheAlignment > 0 ? alignCapacity(i2) : (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.allocationsHuge.value() + (this.allocationsSmall.value() + this.allocationsTiny.value())) - this.deallocationsHuge.value();
        synchronized (this) {
            j2 = (this.allocationsNormal - ((this.deallocationsTiny + this.deallocationsSmall) + this.deallocationsNormal)) + jValue;
        }
        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.allocationsHuge.value() + this.allocationsSmall.value() + this.allocationsTiny.value() + j2;
    }

    @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 this.deallocationsHuge.value() + j2;
    }

    @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:22:0x0058  */
    /* JADX WARN: Removed duplicated region for block: B:26:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void reallocate(io.netty.buffer.PooledByteBuf<T> r13, int r14, boolean r15) {
        /*
            r12 = this;
            if (r14 < 0) goto L62
            int r0 = r13.maxCapacity()
            if (r14 > r0) goto L62
            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 L50
        L33:
            if (r14 >= r6) goto L50
            if (r11 >= r14) goto L4e
            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)
            goto L51
        L4e:
            r0 = r14
            goto L53
        L50:
            r14 = r0
        L51:
            r0 = r14
            r14 = r11
        L53:
            r13.setIndex(r14, r0)
            if (r15 == 0) goto L61
            io.netty.buffer.PoolThreadCache r5 = r13.cache
            r0 = r12
            r1 = r7
            r2 = r8
            r4 = r10
            r0.free(r1, r2, r4, r5)
        L61:
            return
        L62:
            java.lang.IllegalArgumentException r13 = new java.lang.IllegalArgumentException
            java.lang.String r15 = "newCapacity: "
            java.lang.String r14 = g.a.a.a.a.l(r15, r14)
            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%:");
        String str = StringUtil.NEWLINE;
        sb.append(str);
        sb.append(this.qInit);
        sb.append(str);
        sb.append("Chunk(s) at 0~50%:");
        sb.append(str);
        sb.append(this.q000);
        sb.append(str);
        sb.append("Chunk(s) at 25~75%:");
        sb.append(str);
        sb.append(this.q025);
        sb.append(str);
        sb.append("Chunk(s) at 50~100%:");
        sb.append(str);
        sb.append(this.q050);
        sb.append(str);
        sb.append("Chunk(s) at 75~100%:");
        sb.append(str);
        sb.append(this.q075);
        sb.append(str);
        sb.append("Chunk(s) at 100%:");
        sb.append(str);
        sb.append(this.q100);
        sb.append(str);
        sb.append("tiny subpages:");
        appendPoolSubPages(sb, this.tinySubpagePools);
        sb.append(str);
        sb.append("small subpages:");
        appendPoolSubPages(sb, this.smallSubpagePools);
        sb.append(str);
        return sb.toString();
    }
}
