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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Oct 4 17:46:26 UTC 2021


On Mon, 4 Oct 2021 17:14:39 GMT, Julia Boes <jboes at openjdk.org> wrote:

>> This change adds a method to the MemorySegment API that detects if two segments are overlapping.
>
> Julia Boes has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains eight commits:
> 
>  - address PR comments
>  - Merge branch 'foreign-memaccess+abi' into memseg-overlap
>  - add test for overlap and offsetOf and update names
>  - Merge branch 'foreign-memaccess+abi' into memseg-overlap
>  - refactor to overlap(MemorySegment), add offsetOf(MemorySegment)
>  - Merge branch 'foreign-memaccess+abi' into memseg-overlap
>  - address PR comments
>  - initial change

Looks good - added an optional javadoc clarification.

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 342:

> 340:      * segment.
> 341:      *
> 342:      * <p>The offset is relative to the base address of this segment and can be

Perhaps we could add something like:

For instance, if both segments are native segments, the resulting offset can be computed as follows:

other.baseAddress().toRawLongValue() - segment.baseAddress().toRawLongValue()

So that it hints at how the method fully operates. Then you can conclude with the sentence which says we return `0` if base is the same. I'd also add another sentence to say that if `other` is a slice of this segment, then the offset is always `0 <= x <= byteSize()`.

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

Marked as reviewed by mcimadamore (Committer).

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


More information about the panama-dev mailing list