On Fri, 26 Jul 2024 22:59:24 GMT, Phil Race <[email protected]> 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.
>
> Phil Race has updated the pull request incrementally with one additional
> commit since the last revision:
>
> 8337237
> Could this class use `{Byte,Short,Integer,Long,Double}.BYTES` instead of
> `SIZEOF_{BYTE,SHORT,INT,LONG,DOUBLE}` constants? That's what I always write
> when working with native memory, and I find it less magic-word-y. E.g.:
>
> ```java
> // putShort(short)
> curOffset += Short.BYTES;
>
> // put(short[], ...)
> position(position() + length * Short.BYTES);
> ```
Note that this code was written about a decade before that field was added to
JDK, so it I don't think you can criticise the author not using it.
But I'll use it to update the initialisation of the final fields so the uses
don't need to change.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/20339#issuecomment-2256458172