[foreign-memaccess] [Rev 01] RFR: Move "owner" field and thread-confinement checks to MemoryScope

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri May 15 11:52:56 UTC 2020

On Fri, 15 May 2020 11:45:14 GMT, Peter Levart <plevart at openjdk.org> wrote:

>> Now MemoryScope is simplified, I re-based this change and am opening this PR on top. Currently MemorySegment is
>> encapsulating thread-confinement logic and state (owner field) while MemoryScope is encapsulating temporal-confinement
>> logic and state. But the interplay between the two must be very carefully caried out (for example, close() or dup() on
>> child scopes may only be called in owner thread). By moving the thread-confinement logic and state to MemoryScope, I
>> think we get better encapsulation as all MemoryScope methods become "safe" - some can still be called in owner thread
>> only, but failing to do so throws IllegalSateException instead of exhibiting undefined behavior.
> Peter Levart has updated the pull request incrementally with one additional commit since the last revision:
>   Improvements to MemoryScope code considering Maurizio's comments.

Looks good. Thanks.

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryScope.java line 259:

> 258:         void close() {
> 259:             justClose();
> 260:             if (cleanupAction != null) {

This is exactly what I had in mind - I think the code is cleaner. Perhaps rename `justClose` to `doClose` (and make
`doClose` private) - but that's minor - I'll leave that up to you.


Marked as reviewed by mcimadamore (Committer).

PR: https://git.openjdk.java.net/panama-foreign/pull/167

More information about the panama-dev mailing list