[foreign-memaccess] RFR: Alternative scalable MemoryScope
Peter Levart
plevart at openjdk.java.net
Tue May 5 07:55:15 UTC 2020
On Mon, 4 May 2020 21:39:18 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> This is an alternative MemoryScope which is more scalable when used in a scenario where child scope is frequently
>> acquired and closed concurrently from multiple threads (for example in parallel Stream.findAny())
>
> I think this should work under the well-defined `Spliterator` use case but might be problematic if made public sometime
> later on. For example:
> MemorySegment s = ...
> var a = s.acquire();
> a.close();
> var d = s.dup();
> a.acquire(); // transiently affecting state of d since the adders are shared
>
> There also might be ways to poke a `Spliterator` to induce such behaviour e.g. the `Consumer` passed to `tryAdvance`
> creating a new `Spliterator` from the given segment, and operating on that after the `tryAdvance` completes. Clearly
> that's not what someone should be doing but it's starting complex enough that it's hard to reason about the possible
> effects and whether they are harmless or not, at least for me :-)
So, in your scenario:
MemorySegment s = ...
var a = s.acquire();
a.close();
var d = s.dup();
a.acquire(); // transiently affecting state of d since the adders are shared
...the a.acquire() will fail, because s.state == CLOSED, but the shared acquires.sum() will briefly be greater than
releases.sum() and therefore could affect d.close() in a way that it would cause spurious failure of d.close(). This is
of course undesirable (like it was undesirable to have spurious failures of acquire() in previous versions of this
MemoryScope until I added a two-phase close), so it would be best to not share the acquires/releases LongAdders with a
duped MemoryScope. I'll fix this by creating new LongAdder instances for duped scope. Thanks.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/142
More information about the panama-dev
mailing list