On Mon, 9 Sep 2024 05:01:26 GMT, David Holmes <dhol...@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. @dholmes-ora Is this really possible? The `obj` ref is passed to the PhantomReference constructor, which stores it in a field, the constructed PhantomReference is returned, and it's then used in a reachabilityFence call below. So `obj` should remain reachable the entire time, right? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20898#discussion_r1750545860