Reduce the scope of synchronized block in PoolArena (#10410)
Motivation: We shouldn't call incSmallAllocation() in a synchronized block as its backed by a concurrent datastructure Modifications: Move call of incSmallAllocation() out of synchronized block Result: Minimize scope of synchronized block
This commit is contained in:
parent
9f89eb6429
commit
4e86f768b9
@ -157,21 +157,24 @@ abstract class PoolArena<T> extends SizeClasses implements PoolArenaMetric {
|
||||
* {@link PoolChunk#free(long)} may modify the doubly linked list as well.
|
||||
*/
|
||||
final PoolSubpage<T> head = smallSubpagePools[sizeIdx];
|
||||
final boolean needsNormalAllocation;
|
||||
synchronized (head) {
|
||||
final PoolSubpage<T> s = head.next;
|
||||
if (s != head) {
|
||||
needsNormalAllocation = s == head;
|
||||
if (!needsNormalAllocation) {
|
||||
assert s.doNotDestroy && s.elemSize == sizeIdx2size(sizeIdx);
|
||||
long handle = s.allocate();
|
||||
assert handle >= 0;
|
||||
s.chunk.initBufWithSubpage(buf, null, handle, reqCapacity, cache);
|
||||
incSmallAllocation();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
allocateNormal(buf, reqCapacity, sizeIdx, cache);
|
||||
if (needsNormalAllocation) {
|
||||
synchronized (this) {
|
||||
allocateNormal(buf, reqCapacity, sizeIdx, cache);
|
||||
}
|
||||
}
|
||||
|
||||
incSmallAllocation();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user