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

(coll) Arrays.sort(Object[]) should eschew clone() in favor of new Object[]+System.arraycopy()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 7
    • 5.0, 6
    • core-libs

      Josh Bloch writes:

      Wolfgang,

         Hi. The reason is that I thought that cloning the array was faster
      when I wrote the code. I was wrong. Unless I'm missing something,
      this should be fixed. I'm copying Martin Buchholz at Sun in the hopes
      that he'll fix it or pass it on to someone else at Sun to fix. I'm
      copying Neal and Doug because I think they'll be interested.

             Regards,

             Josh


      On Mon, 15 Nov 2004 18:11:17 -0800, Wolfgang Hoschek <###@###.###> wrote:

      >> Josh,
      >> just a quick question since you're probably busy.
      >>
      >> In java.util.Arrays.sort(Object[]) and range based cousin, to set up
      >> the temporary buffer array, why not simply use "new Object[size]" and
      >> then System.arraycopy instead of clone() or reflection in
      >> cloneSubArray()? My understanding is that System.arraycopy is faster
      >> than clone().
      >>
      >> When frequently sorting small arrays on jdk 1.5.0 server, VM clone()
      >> shows up with 14% when profiling with the non-perturbing flags '-server
      >> -agentlib:hprof=cpu=samples,depth=10'
      >>
      >> This is with our binary xml codec:
      >> http://dsd.lbl.gov/nux/api/nux/xom/binary/BinaryXMLCodec.html
      >>
      >> TRACE 300256:
      >> java.lang.Object.clone(Object.java:Unknown line)
      >> java.util.Arrays.sort(Arrays.java:1219)
      >> nux.xom.binary.BinaryXMLCodec.packSort(BinaryXMLCodec.java:560)
      >> nux.xom.binary.BinaryXMLCodec.serialize(BinaryXMLCodec.java:469)
      >> nux.xom.tests.BinaryXMLTest.main(BinaryXMLTest.java:115)
      >>
      >> Thanks,
      >> Wolfgang.

      ###@###.### 2004-11-16 04:44:31 GMT

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: