[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:39:36 UTC 2021


On Mon, 21 Jun 2021 22:10:32 GMT, Lee Rhodes <github.com+12941506+leerho at openjdk.org> wrote:

>> This comment was in the original patch - I'll fix or drop it.
>
> I think what you are seeing the extra copy is in the creation of the `truthSegment`, where an extra copy had to be used because there is no API (yet), to help the code determine which direction the copy should be performed in a self-copy scenario.  If the call to the MemoryCopy API does not perform the self-copy correctly, comparing its result with the `truthSegment` will definitely reveal an error.

Actually, I'm talking about the call to toArray here (as well as for CopyTo): 


ByteOrder bo = mode.swap ? NON_NATIVE_ORDER : NATIVE_ORDER;
//CopyFrom
Object srcArr = helper.toArray(base); // <---------------------
int srcIndex = mode.direction ? 0 : indexShifts;
int srcCopyLen = helper.length(srcArr) - indexShifts;


This call to `toArray` ends of calling one of the `MemorySegment::to*Array` methods, which always copy the contents of the segment.

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

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


More information about the panama-dev mailing list