RFR: 8339531: Improve performance of MemorySegment::mismatch [v6]

Per Minborg pminborg at openjdk.org
Thu Sep 5 13:02:30 UTC 2024


On Wed, 4 Sep 2024 10:14:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Consolidate logic in one method
>
> src/java.base/share/classes/jdk/internal/foreign/SegmentBulkOperations.java line 123:
> 
>> 121:     // This method is intended for 0 <= bytes < 7
>> 122:     @ForceInline
>> 123:     private static long mismatchSmall(AbstractMemorySegmentImpl src, long srcOffset,
> 
> Question. Isn't this:
> 
> 
> // 0...0X00
>             if (remaining >= 4) {
>                 if (SCOPED_MEMORY_ACCESS.getInt(src.sessionImpl(), src.unsafeGetBase(), src.unsafeGetOffset() + srcFromOffset + offset) !=
>                         SCOPED_MEMORY_ACCESS.getInt(dst.sessionImpl(), dst.unsafeGetBase(), dst.unsafeGetOffset() + dstFromOffset + offset)) {
>                     return mismatchSmall(src, srcFromOffset + offset, dst, dstFromOffset + offset, offset, 4, srcAndDstBytesDiffer);
>                 }
>                 offset += 4;
>                 remaining -= 4;
>             }
>             // 0...00X0
>             if (remaining >= 2) {
>                 if (SCOPED_MEMORY_ACCESS.getShort(src.sessionImpl(), src.unsafeGetBase(), src.unsafeGetOffset() + srcFromOffset + offset) !=
>                         SCOPED_MEMORY_ACCESS.getShort(dst.sessionImpl(), dst.unsafeGetBase(), dst.unsafeGetOffset() + dstFromOffset + offset)) {
>                     return mismatchSmall(src, srcFromOffset + offset, dst, dstFromOffset + offset, offset, 2, srcAndDstBytesDiffer);
>                 }
>                 offset += 2;
>                 remaining -= 2;
>             }
>             // 0...000X
>             if (remaining == 1) {
>                 if (SCOPED_MEMORY_ACCESS.getByte(src.sessionImpl(), src.unsafeGetBase(), src.unsafeGetOffset() + srcFromOffset + offset) !=
>                         SCOPED_MEMORY_ACCESS.getByte(dst.sessionImpl(), dst.unsafeGetBase(), dst.unsafeGetOffset() + dstFromOffset + offset)) {
>                     return offset;
>                 }
>             }
> 
> 
> An optimized version of "mismatchSmall" ? Can we reuse the code?

I've managed to do this now that the new optimized bit mismatch finders have removed the need for recursion in such a method.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20848#discussion_r1745491738


More information about the core-libs-dev mailing list