On Thu, 25 Jul 2024 23:32:02 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
>> Migrate from using Unsafe to FFM's MemorySegment API for allocating and >> setting native memory. >> This code is used by Metal, OpenGL and D3D, so I manually tested SwingSet2 >> and J2Demo as well as running all the usual tests. >> I also did some micro-benchmarking on the performance of Unsafe vs >> MemorySegment. >> The performance of either is more than sufficient for us .. ie they could be >> 10x slower and we wouldn't even notice. >> But they are in the same ballpark, and if one or the other is clearly faster >> it is the new FFM code. > > src/java.desktop/share/classes/sun/java2d/pipe/RenderBuffer.java line 175: > >> 173: int offsetInBytes = offset * SIZEOF_SHORT; >> 174: int lengthInBytes = length * SIZEOF_SHORT; >> 175: MemorySegment.copy(x, offsetInBytes, segment, JAVA_SHORT, >> curOffset, length); > > This doesn't look right. When copying from an array like this, the source > offset is an array index, not an offset in bytes. So I believe the second > argument here should just be `offset`. Ah. I was using the copy method that uses a MemorySegment wrapped array then my microbenchmark showed the unwrapped one was faster, so I made a late switch (although then did a full retest) but missed that. I think testing is still fine because offset is always zero in our code .. I will fix that, and think about the other comments. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20339#discussion_r1692409459