Package io.netty.buffer
Class PoolArena<T>
java.lang.Object
io.netty.buffer.PoolArena<T>
- All Implemented Interfaces:
PoolArenaMetric
,SizeClassesMetric
- Direct Known Subclasses:
PoolArena.DirectArena
,PoolArena.HeapArena
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static final class
(package private) static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LongCounter
private final LongCounter
private long
private final LongCounter
private final List
<PoolChunkListMetric> private final LongCounter
private long
private long
private static final boolean
private final ReentrantLock
(package private) final AtomicInteger
(package private) final PooledByteBufAllocator
private final PoolChunkList
<T> private final PoolChunkList
<T> private final PoolChunkList
<T> private final PoolChunkList
<T> private final PoolChunkList
<T> private final PoolChunkList
<T> (package private) final SizeClasses
(package private) final PoolSubpage<T>[]
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
PoolArena
(PooledByteBufAllocator parent, SizeClasses sizeClass) -
Method Summary
Modifier and TypeMethodDescription(package private) PooledByteBuf
<T> allocate
(PoolThreadCache cache, int reqCapacity, int maxCapacity) private void
allocate
(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity) private void
allocateHuge
(PooledByteBuf<T> buf, int reqCapacity) private void
allocateNormal
(PooledByteBuf<T> buf, int reqCapacity, int sizeIdx, PoolThreadCache threadCache) private static void
appendPoolSubPages
(StringBuilder buf, PoolSubpage<?>[] subpages) Returns an unmodifiableList
which holdsPoolChunkListMetric
s.protected abstract void
destroyChunk
(PoolChunk<T> chunk) private void
destroyPoolChunkLists
(PoolChunkList<T>... chunkLists) private static void
destroyPoolSubPages
(PoolSubpage<?>[] pages) protected final void
finalize()
(package private) void
free
(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolThreadCache cache) (package private) void
freeChunk
(PoolChunk<T> chunk, long handle, int normCapacity, PoolArena.SizeClass sizeClass, ByteBuffer nioBuffer, boolean finalizer) private void
(package private) abstract boolean
isDirect()
(package private) void
lock()
protected abstract void
memoryCopy
(T src, int srcOffset, PooledByteBuf<T> dst, int length) protected abstract PooledByteBuf
<T> newByteBuf
(int maxCapacity) newChunk
(int pageSize, int maxPageIdx, int pageShifts, int chunkSize) private PoolSubpage<T>[]
newSubpagePoolArray
(int size) private PoolSubpage
<T> newSubpagePoolHead
(int index) newUnpooledChunk
(int capacity) int
normalizeSize
(int size) Normalizes usable size that would result from allocating an object with the specified size and alignment.long
Return the number of currently active allocations.long
Return the number of active bytes that are currently allocated by the arena.long
Return the number of currently active huge allocations.long
Return the number of currently active normal allocations.long
Return the number of currently active small allocations.long
Return the number of currently active tiny allocations.long
Return the number of allocations done via the arena.int
Returns the number of chunk lists for the arena.long
Return the number of deallocations done via the arena.long
Return the number of huge allocations done via the arena.long
Return the number of huge deallocations done via the arena.long
Return the number of normal allocations done via the arena.long
Return the number of normal deallocations done via the arena.long
Return an estimate of the number of bytes that are currently pinned to buffer instances, by the arena.long
Return the number of small allocations done via the arena.long
Return the number of small deallocations done via the arena.int
Returns the number of small sub-pages for the arena.int
Returns the number of thread caches backed by this arena.long
Return the number of tiny allocations done via the arena.long
Return the number of tiny deallocations done via the arena.int
Returns the number of tiny sub-pages for the arena.long
pageIdx2size
(int pageIdx) Computes size from lookup table according to pageIdx.long
pageIdx2sizeCompute
(int pageIdx) Computes size according to pageIdx.int
pages2pageIdx
(int pages) Normalizes request size up to the nearest pageSize class.int
pages2pageIdxFloor
(int pages) Normalizes request size down to the nearest pageSize class.(package private) void
reallocate
(PooledByteBuf<T> buf, int newCapacity) int
size2SizeIdx
(int size) Normalizes request size up to the nearest size class.private static PoolArena.SizeClass
sizeClass
(long handle) int
sizeIdx2size
(int sizeIdx) Computes size from lookup table according to sizeIdx.int
sizeIdx2sizeCompute
(int sizeIdx) Computes size according to sizeIdx.Returns an unmodifiableList
which holdsPoolSubpageMetric
s for small sub-pages.private static List
<PoolSubpageMetric> subPageMetricList
(PoolSubpage<?>[] pages) private void
tcacheAllocateNormal
(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity, int sizeIdx) private void
tcacheAllocateSmall
(PoolThreadCache cache, PooledByteBuf<T> buf, int reqCapacity, int sizeIdx) Returns an unmodifiableList
which holdsPoolSubpageMetric
s for tiny sub-pages.toString()
(package private) void
unlock()
-
Field Details
-
HAS_UNSAFE
private static final boolean HAS_UNSAFE -
parent
-
smallSubpagePools
-
q050
-
q025
-
q000
-
qInit
-
q075
-
q100
-
chunkListMetrics
-
allocationsNormal
private long allocationsNormal -
allocationsSmall
-
allocationsHuge
-
activeBytesHuge
-
deallocationsSmall
private long deallocationsSmall -
deallocationsNormal
private long deallocationsNormal -
deallocationsHuge
-
numThreadCaches
-
lock
-
sizeClass
-
-
Constructor Details
-
PoolArena
-
-
Method Details
-
newSubpagePoolHead
-
newSubpagePoolArray
-
isDirect
abstract boolean isDirect() -
allocate
-
allocate
-
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
-
free
void free(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolThreadCache cache) -
sizeClass
-
freeChunk
void freeChunk(PoolChunk<T> chunk, long handle, int normCapacity, PoolArena.SizeClass sizeClass, ByteBuffer nioBuffer, boolean finalizer) -
reallocate
-
numThreadCaches
public int numThreadCaches()Description copied from interface:PoolArenaMetric
Returns the number of thread caches backed by this arena.- Specified by:
numThreadCaches
in interfacePoolArenaMetric
-
numTinySubpages
public int numTinySubpages()Description copied from interface:PoolArenaMetric
Returns the number of tiny sub-pages for the arena.- Specified by:
numTinySubpages
in interfacePoolArenaMetric
-
numSmallSubpages
public int numSmallSubpages()Description copied from interface:PoolArenaMetric
Returns the number of small sub-pages for the arena.- Specified by:
numSmallSubpages
in interfacePoolArenaMetric
-
numChunkLists
public int numChunkLists()Description copied from interface:PoolArenaMetric
Returns the number of chunk lists for the arena.- Specified by:
numChunkLists
in interfacePoolArenaMetric
-
tinySubpages
Description copied from interface:PoolArenaMetric
Returns an unmodifiableList
which holdsPoolSubpageMetric
s for tiny sub-pages.- Specified by:
tinySubpages
in interfacePoolArenaMetric
-
smallSubpages
Description copied from interface:PoolArenaMetric
Returns an unmodifiableList
which holdsPoolSubpageMetric
s for small sub-pages.- Specified by:
smallSubpages
in interfacePoolArenaMetric
-
chunkLists
Description copied from interface:PoolArenaMetric
Returns an unmodifiableList
which holdsPoolChunkListMetric
s.- Specified by:
chunkLists
in interfacePoolArenaMetric
-
subPageMetricList
-
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 interfacePoolArenaMetric
-
numTinyAllocations
public long numTinyAllocations()Description copied from interface:PoolArenaMetric
Return the number of tiny allocations done via the arena.- Specified by:
numTinyAllocations
in interfacePoolArenaMetric
-
numSmallAllocations
public long numSmallAllocations()Description copied from interface:PoolArenaMetric
Return the number of small allocations done via the arena.- Specified by:
numSmallAllocations
in interfacePoolArenaMetric
-
numNormalAllocations
public long numNormalAllocations()Description copied from interface:PoolArenaMetric
Return the number of normal allocations done via the arena.- Specified by:
numNormalAllocations
in interfacePoolArenaMetric
-
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 interfacePoolArenaMetric
-
numTinyDeallocations
public long numTinyDeallocations()Description copied from interface:PoolArenaMetric
Return the number of tiny deallocations done via the arena.- Specified by:
numTinyDeallocations
in interfacePoolArenaMetric
-
numSmallDeallocations
public long numSmallDeallocations()Description copied from interface:PoolArenaMetric
Return the number of small deallocations done via the arena.- Specified by:
numSmallDeallocations
in interfacePoolArenaMetric
-
numNormalDeallocations
public long numNormalDeallocations()Description copied from interface:PoolArenaMetric
Return the number of normal deallocations done via the arena.- Specified by:
numNormalDeallocations
in interfacePoolArenaMetric
-
numHugeAllocations
public long numHugeAllocations()Description copied from interface:PoolArenaMetric
Return the number of huge allocations done via the arena.- Specified by:
numHugeAllocations
in interfacePoolArenaMetric
-
numHugeDeallocations
public long numHugeDeallocations()Description copied from interface:PoolArenaMetric
Return the number of huge deallocations done via the arena.- Specified by:
numHugeDeallocations
in interfacePoolArenaMetric
-
numActiveAllocations
public long numActiveAllocations()Description copied from interface:PoolArenaMetric
Return the number of currently active allocations.- Specified by:
numActiveAllocations
in interfacePoolArenaMetric
-
numActiveTinyAllocations
public long numActiveTinyAllocations()Description copied from interface:PoolArenaMetric
Return the number of currently active tiny allocations.- Specified by:
numActiveTinyAllocations
in interfacePoolArenaMetric
-
numActiveSmallAllocations
public long numActiveSmallAllocations()Description copied from interface:PoolArenaMetric
Return the number of currently active small allocations.- Specified by:
numActiveSmallAllocations
in interfacePoolArenaMetric
-
numActiveNormalAllocations
public long numActiveNormalAllocations()Description copied from interface:PoolArenaMetric
Return the number of currently active normal allocations.- Specified by:
numActiveNormalAllocations
in interfacePoolArenaMetric
-
numActiveHugeAllocations
public long numActiveHugeAllocations()Description copied from interface:PoolArenaMetric
Return the number of currently active huge allocations.- Specified by:
numActiveHugeAllocations
in interfacePoolArenaMetric
-
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 interfacePoolArenaMetric
-
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
-
newUnpooledChunk
-
newByteBuf
-
memoryCopy
-
destroyChunk
-
toString
-
appendPoolSubPages
-
finalize
-
destroyPoolSubPages
-
destroyPoolChunkLists
-
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 interfaceSizeClassesMetric
- Returns:
- size
-
sizeIdx2sizeCompute
public int sizeIdx2sizeCompute(int sizeIdx) Description copied from interface:SizeClassesMetric
Computes size according to sizeIdx.- Specified by:
sizeIdx2sizeCompute
in interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- 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 interfaceSizeClassesMetric
- Parameters:
size
- request size- Returns:
- normalized size
-