[foreign-memaccess+abi] RFR: 8274157: java.foreign: Add method MemorySegment::isOverlapping [v2]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Oct 1 12:51:38 UTC 2021
On Fri, 1 Oct 2021 12:20:33 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 five commits:
>
> - 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
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 333:
> 331: *
> 332: * @param other the segment to test for an overlap with this segment.
> 333: * @return a new memory segment, or {@code null} if no overlap occurs.
Should we say a "new slice of this segment" instead of "a new segment" (both here an in the first sentence of the javadoc) ?
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 350:
> 348: * segment, or -1L if no overlap occurs.
> 349: */
> 350: long offsetOf(MemorySegment other);
I think what I had in mind was slightly different:
* return postive, or negative offsets in case of overlaps (of course in the case of sub-slices, offsets will always be positive)
* throw if asked to compute an offset from heap to non-heap (or vice-versa).
src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 261:
> 259: long offsetFromThat = that.offsetOf(this);
> 260: long newSize = Math.min(this.byteSize() - offsetFromThis, that.byteSize() - offsetFromThat);
> 261: return dup(offsetFromThis, newSize, mask, scope);
nitpick: you can probably use asSlice instead of dup?
test/jdk/java/foreign/TestSegmentOffsetOf.java line 1:
> 1: /*
We used to have a test for MemoryAddress.segmentOffset...
https://github.com/openjdk/jdk/blob/master/test/jdk/java/foreign/TestRebase.java
I wonder if that old test can be put to new use?
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/585
More information about the panama-dev
mailing list