Top Description Inners Fields Constructors Methods
io.netty.buffer

pack-priv final Class PoolThreadCache

extends Object
Class Inheritance
Static Imports
io.netty.util.internal.ObjectUtil.checkPositiveOrZero

Acts a Thread cache for allocations. This implementation is moduled after jemalloc and the descripted technics of Scalable memory allocation using jemalloc.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private abstract static class
private static class
PoolThreadCache.NormalMemoryRegionCache<T>

Cache used for buffers which are backed by NORMAL size.

private static class
PoolThreadCache.SubPageMemoryRegionCache<T>

Cache used for buffers which are backed by TINY or SMALL size.

Field Summary

Modifier and TypeField and Description
private int
pack-priv final PoolArena<ByteBuffer>
private final AtomicBoolean
private final PoolThreadCache.FreeOnFinalize
private final int
pack-priv final PoolArena<byte[]>
private static final int
private static final InternalLogger
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[]
private final PoolThreadCache.MemoryRegionCache<byte[]>[]
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[]
private final PoolThreadCache.MemoryRegionCache<byte[]>[]

Constructor Summary

AccessConstructor and Description
pack-priv
PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold, boolean useFinalizer)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
add(PoolArena<?> area, PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass)

Add PoolChunk and handle to the cache if there is enough room.

private boolean
allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf<T> buf, int reqCapacity)

pack-priv boolean
allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)

Try to allocate a normal buffer out of the cache.

pack-priv boolean
allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)

Try to allocate a small buffer out of the cache.

private PoolThreadCache.MemoryRegionCache<?>
cache(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass)

private static <T> PoolThreadCache.MemoryRegionCache<T>
cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx)

private PoolThreadCache.MemoryRegionCache<?>
cacheForNormal(PoolArena<?> area, int sizeIdx)

private PoolThreadCache.MemoryRegionCache<?>
cacheForSmall(PoolArena<?> area, int sizeIdx)

private static void
private static <T> PoolThreadCache.MemoryRegionCache<T>[]
createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)

private static <T> PoolThreadCache.MemoryRegionCache<T>[]
createSubPageCaches(int cacheSize, int numCaches)

pack-priv void
free(boolean finalizer)

Should be called if the Thread that uses this cache is about to exist to release resources out of the cache

private static int
free(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)

private static int
free(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)

pack-priv static int
log2(int val)

pack-priv void
trim()

private static void
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationsback to summary
private int allocations
directArenaback to summary
pack-priv final PoolArena<ByteBuffer> directArena
freedback to summary
private final AtomicBoolean freed
freeOnFinalizeback to summary
private final PoolThreadCache.FreeOnFinalize freeOnFinalize
Annotations
@SuppressWarnings:unused
freeSweepAllocationThresholdback to summary
private final int freeSweepAllocationThreshold
heapArenaback to summary
pack-priv final PoolArena<byte[]> heapArena
INTEGER_SIZE_MINUS_ONEback to summary
private static final int INTEGER_SIZE_MINUS_ONE
loggerback to summary
private static final InternalLogger logger
normalDirectCachesback to summary
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[] normalDirectCaches
normalHeapCachesback to summary
private final PoolThreadCache.MemoryRegionCache<byte[]>[] normalHeapCaches
smallSubPageDirectCachesback to summary
private final PoolThreadCache.MemoryRegionCache<ByteBuffer>[] smallSubPageDirectCaches
smallSubPageHeapCachesback to summary
private final PoolThreadCache.MemoryRegionCache<byte[]>[] smallSubPageHeapCaches

Constructor Detail

PoolThreadCacheback to summary
pack-priv PoolThreadCache(PoolArena<byte[]> heapArena, PoolArena<ByteBuffer> directArena, int smallCacheSize, int normalCacheSize, int maxCachedBufferCapacity, int freeSweepAllocationThreshold, boolean useFinalizer)

Method Detail

addback to summary
pack-priv boolean add(PoolArena<?> area, PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity, PoolArena.SizeClass sizeClass)

Add PoolChunk and handle to the cache if there is enough room. Returns true if it fit into the cache false otherwise.

Annotations
@SuppressWarnings:unchecked, rawtypes
allocateback to summary
private boolean allocate(PoolThreadCache.MemoryRegionCache<?> cache, PooledByteBuf<T> buf, int reqCapacity)
Annotations
@SuppressWarnings:unchecked, rawtypes
allocateNormalback to summary
pack-priv boolean allocateNormal(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)

Try to allocate a normal buffer out of the cache. Returns true if successful false otherwise

allocateSmallback to summary
pack-priv boolean allocateSmall(PoolArena<?> area, PooledByteBuf<?> buf, int reqCapacity, int sizeIdx)

Try to allocate a small buffer out of the cache. Returns true if successful false otherwise

cacheback to summary
private PoolThreadCache.MemoryRegionCache<?> cache(PoolArena<?> area, int sizeIdx, PoolArena.SizeClass sizeClass)
cacheback to summary
private static <T> PoolThreadCache.MemoryRegionCache<T> cache(PoolThreadCache.MemoryRegionCache<T>[] cache, int sizeIdx)
cacheForNormalback to summary
private PoolThreadCache.MemoryRegionCache<?> cacheForNormal(PoolArena<?> area, int sizeIdx)
cacheForSmallback to summary
private PoolThreadCache.MemoryRegionCache<?> cacheForSmall(PoolArena<?> area, int sizeIdx)
checkCacheMayLeakback to summary
private static void checkCacheMayLeak(PoolThreadCache.MemoryRegionCache<?>[] caches, String type)
createNormalCachesback to summary
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createNormalCaches(int cacheSize, int maxCachedBufferCapacity, PoolArena<T> area)
Annotations
@SuppressWarnings:unchecked
createSubPageCachesback to summary
private static <T> PoolThreadCache.MemoryRegionCache<T>[] createSubPageCaches(int cacheSize, int numCaches)
freeback to summary
pack-priv void free(boolean finalizer)

Should be called if the Thread that uses this cache is about to exist to release resources out of the cache

freeback to summary
private static int free(PoolThreadCache.MemoryRegionCache<?>[] caches, boolean finalizer)
freeback to summary
private static int free(PoolThreadCache.MemoryRegionCache<?> cache, boolean finalizer)
log2back to summary
pack-priv static int log2(int val)
trimback to summary
pack-priv void trim()
trimback to summary
private static void trim(PoolThreadCache.MemoryRegionCache<?>[] caches)
trimback to summary
private static void trim(PoolThreadCache.MemoryRegionCache<?> cache)
io.netty.buffer back to summary

private final Class PoolThreadCache.FreeOnFinalize

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final PoolThreadCache

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private final PoolThreadCache cache

Constructor Detail

FreeOnFinalizeback to summary
private FreeOnFinalize(PoolThreadCache cache)

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@SuppressWarnings:FinalizeDeclaration, deprecation
@Override
Exceptions
Throwable:
the Exception raised by this method
io.netty.buffer back to summary

private abstract Class PoolThreadCache.MemoryRegionCache<T>

extends Object
Class Inheritance
Known Direct Subclasses
io.netty.buffer.PoolThreadCache.SubPageMemoryRegionCache, io.netty.buffer.PoolThreadCache.NormalMemoryRegionCache

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private int
private final Queue<PoolThreadCache.MemoryRegionCache.Entry<T>>
private static final ObjectPool<PoolThreadCache.MemoryRegionCache.Entry<T>>
private final int
private final PoolArena.SizeClass

Constructor Summary

AccessConstructor and Description
pack-priv
MemoryRegionCache(int size, PoolArena.SizeClass sizeClass)

Method Summary

Modifier and TypeMethod and Description
public final boolean
add(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity)

Add to cache if not already full.

public final boolean
allocate(PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Allocate something out of the cache if possible and remove the entry from the cache.

public final int
free(boolean finalizer)

Clear out this cache and free up all previous cached PoolChunks and handles.

private int
free(int max, boolean finalizer)

private void
freeEntry(PoolThreadCache.MemoryRegionCache.Entry<T> entry, boolean finalizer)

protected abstract void
initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.

private static PoolThreadCache.MemoryRegionCache.Entry<T>
newEntry(PoolChunk<?> chunk, ByteBuffer nioBuffer, long handle, int normCapacity)

public final void
trim()

Free up cached PoolChunks if not allocated frequently enough.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocationsback to summary
private int allocations
queueback to summary
private final Queue<PoolThreadCache.MemoryRegionCache.Entry<T>> queue
RECYCLERback to summary
private static final ObjectPool<PoolThreadCache.MemoryRegionCache.Entry<T>> RECYCLER
Annotations
@SuppressWarnings:rawtypes
sizeback to summary
private final int size
sizeClassback to summary
private final PoolArena.SizeClass sizeClass

Constructor Detail

MemoryRegionCacheback to summary
pack-priv MemoryRegionCache(int size, PoolArena.SizeClass sizeClass)

Method Detail

addback to summary
public final boolean add(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, int normCapacity)

Add to cache if not already full.

Annotations
@SuppressWarnings:unchecked
allocateback to summary
public final boolean allocate(PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Allocate something out of the cache if possible and remove the entry from the cache.

freeback to summary
public final int free(boolean finalizer)

Clear out this cache and free up all previous cached PoolChunks and handles.

freeback to summary
private int free(int max, boolean finalizer)
freeEntryback to summary
private void freeEntry(PoolThreadCache.MemoryRegionCache.Entry<T> entry, boolean finalizer)
Annotations
@SuppressWarnings:unchecked, rawtypes
initBufback to summary
protected abstract void initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.

newEntryback to summary
private static PoolThreadCache.MemoryRegionCache.Entry<T> newEntry(PoolChunk<?> chunk, ByteBuffer nioBuffer, long handle, int normCapacity)
Annotations
@SuppressWarnings:rawtypes
trimback to summary
public final void trim()

Free up cached PoolChunks if not allocated frequently enough.

io.netty.buffer back to summary

pack-priv final Class PoolThreadCache.MemoryRegionCache.Entry<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv PoolChunk<T>
pack-priv long
pack-priv ByteBuffer
pack-priv int
pack-priv final Recycler.EnhancedHandle<PoolThreadCache.MemoryRegionCache.Entry<?>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkback to summary
pack-priv PoolChunk<T> chunk
handleback to summary
pack-priv long handle
nioBufferback to summary
pack-priv ByteBuffer nioBuffer
normCapacityback to summary
pack-priv int normCapacity
recyclerHandleback to summary
pack-priv final Recycler.EnhancedHandle<PoolThreadCache.MemoryRegionCache.Entry<?>> recyclerHandle

Constructor Detail

Entryback to summary
pack-priv Entry(ObjectPool.Handle<PoolThreadCache.MemoryRegionCache.Entry<?>> recyclerHandle)

Method Detail

recycleback to summary
pack-priv void recycle()
unguardedRecycleback to summary
pack-priv void unguardedRecycle()
io.netty.buffer back to summary

private final Class PoolThreadCache.NormalMemoryRegionCache<T>

extends PoolThreadCache.MemoryRegionCache<T>
Class Inheritance

Cache used for buffers which are backed by NORMAL size.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Implements abstract io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.
Inherited from io.netty.buffer.PoolThreadCache.MemoryRegionCache:
addallocatefreetrim

Constructor Detail

NormalMemoryRegionCacheback to summary
pack-priv NormalMemoryRegionCache(int size)

Method Detail

initBufback to summary
protected void initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Implements abstract io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Doc from io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.

Annotations
@Override
io.netty.buffer back to summary

private final Class PoolThreadCache.SubPageMemoryRegionCache<T>

extends PoolThreadCache.MemoryRegionCache<T>
Class Inheritance

Cache used for buffers which are backed by TINY or SMALL size.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Implements abstract io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.
Inherited from io.netty.buffer.PoolThreadCache.MemoryRegionCache:
addallocatefreetrim

Constructor Detail

SubPageMemoryRegionCacheback to summary
pack-priv SubPageMemoryRegionCache(int size)

Method Detail

initBufback to summary
protected void initBuf(PoolChunk<T> chunk, ByteBuffer nioBuffer, long handle, PooledByteBuf<T> buf, int reqCapacity, PoolThreadCache threadCache)

Implements abstract io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Doc from io.netty.buffer.PoolThreadCache.MemoryRegionCache.initBuf.

Init the PooledByteBuf using the provided chunk and handle with the capacity restrictions.

Annotations
@Override