RFR: 8300727: java/awt/List/ListGarbageCollectionTest/AwtListGarbageCollectionTest.java failed with "List wasn't garbage collected"
Alexey Ivanov
aivanov at openjdk.org
Mon Feb 27 15:45:16 UTC 2023
On Sun, 26 Feb 2023 05:21:59 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
> > Yes, I saw this method, and [it periodically calls System.gc()](https://github.com/openjdk/jdk/blob/b4ea80731c6c0a0328a9801590ba5b081f08c3bd/test/jdk/javax/swing/regtesthelpers/Util.java#L102-L103).
>
> It generates OOM to make sure that gc will be called, unlike System.gc() which per the spec can be ignored.
Can be but it's not ignored, it's respected.
I provided you at least two tests which solely rely on `System.gc()` and they don't fail.
> > I still don't understand your concern. How is generating OutOfMemoryError better than calling System.gc()?
>
> That method uses both, which I suggested doing at the start.
You didn't suggest, at least explicitly, using `Util.generateOOME`.
Nevertheless, I think generating OOME is *redundant*, it adds another level of complexity and makes the test slower.
The flag `-Xmx100m` can be safely removed from the test now: it doesn't affect how quick the reference object is cleared.
> It is better to follow one approach than implement different patterns here and there.
Perhaps, the time has come to change the approach: ditch generating OOME and just use `System.gc()` . We've always done this, but it doesn't mean it's the best approach, does it?
If the developers write tests to verify `Reference` objects are cleared without generating OOME by relying only on `System.gc()`, I see no reason why client-libs shouldn't follow the same pattern. The old tests which use `Util.generateOOME` could be retrofitted to the new pattern.
-------------
PR: https://git.openjdk.org/jdk/pull/12594
More information about the client-libs-dev
mailing list