Class PoolArena<T>

    • Field Detail

      • HAS_UNSAFE

        private static final boolean HAS_UNSAFE
      • smallSubpagePools

        final PoolSubpage<T>[] smallSubpagePools
      • allocationsNormal

        private long allocationsNormal
      • allocationsSmall

        private final LongCounter allocationsSmall
      • allocationsHuge

        private final LongCounter allocationsHuge
      • activeBytesHuge

        private final LongCounter activeBytesHuge
      • deallocationsSmall

        private long deallocationsSmall
      • deallocationsNormal

        private long deallocationsNormal
      • deallocationsHuge

        private final LongCounter deallocationsHuge
      • numThreadCaches

        final java.util.concurrent.atomic.AtomicInteger numThreadCaches
      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
    • Method Detail

      • newSubpagePoolHead

        private PoolSubpage<T> newSubpagePoolHead​(int index)
      • newSubpagePoolArray

        private PoolSubpage<T>[] newSubpagePoolArray​(int size)
      • isDirect

        abstract boolean isDirect()
      • incSmallAllocation

        private void incSmallAllocation()
      • allocateHuge

        private void allocateHuge​(PooledByteBuf<T> buf,
                                  int reqCapacity)
      • free

        void free​(PoolChunk<T> chunk,
                  java.nio.ByteBuffer nioBuffer,
                  long handle,
                  int normCapacity,
                  PoolThreadCache cache)
      • freeChunk

        void freeChunk​(PoolChunk<T> chunk,
                       long handle,
                       int normCapacity,
                       PoolArena.SizeClass sizeClass,
                       java.nio.ByteBuffer nioBuffer,
                       boolean finalizer)
      • reallocate

        void reallocate​(PooledByteBuf<T> buf,
                        int newCapacity)
      • numAllocations

        public long numAllocations()
        Description copied from interface: PoolArenaMetric
        Return the number of allocations done via the arena. This includes all sizes.
        Specified by:
        numAllocations in interface PoolArenaMetric
      • numDeallocations

        public long numDeallocations()
        Description copied from interface: PoolArenaMetric
        Return the number of deallocations done via the arena. This includes all sizes.
        Specified by:
        numDeallocations in interface PoolArenaMetric
      • numActiveBytes

        public long numActiveBytes()
        Description copied from interface: PoolArenaMetric
        Return the number of active bytes that are currently allocated by the arena.
        Specified by:
        numActiveBytes in interface PoolArenaMetric
      • numPinnedBytes

        public long numPinnedBytes()
        Return an estimate of the number of bytes that are currently pinned to buffer instances, by the arena. The pinned memory is not accessible for use by any other allocation, until the buffers using have all been released.
      • newChunk

        protected abstract PoolChunk<T> newChunk​(int pageSize,
                                                 int maxPageIdx,
                                                 int pageShifts,
                                                 int chunkSize)
      • newUnpooledChunk

        protected abstract PoolChunk<T> newUnpooledChunk​(int capacity)
      • newByteBuf

        protected abstract PooledByteBuf<T> newByteBuf​(int maxCapacity)
      • memoryCopy

        protected abstract void memoryCopy​(T src,
                                           int srcOffset,
                                           PooledByteBuf<T> dst,
                                           int length)
      • destroyChunk

        protected abstract void destroyChunk​(PoolChunk<T> chunk)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • appendPoolSubPages

        private static void appendPoolSubPages​(java.lang.StringBuilder buf,
                                               PoolSubpage<?>[] subpages)
      • finalize

        protected final void finalize()
                               throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • destroyPoolSubPages

        private static void destroyPoolSubPages​(PoolSubpage<?>[] pages)
      • destroyPoolChunkLists

        private void destroyPoolChunkLists​(PoolChunkList<T>... chunkLists)
      • lock

        void lock()
      • unlock

        void unlock()
      • sizeIdx2size

        public int sizeIdx2size​(int sizeIdx)
        Description copied from interface: SizeClassesMetric
        Computes size from lookup table according to sizeIdx.
        Specified by:
        sizeIdx2size in interface SizeClassesMetric
        Returns:
        size
      • pageIdx2size

        public long pageIdx2size​(int pageIdx)
        Description copied from interface: SizeClassesMetric
        Computes size from lookup table according to pageIdx.
        Specified by:
        pageIdx2size in interface SizeClassesMetric
        Returns:
        size which is multiples of pageSize.
      • pageIdx2sizeCompute

        public long pageIdx2sizeCompute​(int pageIdx)
        Description copied from interface: SizeClassesMetric
        Computes size according to pageIdx.
        Specified by:
        pageIdx2sizeCompute in interface SizeClassesMetric
        Returns:
        size which is multiples of pageSize
      • size2SizeIdx

        public int size2SizeIdx​(int size)
        Description copied from interface: SizeClassesMetric
        Normalizes request size up to the nearest size class.
        Specified by:
        size2SizeIdx in interface SizeClassesMetric
        Parameters:
        size - request size
        Returns:
        sizeIdx of the size class
      • pages2pageIdx

        public int pages2pageIdx​(int pages)
        Description copied from interface: SizeClassesMetric
        Normalizes request size up to the nearest pageSize class.
        Specified by:
        pages2pageIdx in interface SizeClassesMetric
        Parameters:
        pages - multiples of pageSizes
        Returns:
        pageIdx of the pageSize class
      • pages2pageIdxFloor

        public int pages2pageIdxFloor​(int pages)
        Description copied from interface: SizeClassesMetric
        Normalizes request size down to the nearest pageSize class.
        Specified by:
        pages2pageIdxFloor in interface SizeClassesMetric
        Parameters:
        pages - multiples of pageSizes
        Returns:
        pageIdx of the pageSize class
      • normalizeSize

        public int normalizeSize​(int size)
        Description copied from interface: SizeClassesMetric
        Normalizes usable size that would result from allocating an object with the specified size and alignment.
        Specified by:
        normalizeSize in interface SizeClassesMetric
        Parameters:
        size - request size
        Returns:
        normalized size