On Wed, 12 Jan 2022 18:45:11 GMT, Paul Sandoz <[email protected]> wrote:
>> When looking at larger benchmarks, I noted a discrepancy between the
>> performance of off-heap segments and on-heap segments. Looking at the
>> assembly for the `MemorySegment::asSlice` method I could see some additional
>> barriers in the off-heap case, but could not initially make sense of them.
>> Vlad pointed me at G1 (in fact no such barrier was emitted when using a
>> different GC, such as the serial GC, or ZGC), and later Erik narrowed the
>> problem down to a failure in a C2 optimization to remove barriers around
>> initializing stores. This problem was caused by a synthetic cast added by
>> javac to a value (the base object) that initialized the newly created memory
>> segment slice. Because of that case, C2 missed the store as an
>> "initializing" one, and inserted additional barriers. This patch should make
>> performance of on-heap segments a lot more reliable, especially when slicing
>> is involved.
>
> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/HeapMemorySegmentImpl.java
> line 89:
>
>> 87: public static class OfByte extends HeapMemorySegmentImpl {
>> 88:
>> 89: OfByte(long offset, Object base, long length, int mask) {
>
> Is it possible to retain the array type for the constructor?
yes, that should be harmless
-------------
PR: https://git.openjdk.java.net/jdk18/pull/97