[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
Wed Jun 23 19:42:48 UTC 2021
On Tue, 22 Jun 2021 21:57:48 GMT, Lee Rhodes <github.com+12941506+leerho at openjdk.org> wrote:
>> The claim (wrt overlapping copies) is critical for successful use of the MemoryCopy methods and must be tested. The claim is similar to the one for System.arrayCopy(...) and to the current MemorySegment.copyFrom(...). If executed correctly the overlapping copy operation can be done without having to create an additional buffer. This is important for performance and memory utilization.
>>
>> The design of the test for this claim involves a self-copy of a small segment of 32 bytes to itself.
>>
>> First, a copy UP operation copies the first 24 bytes to the last 24 bytes, which is a shift up of 8 bytes. The result is tested against a manually created "truth" segment, which is what the result should look like.
>>
>> Second, a copy DOWN operation copies the last 24 bytes to the first 24 bytes, which is a shift down of 8 bytes. The result is tested against a "truth" segment for this test.
>>
>> These basic two tests are then repeated for all the variations of primitive type, copyToArray(), copyFromArray(), and additionally with non aligned shifts of 7 bytes instead of 8.
>>
>> With respect to your concern that these tests are not actually self-copies but copies between disjoint segments, I would posit that these are actually self-copies.
>>
>> In the "CopyFrom" tests, a `srcArr` is created with a sequence of values. The `dstSeg` is created from the `srcArr` using `MemorySegment.ofArray(srcArr)`, which is a just a view of the `srcArr`. Since any change in `dstSeg` also changes `srcArr` and visa versa, they cannot be disjoint.
>>
>> The test then calls MemoryCopy.copyFromArray(srcArr,...,..., dstSeg, ...), followed by an assertion.
>>
>> The "CopyTo" tests are very similar and also disjoint.
>>
>> I hope this addresses your concern.
>
> Typo: "The "CopyTo" tests are very similar and also self copies. :)
You're right, I seem to have misread the code earlier. For some reason I thought a copy to/from the `srcArr` to/from the `base` segment was happening, but looking at it now, I can see it's doing as you describe. Sorry.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/555
More information about the panama-dev
mailing list