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

leerho leerho at gmail.com
Wed Sep 29 21:19:50 UTC 2021


Nothing ��!  You are correct for this particular use case. But
*isOverlapping(segment)* is such a basic bit of information about two
segments there might be other use cases that would find this valuable.



On Wed, Sep 29, 2021 at 10:57 AM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

>
> On 29/09/2021 18:03, Lee Rhodes wrote:
> > On Tue, 28 Sep 2021 12:59:19 GMT, Julia Boes <jboes at openjdk.org> wrote:
> >
> >> This change adds a method to the MemorySegment API that detects if two
> segments are overlapping.
> > Doing byte swapping (i.e, adjusting for endianness) is not required.
>  This
> > is for copying structs from one segment to another where all the structs
> > are the same, but arbitrary size.  If we have to restrict these sizes to
> > multiples of 2,4, or 8 bytes that would be OK.  But allowing these
> structs
> > to be larger than 8 bytes is critical, otherwise we would use existing
> copy
> > methods.
>
> If you don't need byte swapping - then isn't this:
>
> ```
> static void copy(MemorySegment srcSegment, long srcOffset, MemorySegment
> dstSegment, long dstOffset, long bytes)
> ```
>
> enough for your needs? What goes wrong if I use the above copy method on
> one of your struct arrays?
>
> Maurizio
>
> >
> > On Wed, Sep 29, 2021 at 9:31 AM Radoslaw Smogura ***@***.***>
> > wrote:
> >
> >> ***@***.**** commented on this pull request.
> >> ------------------------------
> >>
> >> In
> >>
> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
> >> <
> https://github.com/openjdk/panama-foreign/pull/585#discussion_r718684769>
> >> :
> >>
> >>> +    public boolean isOverlapping(MemorySegment other) {
> >> +        AbstractMemorySegmentImpl that =
> (AbstractMemorySegmentImpl)Objects.requireNonNull(other);
> >> +        if (base() == that.base()) {  // both are either native or heap
> >> +            this.checkAccess(0, this.length, true);
> >> +            that.checkAccess(0, that.length, true);
> >> +            this.checkValidState();
> >> +            that.checkValidState();
> >> +
> >> +            final long thisStart = this.min();
> >> +            final long thatStart = that.min();
> >> +            if (thisStart == thatStart) {
> >> +                return true;
> >> +            }
> >> +            final long thisEnd = thisStart + this.byteSize() - 1L;
> >> +            final long thatEnd = thatStart + that.byteSize() - 1L;
> >> +            if (thisStart < thatStart && thisEnd >= thatStart) {
> >>
> >> Not sure if this is relevant, would it make sense to replace this
> checks by
> >> thisStart <= thatEnd && thisEnd >= thatStart
> >> I think it can be more performant.
> >>
> >> Maybe we will be able to drop subtract of 1 and use strong equality
> >>
> >> —
> >> You are receiving this because you were mentioned.
> >> Reply to this email directly, view it on GitHub
> >> <
> https://github.com/openjdk/panama-foreign/pull/585#pullrequestreview-766923138
> >,
> >> or unsubscribe
> >> <
> https://github.com/notifications/unsubscribe-auth/ADCXRQTV4KNEK3ALQ7WM5G3UEM5NVANCNFSM5E5LPKJA
> >
> >> .
> >> Triage notifications on the go with GitHub Mobile for iOS
> >> <
> https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
> >
> >> or Android
> >> <
> https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
> >.
> >>
> >>
> > -------------
> >
> > PR: https://git.openjdk.java.net/panama-foreign/pull/585
>


More information about the panama-dev mailing list