final class PoolChunk<T> extends java.lang.Object implements PoolChunkMetric
Modifier and Type | Field and Description |
---|---|
(package private) PoolArena<T> |
arena |
private int |
chunkSize |
private byte[] |
depthMap |
private int |
freeBytes |
private static int |
INTEGER_SIZE_MINUS_ONE |
private int |
log2ChunkSize |
private int |
maxOrder |
private int |
maxSubpageAllocs |
(package private) T |
memory |
private byte[] |
memoryMap |
(package private) PoolChunk<T> |
next |
private int |
pageShifts |
private int |
pageSize |
(package private) PoolChunkList<T> |
parent |
(package private) PoolChunk<T> |
prev |
private int |
subpageOverflowMask
Used to determine if the requested capacity is equal to or greater than pageSize.
|
private PoolSubpage<T>[] |
subpages |
(package private) boolean |
unpooled |
private byte |
unusable
Used to mark memory as unusable
|
Constructor and Description |
---|
PoolChunk(PoolArena<T> arena,
T memory,
int size)
Creates a special chunk that is not pooled.
|
PoolChunk(PoolArena<T> arena,
T memory,
int pageSize,
int maxOrder,
int pageShifts,
int chunkSize) |
Modifier and Type | Method and Description |
---|---|
(package private) long |
allocate(int normCapacity) |
private int |
allocateNode(int d)
Algorithm to allocate an index in memoryMap when we query for a free node
at depth d
|
private long |
allocateRun(int normCapacity)
Allocate a run of pages (>=1)
|
private long |
allocateSubpage(int normCapacity)
Create/ initialize a new PoolSubpage of normCapacity
Any PoolSubpage created/ initialized here is added to subpage pool in the PoolArena that owns this PoolChunk
|
private static int |
bitmapIdx(long handle) |
int |
chunkSize()
Return the size of the chunk in bytes, this is the maximum of bytes that can be served out of the chunk.
|
private byte |
depth(int id) |
(package private) void |
destroy() |
(package private) void |
free(long handle)
Free a subpage or a run of pages
When a subpage is freed from PoolSubpage, it might be added back to subpage pool of the owning PoolArena
If the subpage pool in PoolArena has at least one other PoolSubpage of given elemSize, we can
completely free the owning Page so it is available for subsequent allocations
|
int |
freeBytes()
Return the number of free bytes in the chunk.
|
(package private) void |
initBuf(PooledByteBuf<T> buf,
long handle,
int reqCapacity) |
(package private) void |
initBufWithSubpage(PooledByteBuf<T> buf,
long handle,
int reqCapacity) |
private void |
initBufWithSubpage(PooledByteBuf<T> buf,
long handle,
int bitmapIdx,
int reqCapacity) |
private static int |
log2(int val) |
private static int |
memoryMapIdx(long handle) |
private PoolSubpage<T>[] |
newSubpageArray(int size) |
private int |
runLength(int id) |
private int |
runOffset(int id) |
private void |
setValue(int id,
byte val) |
private int |
subpageIdx(int memoryMapIdx) |
java.lang.String |
toString() |
private void |
updateParentsAlloc(int id)
Update method used by allocate
This is triggered only when a successor is allocated and all its predecessors
need to update their state
The minimal depth at which subtree rooted at id has some free space
|
private void |
updateParentsFree(int id)
Update method used by free
This needs to handle the special case when both children are completely free
in which case parent be directly allocated on request of size = child-size * 2
|
int |
usage()
Return the percentage of the current usage of the chunk.
|
private byte |
value(int id) |
private static final int INTEGER_SIZE_MINUS_ONE
final T memory
final boolean unpooled
private final byte[] memoryMap
private final byte[] depthMap
private final PoolSubpage<T>[] subpages
private final int subpageOverflowMask
private final int pageSize
private final int pageShifts
private final int maxOrder
private final int chunkSize
private final int log2ChunkSize
private final int maxSubpageAllocs
private final byte unusable
private int freeBytes
PoolChunkList<T> parent
PoolChunk(PoolArena<T> arena, T memory, int pageSize, int maxOrder, int pageShifts, int chunkSize)
private PoolSubpage<T>[] newSubpageArray(int size)
public int usage()
PoolChunkMetric
usage
in interface PoolChunkMetric
long allocate(int normCapacity)
private void updateParentsAlloc(int id)
id
- idprivate void updateParentsFree(int id)
id
- idprivate int allocateNode(int d)
d
- depthprivate long allocateRun(int normCapacity)
normCapacity
- normalized capacityprivate long allocateSubpage(int normCapacity)
normCapacity
- normalized capacityvoid free(long handle)
handle
- handle to freevoid initBuf(PooledByteBuf<T> buf, long handle, int reqCapacity)
void initBufWithSubpage(PooledByteBuf<T> buf, long handle, int reqCapacity)
private void initBufWithSubpage(PooledByteBuf<T> buf, long handle, int bitmapIdx, int reqCapacity)
private byte value(int id)
private void setValue(int id, byte val)
private byte depth(int id)
private static int log2(int val)
private int runLength(int id)
private int runOffset(int id)
private int subpageIdx(int memoryMapIdx)
private static int memoryMapIdx(long handle)
private static int bitmapIdx(long handle)
public int chunkSize()
PoolChunkMetric
chunkSize
in interface PoolChunkMetric
public int freeBytes()
PoolChunkMetric
freeBytes
in interface PoolChunkMetric
public java.lang.String toString()
toString
in class java.lang.Object
void destroy()