RFR: 8337237: Use FFM instead of Unsafe for Java 2D RenderBuffer class

Jorn Vernee jvernee at openjdk.org
Fri Jul 26 00:01:33 UTC 2024


On Thu, 25 Jul 2024 23:36:46 GMT, Jorn Vernee <jvernee at 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 73:
> 
>> 71:     private final long baseAddress;
>> 72:     private long curOffset;
>> 73:     private final int capacity;
> 
> You could perhaps drop the `capacity` field, and use `segment.byteSize()` in it's place.

P.S. same for `baseAddress` I think. Looks like it's only used in `getAddress` now. Could replace with `segment.address()`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20339#discussion_r1692295777


More information about the client-libs-dev mailing list