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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Apr 20 17:09:29 UTC 2020


> 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 :-)

Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:

  Add unload() API point to mark mapped segment as 'no longer used'.

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

Changes:
  - all: https://git.openjdk.java.net/panama-foreign/pull/115/files
  - new: https://git.openjdk.java.net/panama-foreign/pull/115/files/2313601f..aee9a909

Webrevs:
 - full: https://webrevs.openjdk.java.net/panama-foreign/115/webrev.01
 - incr: https://webrevs.openjdk.java.net/panama-foreign/115/webrev.00-01

  Stats: 56 lines in 7 files changed: 55 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/115.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/115/head:pull/115

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


More information about the panama-dev mailing list