On Fri, 4 Sep 2026 14:29:20 GMT, Maurizio Cimadamore <[email protected]> 
wrote:

>> This PR proposes to fix a bug in the `MemorySegment::asOverlapingSlice` 
>> which incorrectly computes the size of the overlapping region. 
>> 
>> A parameterized test is also proposed via this PR
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
>  line 248:
> 
>> 246:     public final Optional<MemorySegment> 
>> asOverlappingSlice(MemorySegment other) {
>> 247:         final AbstractMemorySegmentImpl that = 
>> (AbstractMemorySegmentImpl)Objects.requireNonNull(other);
>> 248:         if (unsafeGetBase() == that.unsafeGetBase()) { // both either 
>> native or the same heap segment
> 
> Why was `overlaps` inlined here, and then not even removed?

It was inlined because otherwise we would have made duplicate calculations. The 
reason the old `overlaps` is retained is that we need that for bulk copying so 
that we can ensure there is no aliasing in the optimized path.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32707#discussion_r3935093338

Reply via email to