[foreign-memaccess+abi] RFR: 8274157: java.foreign: Add method MemorySegment::isOverlapping
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Sep 29 21:50:29 UTC 2021
On 29/09/2021 22:19, leerho wrote:
> 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.
Ok - point taken.
And I think that, since we dropped MemoryAddress::segmentOffset (out of
necessity), having some other way to find the offset of a segment
relative to each other might come in handy anyway.
Maurizio
>
>
>
> On Wed, Sep 29, 2021 at 10:57 AM Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com
> <mailto: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
> <mailto: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
> <https://urldefense.com/v3/__https://github.com/openjdk/panama-foreign/pull/585*discussion_r718684769__;Iw!!ACWV5N9M2RV99hQ!YR8HDJD74V1BfaqWbh75wuy6g0jfIjp8pChFyiDl_oEP910hwCtOuZdedUpK-vUC74L_JBU$>>
> >> :
> >>
> >>> + 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
> <https://urldefense.com/v3/__https://github.com/openjdk/panama-foreign/pull/585*pullrequestreview-766923138__;Iw!!ACWV5N9M2RV99hQ!YR8HDJD74V1BfaqWbh75wuy6g0jfIjp8pChFyiDl_oEP910hwCtOuZdedUpK-vUC6rpjK-o$>>,
> >> or unsubscribe
> >>
> <https://github.com/notifications/unsubscribe-auth/ADCXRQTV4KNEK3ALQ7WM5G3UEM5NVANCNFSM5E5LPKJA
> <https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/ADCXRQTV4KNEK3ALQ7WM5G3UEM5NVANCNFSM5E5LPKJA__;!!ACWV5N9M2RV99hQ!YR8HDJD74V1BfaqWbh75wuy6g0jfIjp8pChFyiDl_oEP910hwCtOuZdedUpK-vUCUSwpexk$>>
> >> .
> >> 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
> <https://urldefense.com/v3/__https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675__;!!ACWV5N9M2RV99hQ!YR8HDJD74V1BfaqWbh75wuy6g0jfIjp8pChFyiDl_oEP910hwCtOuZdedUpK-vUCqS9w8WM$>>
> >> or Android
> >>
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
> <https://urldefense.com/v3/__https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign*3Dnotification-email*26utm_medium*3Demail*26utm_source*3Dgithub__;JSUlJSU!!ACWV5N9M2RV99hQ!YR8HDJD74V1BfaqWbh75wuy6g0jfIjp8pChFyiDl_oEP910hwCtOuZdedUpK-vUC-T-cBQk$>>.
> >>
> >>
> > -------------
> >
> > PR: https://git.openjdk.java.net/panama-foreign/pull/585
> <https://git.openjdk.java.net/panama-foreign/pull/585>
>
More information about the panama-dev
mailing list