Class PoolArena<T>

java.lang.Object
io.netty.buffer.PoolArena<T>
All Implemented Interfaces:
PoolArenaMetric, SizeClassesMetric
Direct Known Subclasses:
PoolArena.DirectArena, PoolArena.HeapArena

abstract class PoolArena<T> extends java.lang.Object implements PoolArenaMetric
  • Field Details

    • HAS_UNSAFE

      private static final boolean HAS_UNSAFE
    • parent

      final PooledByteBufAllocator parent
    • smallSubpagePools

      final PoolSubpage<T>[] smallSubpagePools
    • q050

      private final PoolChunkList<T> q050
    • q025

      private final PoolChunkList<T> q025
    • q000

      private final PoolChunkList<T> q000
    • qInit

      private final PoolChunkList<T> qInit
    • q075

      private final PoolChunkList<T> q075
    • q100

      private final PoolChunkList<T> q100
    • chunkListMetrics

      private final java.util.List<PoolChunkListMetric> chunkListMetrics
    • allocationsNormal

      private long allocationsNormal
    • allocationsSmall

      private final java.util.concurrent.atomic.LongAdder allocationsSmall
    • allocationsHuge

      private final java.util.concurrent.atomic.LongAdder allocationsHuge
    • activeBytesHuge

      private final java.util.concurrent.atomic.LongAdder activeBytesHuge
    • deallocationsSmall

      private long deallocationsSmall
    • deallocationsNormal

      private long deallocationsNormal
    • pooledChunkAllocations

      private long pooledChunkAllocations
    • pooledChunkDeallocations

      private long pooledChunkDeallocations
    • deallocationsHuge

      private final java.util.concurrent.atomic.LongAdder deallocationsHuge
    • numThreadCaches

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

      private final java.util.concurrent.locks.ReentrantLock lock
    • sizeClass

      final SizeClasses sizeClass
  • Constructor Details

  • Method Details

    • newSubpagePoolHead

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

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

      abstract boolean isDirect()
    • allocate

      PooledByteBuf<T> allocate(PoolThreadCache cache, int reqCapacity, int maxCapacity)
    • allocate

      private void allocate(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity)
    • tcacheAllocateSmall

      private void tcacheAllocateSmall(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity, int sizeIdx)
    • tcacheAllocateNormal

      private void tcacheAllocateNormal(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity, int sizeIdx)
    • allocateNormal

      private void allocateNormal(PooledByteBuf<T> buf, int reqCapacity, int sizeIdx, PoolThreadCache threadCache)
    • 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)
    • sizeClass

      private static PoolArena.SizeClass sizeClass(long handle)
    • 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)
    • numThreadCaches

      public int numThreadCaches()
      Description copied from interface: PoolArenaMetric
      Returns the number of thread caches backed by this arena.
      Specified by:
      numThreadCaches in interface PoolArenaMetric
    • numTinySubpages

      public int numTinySubpages()
      Description copied from interface: PoolArenaMetric
      Returns the number of tiny sub-pages for the arena.
      Specified by:
      numTinySubpages in interface PoolArenaMetric
    • numSmallSubpages

      public int numSmallSubpages()
      Description copied from interface: PoolArenaMetric
      Returns the number of small sub-pages for the arena.
      Specified by:
      numSmallSubpages in interface PoolArenaMetric
    • numChunkLists

      public int numChunkLists()
      Description copied from interface: PoolArenaMetric
      Returns the number of chunk lists for the arena.
      Specified by:
      numChunkLists in interface PoolArenaMetric
    • tinySubpages

      public java.util.List<PoolSubpageMetric> tinySubpages()
      Description copied from interface: PoolArenaMetric
      Returns an unmodifiable List which holds PoolSubpageMetrics for tiny sub-pages.
      Specified by:
      tinySubpages in interface PoolArenaMetric
    • smallSubpages

      public java.util.List<PoolSubpageMetric> smallSubpages()
      Description copied from interface: PoolArenaMetric
      Returns an unmodifiable List which holds PoolSubpageMetrics for small sub-pages.
      Specified by:
      smallSubpages in interface PoolArenaMetric
    • chunkLists

      public java.util.List<PoolChunkListMetric> chunkLists()
      Description copied from interface: PoolArenaMetric
      Returns an unmodifiable List which holds PoolChunkListMetrics.
      Specified by:
      chunkLists in interface PoolArenaMetric
    • subPageMetricList

      private static java.util.List<PoolSubpageMetric> subPageMetricList(PoolSubpage<?>[] pages)
    • 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
    • numTinyAllocations

      public long numTinyAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of tiny allocations done via the arena.
      Specified by:
      numTinyAllocations in interface PoolArenaMetric
    • numSmallAllocations

      public long numSmallAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of small allocations done via the arena.
      Specified by:
      numSmallAllocations in interface PoolArenaMetric
    • numNormalAllocations

      public long numNormalAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of normal allocations done via the arena.
      Specified by:
      numNormalAllocations in interface PoolArenaMetric
    • numChunkAllocations

      public long numChunkAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of chunks allocations done via the arena, or -1 if not defined.
      Specified by:
      numChunkAllocations 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
    • numTinyDeallocations

      public long numTinyDeallocations()
      Description copied from interface: PoolArenaMetric
      Return the number of tiny deallocations done via the arena.
      Specified by:
      numTinyDeallocations in interface PoolArenaMetric
    • numSmallDeallocations

      public long numSmallDeallocations()
      Description copied from interface: PoolArenaMetric
      Return the number of small deallocations done via the arena.
      Specified by:
      numSmallDeallocations in interface PoolArenaMetric
    • numNormalDeallocations

      public long numNormalDeallocations()
      Description copied from interface: PoolArenaMetric
      Return the number of normal deallocations done via the arena.
      Specified by:
      numNormalDeallocations in interface PoolArenaMetric
    • numChunkDeallocations

      public long numChunkDeallocations()
      Description copied from interface: PoolArenaMetric
      Return the number of chunk deallocations done via the arena, or -1 if nor defined.
      Specified by:
      numChunkDeallocations in interface PoolArenaMetric
    • numHugeAllocations

      public long numHugeAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of huge allocations done via the arena.
      Specified by:
      numHugeAllocations in interface PoolArenaMetric
    • numHugeDeallocations

      public long numHugeDeallocations()
      Description copied from interface: PoolArenaMetric
      Return the number of huge deallocations done via the arena.
      Specified by:
      numHugeDeallocations in interface PoolArenaMetric
    • numActiveAllocations

      public long numActiveAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active allocations.
      Specified by:
      numActiveAllocations in interface PoolArenaMetric
    • numActiveTinyAllocations

      public long numActiveTinyAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active tiny allocations.
      Specified by:
      numActiveTinyAllocations in interface PoolArenaMetric
    • numActiveSmallAllocations

      public long numActiveSmallAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active small allocations.
      Specified by:
      numActiveSmallAllocations in interface PoolArenaMetric
    • numActiveNormalAllocations

      public long numActiveNormalAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active normal allocations.
      Specified by:
      numActiveNormalAllocations in interface PoolArenaMetric
    • numActiveChunks

      public long numActiveChunks()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active chunks, or -1 if not defined
      Specified by:
      numActiveChunks in interface PoolArenaMetric
    • numActiveHugeAllocations

      public long numActiveHugeAllocations()
      Description copied from interface: PoolArenaMetric
      Return the number of currently active huge allocations.
      Specified by:
      numActiveHugeAllocations 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
    • sizeIdx2sizeCompute

      public int sizeIdx2sizeCompute(int sizeIdx)
      Description copied from interface: SizeClassesMetric
      Computes size according to sizeIdx.
      Specified by:
      sizeIdx2sizeCompute 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