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

Allocation path: initializing stores are not coalesced with pre-zeroing if NPEs are possible

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • 9, 10
    • hotspot

    Description

      This issue affects most copying constructors, notably String(String val).

      E.g. if you run this benchmark with current HotSpot, then "copy()" would be slower, because it will
      first pre-zero all the fields in MyClass, then check the incoming argument for nullity, and then overwrite
      the fields with incoming argument fields. When incoming argument is not null, we are doing excess
      writes.

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public MyClass instant() {
              return new MyClass(x1, x2, x3, x4);
          }

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public MyClass copy() {
              return new MyClass(inst);
          }

          private static class MyClass {
              private long x1, x2, x3, x4;

              public MyClass(long x1, long x2, long x3, long x4) {
                  this.x1 = x1;
                  this.x2 = x2;
                  this.x3 = x3;
                  this.x4 = x4;
              }

              public MyClass(MyClass other) {
                  this.x1 = other.x1;
                  this.x2 = other.x2;
                  this.x3 = other.x3;
                  this.x4 = other.x4;
              }
          }

      Full test, performance results, and disassembly interpretation is here:
       http://cr.openjdk.java.net/~shade/8074566/InitStoreCoalesce.java

      Runnable benchmarks JAR is here:
       http://cr.openjdk.java.net/~shade/8074566/benchmarks.jar

      Attachments

        Activity

          People

            Unassigned Unassigned
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: