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

Phil Race prr at openjdk.org
Fri Jul 26 22:59:29 UTC 2024


On Thu, 25 Jul 2024 23:45:27 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Phil Race has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8337237
>
> src/java.desktop/share/classes/sun/java2d/pipe/RenderBuffer.java line 176:
> 
>> 174:             int lengthInBytes = length * SIZEOF_SHORT;
>> 175:             MemorySegment.copy(x, offsetInBytes, segment, JAVA_SHORT, curOffset, length);
>> 176:             position(position() + lengthInBytes);
> 
> If you want, you could use `MemoryLayout::scale` here, i.e.
> Suggestion:
> 
>             position(JAVA_SHORT.scale(position(), length));
> 
> (up to preference though)

I guess that would allow me to get rid of lengthInBytes.
But this scale API does one of the things in FFM that I find too easy to cause mistakes - the first param is offset count in bytes and the second param is the the one that is scaled by the layout size.
One might assume both are scaled since it is called scale(), not scaleIndex(), You have to pay close attention.
And that's what caught me out switching from one copy() overload to another.

So I tried it, and I didn't like it as much as the existing code.
I did however get rid of the lengthInBytes variable.

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

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


More information about the client-libs-dev mailing list