ArrayList.addAll() optimizations

XMLWordPrintable

    • 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.

            Assignee:
            John Engebretson
            Reporter:
            John Engebretson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: