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

C2: Cast nodes hinder memory alias analysis

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9, 10
    • Fix Version/s: 13
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b09

      Description

      See http://www.scala-lang.org/blog/2016/07/08/trait-method-performance.html#back-to-default-methods for the motivating example. This bug follows up why non-CHA inlining produces suboptimal loop.

      While the same can be demonstrated with default methods that do not enjoy CHA inlining due to JDK-8036580, we can also show the same on virtual methods with -XX:-UseCHA. While we can argue that CHA *should* be faster because it uses static information for inlining, it is very weird to see the impact on loop optimizer.

      Running this test:

          interface I {
              int getV();
          }

          abstract class A implements I {
              public int accessVirtual() { return getV(); }
          }

          class C extends A {
              public int v = 0;
              public int getV() { return v; }
          }

          final int NB = 1000;

          public C c;

          @Setup
          public void setup() {
              c = new C();
          }

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public int test() {
              int value = 0;
              for (int i = 0; i < NB; i++) {
                  c.v = i;
                  value += c.accessVirtual();
              }
              return value;
          }

      (full test: http://cr.openjdk.java.net/~shade/8161334/CHAnoCHA.java, http://cr.openjdk.java.net/~shade/8161334/benchmarks.jar)

      ...will yield different performance with -XX:+UseCHA and -XX:-UseCHA. The performance difference seems to be explained with the suboptimal loop generation in non-CHA case, and at least here reaches 20%.

      Disassemblies:
       http://cr.openjdk.java.net/~shade/8161334/cha.perfasm
       http://cr.openjdk.java.net/~shade/8161334/no-cha.perfasm

      It seems to start with a subtly different IRs generated for CHA and non-CHA inlining:
       http://cr.openjdk.java.net/~shade/8161334/cha-after-parsing.png
       http://cr.openjdk.java.net/~shade/8161334/no-cha-after-parsing.png

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vlivanov Vladimir Ivanov
                Reporter:
                shade Aleksey Shipilev
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: