RFR: 8357959: (bf) ByteBuffer.allocateDirect initialization can result in large TTSP spikes [v7]
Aleksey Shipilev
shade at openjdk.org
Tue Jun 3 10:07:53 UTC 2025
On Tue, 3 Jun 2025 09:47:01 GMT, Rohitash Kumar <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/nio/Bits.java line 260:
>>
>>> 258: offset += len;
>>> 259: }
>>> 260: }
>>
>> So this becomes:
>>
>> Suggestion:
>>
>> static void setMemory(long srcAddr, long count, byte value) {
>> long offset = 0;
>> while (offset < count) {
>> long len = Math.min(UNSAFE_SET_THRESHOLD, count - offset);
>> UNSAFE.setMemory(srcAddr + offset, len, value);
>> offset += len;
>> }
>> }
>
> It might be trival but isn't it better to keep `len` declaration outside of while loop?
I don't think so, reliability argument wins: put the variables in their closest scope. Here, for example, it shows directly that `len` is (re-)defined for every iteration. There are hardly any performance implications of doing this, barring compiler nitpicks.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25487#discussion_r2123349452
More information about the nio-dev
mailing list