< prev index next > src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
Print this page
final long thatStart = that.unsafeGetOffset();
final long thisEnd = thisStart + this.byteSize();
final long thatEnd = thatStart + that.byteSize();
if (thisStart < thatEnd && thisEnd > thatStart) { //overlap occurs
! long offsetToThat = this.segmentOffset(that);
long newOffset = offsetToThat >= 0 ? offsetToThat : 0;
return Optional.of(asSlice(newOffset, Math.min(this.byteSize() - newOffset, that.byteSize() + offsetToThat)));
}
}
return Optional.empty();
}
- @Override
- public final long segmentOffset(MemorySegment other) {
- AbstractMemorySegmentImpl that = (AbstractMemorySegmentImpl) Objects.requireNonNull(other);
- if (unsafeGetBase() == that.unsafeGetBase()) {
- return that.unsafeGetOffset() - this.unsafeGetOffset();
- }
- throw new UnsupportedOperationException("Cannot compute offset from native to heap (or vice versa).");
- }
-
@Override
public void load() {
throw notAMappedSegment();
}
final long thatStart = that.unsafeGetOffset();
final long thisEnd = thisStart + this.byteSize();
final long thatEnd = thatStart + that.byteSize();
if (thisStart < thatEnd && thisEnd > thatStart) { //overlap occurs
! long offsetToThat = that.address() - this.address();
long newOffset = offsetToThat >= 0 ? offsetToThat : 0;
return Optional.of(asSlice(newOffset, Math.min(this.byteSize() - newOffset, that.byteSize() + offsetToThat)));
}
}
return Optional.empty();
}
@Override
public void load() {
throw notAMappedSegment();
}
< prev index next >