[foreign-memaccess] RFR: 8248487: Add static helpers to access segments (continued)

Jorn Vernee jvernee at openjdk.java.net
Fri Jul 3 15:31:25 UTC 2020


On Fri, 3 Jul 2020 14:15:24 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> Following some feedback from jextract experiments, we have noted that, while the set of primitive accessors is the
> right one to expose, as it is the most primitive (and others can be derived from that), usability-wise we lose a bit
> when it comes to perform dereference at offset 0 (in which case an extra offset 0 has to be specified), or a
> dereference with a logical index (e.g. `p[i] = ...`).  To overcome these issues, I've added two additional variants of
> static accessors - now:
> * `getByte_LE(MemoryAddress addr)` -> dereference at given address
> * `getByteAtOffset(MemoryAddress, byte offset)` -> dereference at given address + offset (in bytes)
> * `getByteAtIndex(MemoryAddress, long index)` -> dereference at given logical index (where offset = index * stride)
> 
> Looking at TestByteBuffer, this immediately seem to make things better.

Marked as reviewed by jvernee (Committer).

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAccess.java line 19:

> 18:  * which take an <em>base</em> address and a <em>logical</em> element index. The formula to obtain the byte offset
> {@code O} from an 19:  * index {@code I} is given by {@code O = I * S} where {@code s} is the size (expressed in bytes)
> of the element to 20:  * be dereferenced.

Suggestion:

 * index {@code I} is given by {@code O = I * S} where {@code S} is the size (expressed in bytes) of the element to

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

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


More information about the panama-dev mailing list