RFR: 8314480: Memory ordering spec updates in java.lang.ref [v28]
Viktor Klang
vklang at openjdk.org
Sat Apr 27 12:03:12 UTC 2024
On Fri, 26 Apr 2024 17:59:39 GMT, Brent Christian <bchristi at openjdk.org> wrote:
>> Classes in the `java.lang.ref` package would benefit from an update to bring the spec in line with how the VM already behaves. The changes would focus on _happens-before_ edges at some key points during reference processing.
>>
>> A couple key things we want to be able to say are:
>> - `Reference.reachabilityFence(x)` _happens-before_ reference processing occurs for 'x'.
>> - `Cleaner.register()` _happens-before_ the Cleaner thread runs the registered cleaning action.
>>
>> This will bring Cleaner in line (or close) with the memory visibility guarantees made for finalizers in [JLS 17.4.5](https://docs.oracle.com/javase/specs/jls/se18/html/jls-17.html#jls-17.4.5):
>> _"There is a happens-before edge from the end of a constructor of an object to the start of a finalizer (§12.6) for that object."_
>
> Brent Christian has updated the pull request incrementally with one additional commit since the last revision:
>
> new section for finalizer memviz
src/java.base/share/classes/java/lang/ref/package-info.java line 137:
> 135: * <a id="MemoryConsistency"></a>
> 136: * <h2>Memory Consistency Properties</h2>
> 137: * Certain interactions between references, references queues, and the garbage
Suggestion:
* Certain interactions between references, reference queues, and the garbage
src/java.base/share/classes/java/lang/ref/package-info.java line 157:
> 155: * <li>The dequeuing of a reference to a
> 156: * {@linkplain Cleaner#register(Object object, Runnable action) registered}
> 157: * object, by a Cleaner thread, <i>happens-before</i> that Cleaner thread runs
Are we committing to this? I.e. that there will always be a single Cleaner thread? (i.e. one could imagine a situation where you have one polling thread which executes the cleaning action on some other thread?)
src/java.base/share/classes/java/lang/ref/package-info.java line 176:
> 174: * <li>Actions in a thread prior to calling
> 175: * {@link Reference#reachabilityFence Reference.reachabilityFence(x)}
> 176: * <i>happen-before</i> the finalizer for x is run by a finalizer thread.</li>
Suggestion:
* <i>happen-before</i> the finalizer for {@code x} is run by a finalizer thread.</li>
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16644#discussion_r1581818740
PR Review Comment: https://git.openjdk.org/jdk/pull/16644#discussion_r1581818931
PR Review Comment: https://git.openjdk.org/jdk/pull/16644#discussion_r1581819080
More information about the core-libs-dev
mailing list