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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Sep 28 23:10:24 UTC 2021


On Tue, 28 Sep 2021 23:07:52 GMT, Lee Rhodes <github.com+12941506+leerho at openjdk.org> wrote:

>> Returning the slice of the overlapped region is an interesting idea.
>> 
>> I was trying to think if this would be useful in computing intersections between A and B, but alas, the circumstances where this would be true are highly specialized. In the general case, if the returned slice is != null, then the lower bound of the size of the intersection is the size of the slice.  But if it is null, we know absolutely nothing.  So for intersections anyway, this is not too useful.  
>> 
>> The use-case I originally had in mind was copying non-primitive elements from A into B.  To do this efficiently, without requiring extra copying space requires that we know if there is an overlap and knowing whether A_lo <= B_lo,  or B_lo < A_lo (by address),  or if A is a subset of B.  Knowing that there exists an overlap is a big help, but to answer the rest we would need to obtain the start and end addresses of both A and B.
>> 
>> In my mind, what would be more useful than returning the overlapping slice, would be to return sufficient information so that an efficient copy from A to B could proceed immediately.  For example, returning a small array of 4 addresses: {A_lo, A_hi, B_lo, B_hi}.  This provides all the info we need for all different types of copies and moves.
>> 
>> Cheers,
>> Lee.
>
> 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.

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

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


More information about the panama-dev mailing list