Skip to content

Multi-threaded/parallel allocation#259

Merged
chrisvest merged 41 commits intomainfrom
mt-alloc
Jan 28, 2026
Merged

Multi-threaded/parallel allocation#259
chrisvest merged 41 commits intomainfrom
mt-alloc

Conversation

@chrisvest
Copy link
Owner

@chrisvest chrisvest commented Jan 12, 2026

Allow the pool to populate faster by allocating multiple objects in parallel.

This adds asynchronous methods to Allocator and Reallocator for their respective operations.
The background allocation thread will use these if the pool has been configured with a PoolBuilder.setMaxConcurrentAllocations value greater than one.
Default implementations of these methods are provided, which will spawn a virtual thread for each operation.

A few fixes to leak detection have also been implemented, due to shortcomings made apparent by the asynchronous allocator operations. For instance, reallocation previously did not re-register the reallocated object. There were also a possibility of false-positives, from the references to deallocated objects being cleared before their corresponding slot had been deregistered with the leak detector. A few flaky tests in that area have also been fixed.

This fixes #216

This works by starting virtual threads to do the object allocations, when the allocation concurrency is greater than one.
They are false positives because we can add methods to an interface when it is sealed and does not permit external implementations.

See revapi/revapi#304
They now rely on count down latches to assert concurrent allocator calls, rather than relying on timing.
This makes them more robust.
@chrisvest chrisvest requested a review from Copilot January 24, 2026 23:14
@chrisvest chrisvest marked this pull request as ready for review January 24, 2026 23:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for faster pool population by allowing allocations (and related allocator work) to run concurrently, addressing issue #216.

Changes:

  • Introduces allocator async hooks (allocateAsync/deallocateAsync and reallocateAsync) and updates timing adaptors to record latency for async operations.
  • Adds PoolBuilder#setMaxConcurrentAllocations(...) (default 1) and wires it into the threaded allocation controller to run allocator work in parallel.
  • Expands/adjusts blackbox tests and testkits to exercise concurrent allocation/deallocation/reallocation and async failure propagation.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
src/main/java/stormpot/Allocator.java Adds default async allocation/deallocation methods.
src/main/java/stormpot/Reallocator.java Adds default async reallocation method.
src/main/java/stormpot/PoolBuilder.java Adds configuration API for max concurrent allocations + docs.
src/main/java/stormpot/Pool.java Javadoc typo fix.
src/main/java/stormpot/internal/PoolBuilderImpl.java Stores/reads allocation concurrency setting and updates defaults/thread setup.
src/main/java/stormpot/internal/PoolBuilderDefaults.java Adds default allocation concurrency field.
src/main/java/stormpot/internal/BAllocThread.java Implements parallel allocator work and async completion handling.
src/main/java/stormpot/internal/Task.java Extends task model to include async completions and switch signals.
src/main/java/stormpot/internal/AsyncAllocationCompletion.java New task type for delivering async allocation results back to allocator thread.
src/main/java/stormpot/internal/AsyncDeallocationCompletion.java New task type for delivering async deallocation completion back to allocator thread.
src/main/java/stormpot/internal/AllocatorSwitchRequestPending.java New task type to wake allocator thread for allocator-switch processing.
src/main/java/stormpot/internal/ReallocatingAdaptor.java Forwards async allocate/deallocate to underlying allocator.
src/main/java/stormpot/internal/TimingReallocatingAdaptor.java Adds metrics recording for async allocate/deallocate.
src/main/java/stormpot/internal/TimingReallocatorAdaptor.java Adds metrics recording for async reallocate.
src/main/java/stormpot/internal/IdentityHashSet.java Tweaks insertion selection logic.
src/test/java/stormpot/tests/blackbox/ThreadBasedPoolTest.java Adds concurrency/async propagation tests for threaded pools.
src/test/java/stormpot/tests/blackbox/ThreadBasedWithConcurrentAllocationPoolTest.java New threaded-pool variant configured for concurrent allocations.
src/test/java/stormpot/tests/blackbox/AllocatorBasedPoolTest.java Adjusts leak test mechanics and allocation-order test behavior.
src/test/java/testkits/AlloKit.java Makes action sequencing thread-safe for concurrent test execution.
src/test/java/testkits/DelegateAllocator.java New wrapper allocator used by async tests.
src/test/java/testkits/DelegateReallocator.java New wrapper reallocator used by async tests.
api-changes.json Revapi suppression entries for the new PoolBuilder interface methods.

…ble instead of exception

Otherwise, an Error being thrown from the synchronous operations would cause the CompletableFuture to never be completed.
This setting is not supported by inline or direct allocation
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 9 comments.

Comments suppressed due to low confidence (1)

src/main/java/stormpot/PoolBuilder.java:176

  • The Javadoc for precise leak detection says it’s enabled by default (both here and in the setter docs), but PoolBuilderTest.preciseLeakDetectionMustBeDisabledByDefault asserts the default is disabled. Please align the documentation with the actual default behavior (or update the default if the docs are correct).
  /**
   * Return whether precise object leak detection is enabled, which is
   * the case by default.
   *
   * @return {@code true} if precise object leak detection is enabled.
   * @see #setPreciseLeakDetectionEnabled(boolean)
   */
  boolean isPreciseLeakDetectionEnabled();

  /**
   * Enable or disable precise object leak detection. It is enabled by default.
   * Precise object leak detection makes the pool keep an eye on the allocated

@chrisvest chrisvest merged commit 610595a into main Jan 28, 2026
19 checks passed
@chrisvest chrisvest deleted the mt-alloc branch January 28, 2026 05:32
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.

Allow multi-threaded object initialization with optional deallocation call

1 participant