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

Henry Jen henry.jen at oracle.com
Tue Jun 30 17:48:56 UTC 2020


I am leaning toward to separate “Type access” as a different concern, as Paul illustrated earlier like to have something like “MemoryAccess” to deal with typed access. In the future, it can either got absorbed into boxes types.

The existing instance methods seems reasonable to be where they are today without mixing 'carrier type’ concept.

Cheers,
Henry

> On Jun 30, 2020, at 10:09 AM, Maurizio Cimadamore <mcimadamore at openjdk.java.net> wrote:
> 
> 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