On Fri, 16 Apr 2021 19:05:25 GMT, Roger Riggs <[email protected]> wrote:
>> Peter Levart has updated the pull request incrementally with one additional
>> commit since the last revision:
>>
>> Add String.join benchmark method to StringJoinerBenchmark and adjust some
>> parameters to cover bigger range
>
> src/java.base/share/classes/java/lang/String.java line 3254:
>
>> 3252:
>> 3253: byte[] value = StringConcatHelper.newArray(((long) icoder <<
>> 32) | llen);
>> 3254: int off = 0;
>
> StringConcatHelper.newArray() can double the length (based on the coder) and
> it is then truncated to 32 bits when passed to
> UNSAFE.allocatlUnitializedArray.
> The test of length above only ensures llen can be truncated to 32 bits
> without loss of data.
I thought about that, yes. And I think we have to do the check for the doubled
length before calling the newArray. I checked the StringJoinerTest and it only
deals with ascii strings unfortunately. Will have to add a test for that too...
> src/java.base/share/classes/java/lang/String.java line 3256:
>
>> 3254: int off = 0;
>> 3255: prefix.getBytes(value, off, coder); off += prefix.length();
>> 3256: for (int i = 0; i < size; i++) {
>
> Can you save a branch inside the loop by handling element 0 outside the loop
> and
> then do the loop for the rest?
Thanks, I'll do that and then re-test to see if there's any improvement.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3501