From 734c18b84bde57514ed0d99261d450b07bbc0d7d Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Mon, 27 May 2024 14:25:10 -0700 Subject: [PATCH] Fix pool shrinking with new allocations Make BAllocThread.reduceSizeByDeallocating() call refill on the disregardPile and the newAllocations. Otherwise, the pool might not be able to deallocate objects allocated but unused prior to a new target size being set. This is normally not a big deal for pools that have any sort of activity, but the `ThreadedPoolTest.decreasingSizeMustNotDeallocateTlrClaimedObjects` test could end up in an infinite loop, and break the build. --- src/main/java/stormpot/BAllocThread.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/stormpot/BAllocThread.java b/src/main/java/stormpot/BAllocThread.java index b89c4f37..6cb344ce 100644 --- a/src/main/java/stormpot/BAllocThread.java +++ b/src/main/java/stormpot/BAllocThread.java @@ -154,6 +154,10 @@ private void increaseSizeByAllocating() { } private void reduceSizeByDeallocating(BSlot slot) { + if (slot == null || !didAnythingLastIteration) { + disregardPile.refill(); + newAllocations.refill(); + } slot = slot == null ? live.poll() : slot; if (slot != null) { if (slot.isDead() || slot.live2dead()) {