[foreign-memaccess] RFR: JDK-8243064: Add more support for mapped memory segments

Paul Sandoz psandoz at openjdk.java.net
Fri Apr 17 19:25:55 UTC 2020


On Fri, 17 Apr 2020 11:54:12 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch adds more targeted support for mapped segments, by providing the same set operations also offered by
> MappedByteBuffer (force/load/isLoaded).
> To get there some refactoring of the undelying mapped routines was necessary so that it could be shared across
> MappedByteBuffer and MappedMemorySegment.
> One notable consequence of this work is that, in order to keep the typing sharp, I had to turn the
> MemorySegment::spliterator method from instance to static, so that I could take advantage of generic method type
> variables. With an instance method it is not possible to write a covariant override that makes sense for clients (note:
> returning `Spliterator<? extends MemorySegment>` is possible in principle, but useless in practice, as calls to e.g.
> `tryAdvance` will fail). Overall, I think that is a decent compromise.  Here's a link to the javadoc:
> http://cr.openjdk.java.net/~mcimadamore/panama/8243064/javadoc/jdk/incubator/foreign/package-summary.html
> The doc for the new memory mapped segment heavily borrows from MappedByteBuffer - I did only minor tuning here and
> there to make the doc fit better within the memory segment javadoc.
> The testing side is thin/non-existing. Unfortunately I could not find any relevant JDK test for mapped buffers that
> stressed the behavior of the various routines in a meaningful way. For instance, there's a test
> `MappedByteBuffer/Force.java` which doesn't really test anything, other than calling force() doesn't fail with some
> error. I've added a call to MappedMemorySegment::force in the buffer segment test, but I realize that this is pretty
> ad-hoc. If anybody has ideas on how to test this thing in a reliable way, suggestions are welcome :-)

Marked as reviewed by psandoz (Committer).

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

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


More information about the panama-dev mailing list