[foreign-memaccess] RFR 8223712: Investigate more fluent LayoutPath API

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri May 10 15:24:45 UTC 2019


Hi,
after some discussion with Brian, here's an attempt to make the 
LayoutPath lookup API simpler, by removing the Stream-returning lookup 
method.

Now, you just ask a path out of a layout (the path you obtain is rooted 
there), and then you proceed from there calling various builder-like 
methods - example:

Sequence seq = Sequence.of(20,
                 Sequence.of(10,
                       Group.struct(
                             Padding.of(32),
                             Value.ofUnsignedInt(32).withName("elem")
                       )
                 ));


seq.toPath()
                 .sequenceElement()
                 .sequenceElement()
                 .groupElement("elem")


I've also added support for 'by-index' lookups, so the above can also be 
written by this:

seq.toPath()
                 .sequenceElement()
                 .sequenceElement()
                 .groupElement(1)


Webrev:

http://cr.openjdk.java.net/~mcimadamore/panama/8223712/


As a side-bar, I'm growing more and more skeptical about the 
relationship between Sequence and Group; there are sequences that cannot 
be represented as groups:

* if sequence has more than 2^32 elements (in which case we cannot 
create a big enough group for it)
* if sequence has an unknown arity (which we know in the case of native 
interop can happen)

The latter case is important - when you have a pointer, languages are 
typically very loose as to whether you point to ONE element of that 
kind, or MANY. It would be nice to be able to model these different 
cases with different layouts.

Maurizio







More information about the panama-dev mailing list