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

EA: Inlining brings excess uses, and then breaks escape analysis

    Details

      Description

      (This is probably caused by an unusual graph shape, and not by issues in EA, change the synopsis for the root cause, once found)

      This is best demonstrated with this test:

          @Benchmark
          @CompilerControl(CompilerControl.Mode.INLINE)
          public long inner_inlined() {
              long sum = 0;
              for (Integer i : new InnerList<>(ints)) {
                  sum += i;
              }
              return sum;
          }

          @Benchmark
          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          public long inner_notInlined() {
              long sum = 0;
              for (Integer i : new InnerList<>(ints)) {
                  sum += i;
              }
              return sum;
          }

      The scalarization of InnerList and its associated iterator is the target for this test. Counter-intuitively, inlining the host @Benchmark method *breaks* EA, even though allocation is local to @Benchmark method! This only happens when an internal iterator in this custom list is referencing the parent list. If you make the iterator nested, then EA works again!

      Test and runnable JAR:
        http://cr.openjdk.java.net/~shade/8155769/EAInnerBench.java
        http://cr.openjdk.java.net/~shade/8155769/benchmarks.jar

      With this tracing patch:
        http://cr.openjdk.java.net/~shade/8155769/trace.patch

      ...the worst inner_inlined test fails to scalarize InnerList with this message:

      Oops, merging with other object at use:
       1004 AddP === _ 992 992 75 [[ 1006 ]] Oop:org/openjdk/EAInnerBench$InnerList$It:NotNull:exact+16 * [narrow] !jvms: EAInnerBench$InnerList$It::<init> @ bci:2 EAInnerBench$InnerList::iterator @ bci:5 EAInnerBench::inner_inlined @ bci:13 EAInnerBench_inner_inlined_jmhTest::inner_inlined_avgt_jmhStub @ bci:16

      Trying to allocate:
       793 Allocate === 1508 776 777 8 1 ( 75 74 47 1 1 728 45 70 694 778 1 25 1 694 70 25 1 1 1 ) [[ 794 795 796 803 804 805 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top ) EAInnerBench::inner_inlined @ bci:2 EAInnerBench_inner_inlined_jmhTest::inner_inlined_avgt_jmhStub @ bci:16 !jvms: EAInnerBench::inner_inlined @ bci:2 EAInnerBench_inner_inlined_jmhTest::inner_inlined_avgt_jmhStub @ bci:16

      Type...
       74 ConP === 0 [[ 77 793 ]] #precise klass org/openjdk/EAInnerBench$InnerList: 0x00007ff19c16a530:Constant:exact * Klass:precise klass org/openjdk/EAInnerBench$InnerList: 0x00007ff19c16a530:Constant:exact *

      Alternative edge:
       JavaObject NoEscape(NoEscape) NSR [ [ 168 403 404 405 418 1004 1077 1078 1079 1092 874 1093 1094 1095 1108 ]] 31 ConP === 0 [[ 32 40 58 65 150 1080 390 397 406 413 1096 1087 1103 716 1270 1262 578 587 723 859 682 689 ]] #NULL

      It seems there is a NULL constant coming from some new path.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            shade Aleksey Shipilev
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: