Skip to content

Pooled Array Wrapper - #1167

Open
RuffledPlume wants to merge 11 commits into
117HD:masterfrom
RuffledPlume:PooledArrayChanges
Open

Pooled Array Wrapper#1167
RuffledPlume wants to merge 11 commits into
117HD:masterfrom
RuffledPlume:PooledArrayChanges

Conversation

@RuffledPlume

@RuffledPlume RuffledPlume commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Instead of PooledArrayType returning a raw array, it instead returns a wrapper to help track & manage arrays

Added Borrow Contexts to help track leaks via Cleaner API so that if a PooledArray is garbage collected whist still borrowed, which could lead to erroneous behavior since the Object has been revived after GC

@RuffledPlume
RuffledPlume force-pushed the PooledArrayChanges branch 3 times, most recently from 27d3823 to 1b69f4a Compare August 11, 2026 23:38
Instead of `PooledArrayType` returning a raw array, it instead returns a wrapper to help track & manage arrays

Added Borrow Contexts to help track leaks
@RuffledPlume
RuffledPlume marked this pull request as ready for review August 11, 2026 23:39
@RuffledPlume

RuffledPlume commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@aHooder Thoughts on including this into the release? I think I'd prefer if it we're, even if it means delaying the release a little bit, just because this makes the PooledArray API significantly more robust, since where no longer returning raw arrays but wrapped/tracked objects.

This PR should make it safer and easier to debug if any issues occur in Prod, since before we could only check for double release by looping through the queue, whereas now it's built into the wrapper along with additional debugging info:

04:59:40.917 [Test worker] WARN  r.h.u.c.PooledArrayType        - Attempted to use a PooledArray after it was released back to the pool (borrowed by Thread-1-Test worker, released by Thread-1-Test worker, attempted access by Thread-1-Test worker)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.getArray(PooledArrayType.java:488)
	rs117.hd.tests.PooledArrayTest.testGetArrayAfterRelease_logsBorrowReleaseAndAccessThreadIds(PooledArrayTest.java:81)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

04:59:40.925 [Test worker] WARN  r.h.u.c.PooledArrayType        - Attempted to use a PooledArray after it was released back to the pool (borrowed by Thread-27-Unknown, released by Thread-1-Test worker, attempted access by Thread-1-Test worker)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.getArray(PooledArrayType.java:488)
	rs117.hd.tests.PooledArrayTest.testCrossThreadBorrowAndRelease_recordsDistinctThreadIds(PooledArrayTest.java:146)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

04:59:40.927 [Test worker] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@102cec62 (borrowed by Thread-1-Test worker, previously released by Thread-1-Test worker, this release attempted by Thread-1-Test worker)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.testDoubleRelease_logsBorrowinggetId(PooledArrayTest.java:107)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

04:59:40.935 [pool-1-thread-8] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@aff0cdf (borrowed by Thread-35-pool-1-thread-8, previously released by Thread-35-pool-1-thread-8, this release attempted by Thread-35-pool-1-thread-8)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.937 [pool-1-thread-7] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@7ba9c65c (borrowed by Thread-34-pool-1-thread-7, previously released by Thread-34-pool-1-thread-7, this release attempted by Thread-34-pool-1-thread-7)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.935 [pool-1-thread-1] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@66e3f3c (borrowed by Thread-28-pool-1-thread-1, previously released by Thread-28-pool-1-thread-1, this release attempted by Thread-28-pool-1-thread-1)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.936 [pool-1-thread-2] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@44552343 (borrowed by Thread-29-pool-1-thread-2, previously released by Thread-29-pool-1-thread-2, this release attempted by Thread-29-pool-1-thread-2)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.936 [pool-1-thread-3] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@719abec (borrowed by Thread-30-pool-1-thread-3, previously released by Thread-30-pool-1-thread-3, this release attempted by Thread-30-pool-1-thread-3)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.937 [pool-1-thread-5] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@4ec3d80e (borrowed by Thread-32-pool-1-thread-5, previously released by Thread-32-pool-1-thread-5, this release attempted by Thread-32-pool-1-thread-5)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.936 [pool-1-thread-6] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@2eb15fc9 (borrowed by Thread-33-pool-1-thread-6, previously released by Thread-33-pool-1-thread-6, this release attempted by Thread-33-pool-1-thread-6)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

04:59:40.937 [pool-1-thread-4] WARN  r.h.u.c.PooledArrayType        - Attempted to release a PooledArray that's already back in the pool: INT[16]@1a04ece5 (borrowed by Thread-31-pool-1-thread-4, previously released by Thread-31-pool-1-thread-4, this release attempted by Thread-31-pool-1-thread-4)
	rs117.hd.utils.collections.PooledArrayType.release(PooledArrayType.java:293)
	rs117.hd.utils.collections.PooledArrayType$PooledArray.close(PooledArrayType.java:514)
	rs117.hd.tests.PooledArrayTest.lambda$testConcurrentDoubleRelease_eachThreadLogsItsOwnThreadIdOnly$3(PooledArrayTest.java:195)
	java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)

@RuffledPlume
RuffledPlume force-pushed the PooledArrayChanges branch 9 times, most recently from af9954a to 033179e Compare August 19, 2026 03:37
Switch from AtomicLong to AtomicAdder

TreiberStack now Extends AtomicReference to avoid the additional object

Tweaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant