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

OptimizeStringConcat fails on pre-sized StringBuilder shapes

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b105
    • Verification:
      Verified

      Description

      A sample benchmark:

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public String explicitSized() throws Exception {
              String time = String.valueOf(System.nanoTime());
              String thread = Thread.currentThread().getName();
              String m = method;
              return new StringBuilder(63 + time.length() + thread.length() + m.length())
                      .append("[")
                      .append(time)
                      .append("] ")
                      .append(thread)
                      .append(":")
                      .append("Calling an application method \"")
                      .append(m)
                      .append("\" without fear and prejudice.")
                      .toString();
          }

      This benchmark regresses severely with Compact Strings. Turning OptimizeStringConcat off does not degrade performance further, which means it is broken with Compact Strings to begin with. The disassembly confirms it. Also see the (broken) workaround patch below:

      # JDK 9 Baseline
      LogLineBench.explicitSized: 83.267 ± 3.021 ns/op
      LogLineBench.explicitSized:·gc.alloc.rate.norm: 384.000 ± 0.001 B/op

      # JDK 9 Baseline, -XX:-OptimizeStringConcat
      LogLineBench.explicitSized: 190.090 ± 5.893 ns/op
      LogLineBench.explicitSized:·gc.alloc.rate.norm: 1296.000 ± 0.001 B/op

      # JDK 9 Compact Strings
      LogLineBench.explicitSized: 148.536 ± 5.032 ns/op
      LogLineBench.explicitSized:·gc.alloc.rate.norm: 704.000 ± 0.001 B/op

      # JDK 9 Compact Strings, -XX:-OptimizeStringConcat
      LogLineBench.explicitSized: 143.668 ± 7.654 ns/op
      LogLineBench.explicitSized:·gc.alloc.rate.norm: 704.000 ± 0.001 B/op

        Attachments

        1. graph.png
          10 kB
          Tobias Hartmann
        2. TestPresizedStringBuilder.java
          2 kB
          Tobias Hartmann

          Issue Links

            Activity

              People

              • Assignee:
                thartmann Tobias Hartmann
                Reporter:
                shade Aleksey Shipilev
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: