[foreign-memaccess+abi] RFR: 8305369: Issues in zero-length memory segment javadoc section

Jorn Vernee jvernee at openjdk.org
Fri Mar 31 15:25:57 UTC 2023


On Fri, 31 Mar 2023 10:44:42 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch addresses a number of issue in the zero-length memory segment javadoc section:
> 
> * there are some typo in the code samples (e.g. extra semi-colons);
> * variable names are off (e.g. spurious references to a `foreign` segment variable);
> * the explanation of how a pointer is read from a segment is lacking, and could be clarified;
> * it would be useful to have links to other section (e.g. in the Linker javadoc) which also deal with ZLMS.

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 400:

> 398:  *       int x = ptr.getAtIndex(ValueLayout.JAVA_INT, 3);            // ok
> 399:  * }
> 400:  * int x = pointer.get(ValueLayout.JAVA_INT, 3);                     // throws IllegalStateException

This doesn't look right. `pointer` is still `null` at the end. I guess `MemorySegment ptr` should just be `pointer` here?

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 414:

> 412:  *         MemoryLayout.sequenceLayout(4, ValueLayout.JAVA_INT)); // layout for int (*ptr)[4]
> 413:  * MemorySegment ptr = segment.get(intArrPtrLayout, ...);         // size = 16
> 414:  * int x = pointer.getAtIndex(ValueLayout.JAVA_INT, 3);           // ok

Suggestion:

 * int x = ptr.getAtIndex(ValueLayout.JAVA_INT, 3);           // ok

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

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/825#discussion_r1154608192
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/825#discussion_r1154610478


More information about the panama-dev mailing list