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

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Sep 5 18:11:58 UTC 2024


On Thu, 5 Sep 2024 18:02:32 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fix errors in a benchmark
>
> src/java.base/share/classes/jdk/internal/foreign/SegmentBulkOperations.java line 76:
> 
>> 74:             final int limit = (int) (dst.length & (NATIVE_THRESHOLD_FILL - 8));
>> 75:             for (; offset < limit; offset += 8) {
>> 76:                 SCOPED_MEMORY_ACCESS.putLong(dst.sessionImpl(), dst.unsafeGetBase(), dst.unsafeGetOffset() + offset, longValue);
> 
> Now that I look again at this - I think all these calls should use `putXYZUnaligned`. Otherwise alignment can introduce issues on some platforms. That will call an `Unsafe` intrinsics that will do the best possible job at serving a potentially unaligned request. This is, btw, what we use when we do e.g. `segment.get(JAVA_LONG, offset)`. Since you are using a lower-level API here, you need to make sure you use the correct memory access primitive.

This tactic should be reflected in a top-level comment in this class.

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

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


More information about the core-libs-dev mailing list