[foreign-memaccess] RFR: JDK-8243064: Add more support for mapped memory segments
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Apr 17 12:04:47 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 :-)
-------------
Commit messages:
- Fix javadoc for MemorySegment/MappedMemorySegment
- Add MappedMemorySegment subclass
- Moved load/isLoaded/force onto separate helper class
Changes: https://git.openjdk.java.net/panama-foreign/pull/115/files
Webrev: https://webrevs.openjdk.java.net/panama-foreign/115/webrev.00
Issue: https://bugs.openjdk.java.net/browse/JDK-JDK-8243064
Stats: 938 lines in 21 files changed: 562 ins; 333 del; 43 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