[foreign-memaccess] RFR 8234073: Add support for deterministic shared segments

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Nov 13 08:58:42 UTC 2019


Hi,
in the latest iteration, we added support for shared memory segments - 
that is, memory segments that can be shared (and accessed) across 
multiple threads. This came at the cost of sacrificing one of our goals: 
deterministic deallocation; the story there was something like: if the 
segment is confined, deallocation is deterministic, but if the segment 
is shared, you cannot call close() - which sends you back to the 
ByteBuffer non-deterministic deallocation model (for shared segments).

We believe we now have found a way to have both deterministic 
deallocation and shared segments - all bundled in a relatively 
inoffensive API. What this patch does, is, it removes all the state 
transition between confined and shared - all segments now have the 
potential to be shared - no state transition is needed.

Each segment is born with a thread owner - like before; if you want to 
access the segment from a thread other than the owner, the second thread 
must 'acquire' the segment (this is, in fact, the only new API method we 
need to support shared segments in full). Doing acquire gives the second 
thread a 'view' of the segment that can be used to work within that 
particular thread. When the second segment has finished working with the 
segment, he must close() the view. Internally, a view counter is 
maintained in the original shared segment, so that the shared segment 
cannot be close if there are still confined views being used by other 
threads.

With this simple move we reclaim back deterministic deallocation, and we 
also significantly simplify the API.

Webrev:

http://cr.openjdk.java.net/~mcimadamore/panama/8234073/

Javadoc:

http://cr.openjdk.java.net/~mcimadamore/panama/8234073_javadoc/jdk/incubator/foreign/package-summary.html

Note: as part of this changeset I've also removed the reachability 
fences on the memory VarHandle implementation. Since now we no longer 
rely on cleaners, there's no risk that a segment could 'disappear' in 
the middle of an access operation. I've also did a bit of an overhaul of 
the javadoc when it comes to explain the concept associated with 
segments and concurrent access.

Cheers
Maurizio



More information about the panama-dev mailing list