[foreign-memaccess+abi] RFR: Add support for high-level functions to copy to and from Java arrays [v2]

Jorn Vernee jvernee at openjdk.java.net
Tue Jun 22 02:34:35 UTC 2021


On Mon, 21 Jun 2021 20:44:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryCopy.java line 40:
>> 
>>> 38:  * <p>
>>> 39:  * Copy operations defined in this class accept a <em>byte order</em> parameter. If the specified byte order is different
>>> 40:  * from the <em>native</em> byte order, a byte swap operation is performed on each array elements
>> 
>> This seems somewhat roundabout. Why not accept a `boolean swap` instead?
>
> That seems consistent with MemoryAccess, to be honest. And with every other access operation which touches segments in the API.

True. Ok, that actually makes sense now that I compare it with what memaccess var handles do. i.e. the byte order always corresponds to the memory segment, since the array is of course in native order. So, in practice this means a swap occurs when the specified or is non-native. Thanks.

>> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 405:
>> 
>>> 403:      * @param src the source segment.
>>> 404:      * @param srcElementLayout the element layout associated with the source segment.
>>> 405:      * @throws IndexOutOfBoundsException if {@code src.byteSize() > this.byteSize()}.
>> 
>> Maybe this should be strengthened to require both segments to be the same size? (Otherwise I guess there's quickly a question of 'why can't I specify a destination offset here').
>
> For now, that is consistent with what the other `MemorySegment::copyFrom` does.

Ok, makes sense.

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

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


More information about the panama-dev mailing list