Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8305148

Add constructs for shared empty arrays

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      There are over one hundred occasions in the JDK where empty arrays are created and dozens of static duplicate declarations of empty arrays.

      Some of these could be replaced by shared empty arrays. An empty array is immutable and safe to share across threads.

      Replacement should not be mechanically applied on all occasions with empty arrays as JIT, inlining, escape analysis etc. might favor a local copy.

      The construct could, optionally, be made available via the `java.util.Arrays` class.

      Experimenting with a prototype reveals the class file could actually get marginally *bigger* with shared empty arrays (in this case only one shared array was replaces which is the worst case scenario).

      Baseline:
      % ll DataInputStream.class
      -rw-r--r-- 1 pminborg staff 5521 Mar 28 16:13 DataInputStream.class

      Patch:
      % ll DataInputStream.class
      -rw-r--r-- 1 pminborg staff 5535 Mar 28 17:10 DataInputStream.class

            pminborg Per-Ake Minborg
            pminborg Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: