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

C2: Subsequent arraycopy does not always eliminate array zeroing

    XMLWordPrintable

    Details

      Description

      There are many cases where C2 eliminates the array pre-zeroing followed by arraycopy into the array. However, there are cases where this surprisingly does not work.

      For example, see this benchmark:
       http://cr.openjdk.java.net/~shade/8146828/ArrayZeroingBench.java
       http://cr.openjdk.java.net/~shade/8146828/benchmarks.jar

      The most puzzling example is this:

          @Benchmark
          public Foo[] arraycopy_srcLength() {
              Object[] src = this.src;
              Foo[] dst = new Foo[size];
              System.arraycopy(src, 0, dst, 0, src.length);
              return dst;
          }

          @Benchmark
          public Foo[] arraycopy_dstLength() {
              Object[] src = this.src;
              Foo[] dst = new Foo[size];
              System.arraycopy(src, 0, dst, 0, dst.length);
              return dst;
          }

      In srcLength case we successfully eliminate the pre-zeroing on destination array, while in dstLength we don't!

      See "rep stos" in dstLength case, and no zeroing in srcLength case:
       http://cr.openjdk.java.net/~shade/8146828/jdk9b99.perfasm
       http://cr.openjdk.java.net/~shade/8146828/jdk9b99-size10.perfasm

        Attachments

          Activity

            People

            • Assignee:
              roland Roland Westrelin
              Reporter:
              shade Aleksey Shipilev
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: