On Mon, 6 Mar 2023 17:24:13 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>> The test has become unstable recently, there were quite a few failures, on >> Windows mostly. I was lucky enough to find a host where the test failed >> consistently. >> >> I call `System.gc()` directly as suggested in comments to the bug. I used >> `PhantomReference` instead of `WeakReference`. >> >> Now the test calls `System.gc()` in a loop and waits for the reference to be >> enqueued. In majority of cases, the test exits the loop at the second >> attempt. > > Alexey Ivanov has updated the pull request incrementally with one additional > commit since the last revision: > > Use jdk.test.lib.util.ForceGC library class to Force GC Eventually, core-libs have their own helper method in [`jdk.test.lib.util.ForceGC`](https://github.com/openjdk/jdk/blob/master/test/lib/jdk/test/lib/util/ForceGC.java). I replaced my custom waiter with `ForceGC`. I asked a question on [core-libs-dev](https://mail.openjdk.org/pipermail/core-libs-dev/2023-March/101520.html) and [hotspot-gc-dev](https://mail.openjdk.org/pipermail/hotspot-gc-dev/2023-March/041574.html). Two approaches were suggested: `ForceGC` and `WhiteBox`. I chose `ForceGC` because it is simpler and easier to use. Stuart Marks provided [a detailed reply](https://mail.openjdk.org/pipermail/core-libs-dev/2023-March/101547.html) with a couple of points: > “I'd strongly recommend using this [ForceGC] in preference to allocating a > lot of memory in order to provoke OutOfMemoryError. That technique has > historically been a cause of test flakiness, and it still is, as you've > discovered.” > “It's true that System.gc() may sometimes be ignored -- for instance if > Epsilon GC is enabled -- but for practical purposes, on Hotspot using a > standard collector, calling it will eventually cause garbage collection and > reference processing.” Thomas also advises against using OOME: > “I recommend to not use OOME for anything unless in extremely specific > situations (test OOME is triggered or something). At/after OOME the VM is in > a very precarious state that can give unexpected VM bailouts.” --- The latest revision uses a *standard* helper `ForceGC` class which is used in a number of tests. ------------- PR: https://git.openjdk.org/jdk/pull/12594