[jdk18] RFR: 8279527: Dereferencing segments backed by different scopes leads to pollution [v2]

Paul Sandoz psandoz at openjdk.java.net
Wed Jan 5 18:28:22 UTC 2022


On Wed, 5 Jan 2022 17:57:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/ResourceScopeImpl.java line 190:
>> 
>>> 188:     @ForceInline
>>> 189:     public final void checkValidState() {
>>> 190:         if (owner != null && owner != Thread.currentThread()) {
>> 
>> For consistency we could change code `checkValidStateSlow` to refer directly to `owner`.
>> 
>> It would be satisfying, but I don't know if it's possible, to compose `checkValidStateSlow` from `checkValidState` e.g.
>> 
>> public final checkValidStateSlow() {
>>     checkValidState();
>>     if (!isAlive() { ... }
>> }
>
> I'll change use of `owner`. It's not really possible to write checkValidStateSlow in terms of checkValidState, because the latter does a plain read of the state, whereas the former does a volatile read. Reusing one from the other would result in two reads (a plain and a volatile).

Ok. My thought was that since this is slow two reads do not matter, but i did not reason fully about the concurrent implications (if the fast alive check returns false, the slow alive check can still return true so that seems good, if the fast check returns true i was presume the slow alive check would also be true, given the way state changes monotonically?)

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

PR: https://git.openjdk.java.net/jdk18/pull/82


More information about the core-libs-dev mailing list