[foreign-memaccess] RFR: RFC: move factories and helper methods to new MemorySegments class

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Jun 30 17:09:38 UTC 2020


This patch explores moving several static factories and methods (as well as some instance ones such as
fill/copy/mismatch) onto a separate "sidecar" class, namely `MemorySegments`.

I guess overall the approach is defensible, but the API feels a bit less tight:

* having segment factories in a different class than `MemorySegment` feels odd
* `segment.fill(42)` reads better than `MemorySegments.fill(segment, 42)`

There might be an argument that this patch is overrotating towards the static, helper class approach, but then the
question is where to draw the line between essential and non-essential stuff.

One possibility would be to:

* keep copy/mismatch/fill where they are (instance methods in MemorySegment)
* keep MemorySegment.allocateNative where it is
* move MemorySegment.mapFromPath to MappedMemorySegment
* move all the view-y factories, as well as array and buffer projections, and accessors on the sidecar class
* perhaps, move the static spliterator method in the sidecar as well

Any thoughts?

Javadoc for this revision available here:
http://cr.openjdk.java.net/~mcimadamore/panama/memaccess-segments-helpers/javadoc/jdk/incubator/foreign/package-summary.html

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

Commit messages:
 - Move ancillary methods out to new MemorySegments class
 - Remove whitespaces
 - Add simple benchmark for static helpers
 - Remove whitespace
 - Initial push

Changes: https://git.openjdk.java.net/panama-foreign/pull/223/files
 Webrev: https://webrevs.openjdk.java.net/panama-foreign/223/webrev.00
  Stats: 2192 lines in 37 files changed: 1394 ins; 486 del; 312 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/223.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/223/head:pull/223

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


More information about the panama-dev mailing list