[foreign-memaccess+abi] RFR: 8270376: Finalize API for memory copy [v9]

Paul Sandoz psandoz at openjdk.java.net
Fri Aug 6 17:41:40 UTC 2021


On Fri, 6 Aug 2021 17:01:10 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This patch ties up some loose ends with the MemoryCopy API, and it also prepares the ground for some other related refactorings in this area.
>> 
>> The meat of this patch is represented by the various changes in MemoryCopy, where all methods were renamed to simply `copy`, and the length parameter (now called `elementCount`) is always moved to the end.
>> 
>> I've also simplified naming of parameters, as I think distinguishing between `index` and `offset` is enough (e.g. an array has an index, a segment has an offset).
>> 
>> You will see that, at the very end of the class, three more copy methods have been added, which deal fully in terms of segments. I have also moved the complex layout-based memory segment copy operation (which does the swap) as a static method in this class, as I believe the static form makes the method more regular and usable.
>> 
>> I've made some changes to our uses of `copyFrom` in the linker, to use the new methods in `MemoryCopy` when the copy operation was performing slicing in the source/target segment, which I think makes the code more readable. Of course these changes are completely optional and could be omitted as well.
>
> Maurizio Cimadamore has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
> 
>   Revert name of accessors in MemoryAccess

Re: `MemorySegment.toXArray`, yes good point. I think we could remove these. They are a bit like the `Arrays.copyOf/Range` methods. Not suggesting we such methods.

Re: `MemorySegment.copyFrom`, my inclination is to keep the one copy arg method. and move all others to static methods on `MemorySegment` with signatures consistent with `System.arraycopy` (lets keep methods on `MemoryAccess` for accesses with primitives).
If we keep the one arg method i would rename it `copy` and flip the dst/src, and returning dst.

Now you got me looking at `MemorySegment.fill`! Arguably that is a bulk copy broadcasting a scalar, like `Arrays.fill`.

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

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


More information about the panama-dev mailing list