RFR: 8339687: Rearrange reachabilityFence()s in jdk.test.lib.util.ForceGC
Daniel Fuchs
dfuchs at openjdk.org
Mon Sep 9 14:44:10 UTC 2024
On Mon, 9 Sep 2024 05:01:26 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> test/lib/jdk/test/lib/util/ForceGC.java line 82:
>>
>>> 80: PhantomReference<Object> ref = new PhantomReference<>(obj, queue);
>>> 81: Reference.reachabilityFence(obj);
>>> 82: obj = null;
>>
>> You're right to question the utility of calling reachabilityFence(obj) after obj has been nulled out. But I'm still questioning the utility of calling RF(obj) at all. We don't care when obj is determined to be unreachable; what we care about is that the GC has done some reference processing. Seems to me we can simplify the above lines to
>>
>> PhantomReference<Object> ref = new PhantomReference<>(new Object(), queue);
>>
>> and get rid of the local variable obj entirely.
>
> The reason for the explicit reference and RF, as I recall, is to guard against the allocation of the new object being elided entirely, with the `PhantomReference` constructor being passed null (or itself being elided) and no reference processing ever actually happening.
What David says ;-)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20898#discussion_r1750394382
More information about the core-libs-dev
mailing list