Cleanup PoolChunk / PoolSubpage and add a few more asserts (#10690)
Motivation: As the PooledByteBufAllocator is a critical part of netty we should ensure it works as expected. Modifications: - Add a few more asserts to ensure we not see any corrupted state - Null out slot in the subpage array once the subpage was freed and removed from the pool - Merge methods into constructor as it was only called from the constructor anyway. Result: Code cleanup
This commit is contained in:
parent
0ed788c15e
commit
9563d2bd61
@ -435,6 +435,7 @@ final class PoolChunk<T> implements PoolChunkMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int runOffset = runOffset(runHandle);
|
int runOffset = runOffset(runHandle);
|
||||||
|
assert subpages[runOffset] == null;
|
||||||
int elemSize = arena.sizeIdx2size(sizeIdx);
|
int elemSize = arena.sizeIdx2size(sizeIdx);
|
||||||
|
|
||||||
PoolSubpage<T> subpage = new PoolSubpage<T>(head, this, pageShifts, runOffset,
|
PoolSubpage<T> subpage = new PoolSubpage<T>(head, this, pageShifts, runOffset,
|
||||||
@ -457,7 +458,8 @@ final class PoolChunk<T> implements PoolChunkMetric {
|
|||||||
int sizeIdx = arena.size2SizeIdx(normCapacity);
|
int sizeIdx = arena.size2SizeIdx(normCapacity);
|
||||||
PoolSubpage<T> head = arena.findSubpagePoolHead(sizeIdx);
|
PoolSubpage<T> head = arena.findSubpagePoolHead(sizeIdx);
|
||||||
|
|
||||||
PoolSubpage<T> subpage = subpages[runOffset(handle)];
|
int sIdx = runOffset(handle);
|
||||||
|
PoolSubpage<T> subpage = subpages[sIdx];
|
||||||
assert subpage != null && subpage.doNotDestroy;
|
assert subpage != null && subpage.doNotDestroy;
|
||||||
|
|
||||||
// Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it.
|
// Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it.
|
||||||
@ -467,6 +469,9 @@ final class PoolChunk<T> implements PoolChunkMetric {
|
|||||||
//the subpage is still used, do not free it
|
//the subpage is still used, do not free it
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
assert !subpage.doNotDestroy;
|
||||||
|
// Null out slot in the array as it was freed and we should not use it anymore.
|
||||||
|
subpages[sIdx] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +60,7 @@ final class PoolSubpage<T> implements PoolSubpageMetric {
|
|||||||
this.runSize = runSize;
|
this.runSize = runSize;
|
||||||
this.elemSize = elemSize;
|
this.elemSize = elemSize;
|
||||||
bitmap = new long[runSize >>> 6 + LOG2_QUANTUM]; // runSize / 64 / QUANTUM
|
bitmap = new long[runSize >>> 6 + LOG2_QUANTUM]; // runSize / 64 / QUANTUM
|
||||||
init(head, elemSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
void init(PoolSubpage<T> head, int elemSize) {
|
|
||||||
doNotDestroy = true;
|
doNotDestroy = true;
|
||||||
if (elemSize != 0) {
|
if (elemSize != 0) {
|
||||||
maxNumElems = numAvail = runSize / elemSize;
|
maxNumElems = numAvail = runSize / elemSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user