RFR: 8371164: ArrayList.addAll() optimizations [v2]
Jason Mehrens
duke at openjdk.org
Wed Nov 5 03:00:01 UTC 2025
On Tue, 4 Nov 2025 20:38:35 GMT, jengebr <duke at openjdk.org> wrote:
>> That variant is incorrect since `size <= a.length`, potentially adding a surprising tail of `null` elements to the list.
>
> Thank you both! @cl4es splitting it out had zero performance impact (per the benchmark). As you said, it's a bit subjective... how strongly do you feel? Other opinions are welcome too.
I would think that you need to check `src.modCount` has same value at start and end of the method.
final int expectedSrcModCount = src.modCount;
//access src internals....
checkForComodification(expectedSrcModCount)
Looks like ArrayList::toArray is not doing this check either. So perhaps it is not needed. I would have thought mod check would have been needed in toArray to mimic iterator behavior. Therefore needed in addAll.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28116#discussion_r2492622937
More information about the core-libs-dev
mailing list