RFR: 8343394: Make MemorySessionImpl.state a stable field [v4]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Nov 4 10:15:34 UTC 2024
On Fri, 1 Nov 2024 10:05:22 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/foreign/SharedSession.java line 90:
>>
>>> 88: }
>>> 89:
>>> 90: STATE.setOpaque(this, CLOSED);
>>
>> Why are we using opaque semantics here and not volatile?
>
> Because this variable is not used as a synchronization device, so a stronger order is unnecessary. We still need the store to be observed by other threads when they fail an `acquire` or a `close` so opaque is appropriate here.
I'm dubious about this. Typically these modes work in a symmetric way - if you `setOpaque` you need to `getOpaque`. From [this](https://gee.cs.oswego.edu/dl/html/j9mm.html):
> Opaque mode, obtained using VarHandle getOpaque and setOpaque, adds constraints over Plain mode that provide minimal awareness of a variable that is subject to interthread access, **when all accesses use Opaque (or stronger) mode**
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21810#discussion_r1827487516
More information about the core-libs-dev
mailing list