RFR: 8314480: Memory ordering spec updates in java.lang.ref [v7]

Brent Christian bchristi at openjdk.org
Wed Jan 31 01:16:05 UTC 2024


On Mon, 27 Nov 2023 22:52:10 GMT, Hans Boehm <duke at openjdk.org> wrote:

>> Brent Christian has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Updates to clear() and enqueue()
>
> src/java.base/share/classes/java/lang/ref/package-info.java line 109:
> 
>> 107:  *
>> 108:  * <li>The clearing of a reference by the garbage collector <i>happens-before</i>
>> 109:  * the garbage collector enqueues the reference.</li>
> 
> Is it worth specifying this middle step? Is there a way to tell that something has been enqueued without removing the reference or calling the deprecated (and very dubious) isEnqueued method? Could we just remove this paragraph, and instead start the next one with "The clearing of a reference by the garbage collector ..."

Here, we are building a chain of _happens-befores_ that reaches from RF to dequeue (and on, to the running of the cleaning action, in the case of Cleaner).

A ref can also be cleared by a call to clear(), but that has no memory consistency effects.

So I think it's worth clarifying here that ref-clearing only forms a "link" in the _happens-before_ chain **_when performed by the GC_**.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16644#discussion_r1472189769


More information about the core-libs-dev mailing list