-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
None
-
Affects Version/s: 17, 25, 26
-
Component/s: core-libs
-
generic
-
generic
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.
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.
- relates to
-
JDK-8368292 Severe performance penalty in bulk Collections methods (putAll, addAll, .<init>(Collection))
-
- Open
-
- links to
-
Review(master)
openjdk/jdk/28116