JDK-8371164 : ArrayList.addAll() optimizations
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 17,25,26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2025-11-03
  • Updated: 2025-11-24
  • Resolved: 2025-11-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26 b25Fixed
Related Reports
Relates :  
Description
ArrayList.addAll() contains a semi-workaround for the megamorphic poisoning described on JDK-8368292 : it makes one virtual call to Collection.toArray().  Production profiling shows that further improvements are possible:
1. ArrayList.toArray() creates a defensive copy of the existing array, which is unnecessary inside the method.
2. Collections$SingletonSet falls back to AbstractCollection.toArray(), which is vulnerable to the exact megamorphic poisoning described in the other ticket.

Minor code changes will address #1 via a fast-path specific to ArrayList, and #2 via a type-specific override of toArray(), Collections$SingletonSet.toArray().

It is possible to enhance other instances of *.toArray(), but my available profiling data only supports these changes.
Comments
Changeset: aeea8497 Branch: master Author: John Engebretson <jengebr@amazon.com> Committer: Stuart Marks <smarks@openjdk.org> Date: 2025-11-18 23:37:06 +0000 URL: https://git.openjdk.org/jdk/commit/aeea8497562aabda12f292ad93c9f0f6935cc842
18-11-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/28116 Date: 2025-11-03 20:45:44 +0000
03-11-2025