[foreign-memaccess+abi] RFR: 8274157: java.foreign: Add method MemorySegment::isOverlapping

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Sep 28 23:26:48 UTC 2021


On Tue, 28 Sep 2021 23:08:13 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> If you are reluctant to return actual addresses, you could return the 4 values as relative offsets where either A_lo == 0, or B_lo == 0, or A_lo == B_lo == 0.
>> 
>> I thought I saw in one of your refactorings where you eliminated both MemoryAccess and MemoryCopy, a new general purpose copy(seg A, LayoutA, offsetA, seg B, LayoutB, offsetB, length) or something like that (I can't find it at this moment).  If the layouts can describe repeating elements of any size, doesn't this solve the copy problem and possibly eliminate the need for the isOverlapping() method?
>
> Not sure I understand correctly - but it sounds almost as if you are interested in knowing the two, maximal, non-overlapping slices of A and B?
> 
> It would help to have an example with some numeric bounds, to make sure we're talking about the same things.

> If you are reluctant to return actual addresses, you could return the 4 values as relative offsets where either A_lo == 0, or B_lo == 0, or A_lo == B_lo == 0.
> 
> I thought I saw in one of your refactorings where you eliminated both MemoryAccess and MemoryCopy, a new general purpose copy(seg A, LayoutA, offsetA, seg B, LayoutB, offsetB, length) or something like that (I can't find it at this moment). If the layouts can describe repeating elements of any size, doesn't this solve the copy problem and possibly eliminate the need for the isOverlapping() method?

The MemorySegment::copy you are referring to takes a pair of ValueLayouts, which cannot be arbitrarily big. In fact, not even the underlying `Unsafe.copyMemorySwap` can work with arbitrary element sizes.

That said, I'm still trying to understand what exactly you want to do; if you want to copy elements of N bytes from a slice to another - why isn't copying bytes enough (since the bulk copy already can deal with overlapping addresses)? Do you want to "swap" entire structs as part of the copy (that would be inefficient!).

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

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


More information about the panama-dev mailing list