On Thu, 18 May 2023 15:44:15 GMT, Alan Bateman <[email protected]> wrote:
> ThreadContainers is an internal class used to make thread pools and other
> groupings of threads discoverable for observability. Some refactoring in 2021
> (in the loom repo, and before integration) accidentally changed the creation
> of a weak reference so that it no longer associated with the reference queue.
> The result is that stale refs aren't expunged from a CHM, leading to a memory
> leak. The change to fix the issue is trivial.
>
> Tests for memory leaks can be problematic, often more trouble than they are
> worth. I started with a test that polls the size of the internal CHM but
> decided to ditch it. Instead, the test is simple. It just runs for a few
> seconds creating ExecuorService implementations (including TPE, TPPE, and
> FJP), unreferencing them without shutdown (so they don't terminate and
> unregister). This is enough to causes OOME with product builds a small heap.
test/jdk/java/util/concurrent/Executors/UnreferencedExecutor.java line 38:
> 36: int ncores = Runtime.getRuntime().availableProcessors();
> 37: long start = System.currentTimeMillis();
> 38: while (System.currentTimeMillis() - start < 5000) {
@AlanBateman Might want to have this based on `nanoTime()` such that changes to
wall-clock doesn't impact the length of the run of the test.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14047#discussion_r1198690117