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

Per Minborg pminborg at openjdk.org
Fri Jul 26 06:54:32 UTC 2024


On Thu, 25 Jul 2024 22:53:36 GMT, Phil Race <prr 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 60:

> 58:     private static final int SIZEOF_FLOAT  = 4;
> 59:     private static final int SIZEOF_LONG   = 8;
> 60:     private static final int SIZEOF_DOUBLE = 8;

These fields could be eliminated and replaced with e.g. `JAVA_LONG.byteSize()` . I do not think the `int` vs. `long` matters that much if at all.

src/java.desktop/share/classes/sun/java2d/pipe/RenderBuffer.java line 70:

> 68:     private static final int COPY_FROM_ARRAY_THRESHOLD = 10;
> 69: 
> 70:     MemorySegment segment;

Could we use `private final` for this field?

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

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


More information about the client-libs-dev mailing list