RFR: 8323552: AbstractMemorySegmentImpl#mismatch returns -1 when comparing distinct areas of the same instance of MemorySegment [v2]

Jorn Vernee jvernee at openjdk.org
Thu Jan 11 15:26:25 UTC 2024


On Thu, 11 Jan 2024 13:30:44 GMT, Peter Levart <plevart at openjdk.org> wrote:

>> I belive there is a bug in `AbstractMemorySegmentImpl#mismatch` method. It returns `-1` (meaning that regions are equal) when passing the same instance of MemorySegment as both `srcSegment` and `dstSegment` parameters regardless of whether `srcFromOffset` and `dstFromOffset` as well as `srcToOffset` and `dstToOffset` are also equal.
>> 
>> Am I right?
>
> Peter Levart has updated the pull request incrementally with one additional commit since the last revision:
> 
>   move special-case check for equal segments to the instance method (more probable)

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 299:

> 297:             checkValidState();
> 298:             return -1;
> 299:         }

I'm skeptical of trying to optimize this without a more thorough performance investigation. We shouldn't add this complexity on a whim.

I'm more in favor of just dropping the check from the static mismatch method and leaving it at that. (And adding a test as Maurizio mentioned).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17354#discussion_r1449022827


More information about the core-libs-dev mailing list