[foreign-memaccess+abi] RFR: 8274157: java.foreign: Add method MemorySegment::isOverlapping
Lee Rhodes
github.com+12941506+leerho at openjdk.java.net
Wed Sep 29 17:03:55 UTC 2021
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.
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