On Thu, 23 Feb 2023 20:14:11 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>>>For this reason, GC logs are enabled. If, for whatever reason, the call to >>>System.gc() is ignored, we'll see it in the test log. Then a specific GC >>>could be selected, for example, or another fix implemented. >> >> As of now this test can be executed with different GC, and some of them can >> skip System.gc(). >> >>>OOME does not guarantee a full GC cycle either. >> >> But it guarantee that at least some GC will be always run, unlike >> System.gc(). > > I followed the piece of advice in the [JBS > comment](https://bugs.openjdk.org/browse/JDK-8300727?focusedCommentId=14560139&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14560139). > > If using `System.gc()` is good enough for testing references: > > https://github.com/openjdk/jdk/blob/f612dcfebea7ffd4390f833646ad45d6f0ebd04f/test/jdk/java/lang/ref/ReferenceEnqueue.java#L54-L60 > > https://github.com/openjdk/jdk/blob/f612dcfebea7ffd4390f833646ad45d6f0ebd04f/test/jdk/java/lang/ref/PhantomReferentClearing.java#L85-L92 > > Then it should be good enough for this test too. > > Perhaps, the same effect could be achieved by causing OOME in a loop. > However, using `System.gc()` makes the intention clearer: *run GC*, wait for > the phantom reference to be cleared and enqueued. > > I can explicitly select a GC: `-XX:+UseG1GC` (default) or `-XX:+UseSerialGC`. There are lots of tests that rely on System.gc() actually triggering a gc. SFAIK all collectors we have today will obey it unless you use -XX:+DisableExplicitGC If you can make the test work with that then that would be interesting but calling just System.gc() is no worse than all those other tests. ------------- PR: https://git.openjdk.org/jdk/pull/12594