JDK-8276455 : C2: iterative EA
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-11-02
  • Updated: 2022-02-14
  • Resolved: 2021-12-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 b02Fixed
Related Reports
Duplicate :  
Relates :  
Description
There is issue with nested initialization when Escape Analysis can not scalarize allocations: `new A(new B( new C)))`

public class TestIterativeEA {

  static class B {
    int i;

    public B(int i) {
      this.i = i;
    }
  }

  static class A {
    B b;

    public A(B b) {
      this.b = b;
    }
  }

  static class C {
    A a;

    public C(A a) {
      this.a = a;
    }
  }

  static int test0(int i) {
    C c = new C(new A(new B(i)));
    return c.a.b.i;
  }

  public static void main(String[] args) {
    for (int i = 0; i < 12000; ++i) {
      int j = test0(i);
    }
  }
}

JavaObject NoEscape(NoEscape) [ 347F [ 38 43 ]]   26  Allocate  ===  5  6  7  8  1 ( 24  22  23  1  10  1 ) [[ 27  28  29  36  37  38 ]]  rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top ) TestIterativeEA::test0 @ bci:0 (line 28)  Type:{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address, 5:rawptr:NotNull} !jvms: TestIterativeEA::test0 @ bci:0 (line 28)

JavaObject ArgEscape(ArgEscape) [ 191F 525F [ 60 65 401 347 365 509 366 510 524 ]]   48  Allocate  ===  40  37  25  8  1 ( 24  46  23  1  10  1  43  43 ) [[ 49  50  51  58  59  60 ]]  rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top ) TestIterativeEA::test0 @ bci:4 (line 28)  Type:{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address, 5:rawptr:NotNull} !jvms: TestIterativeEA::test0 @ bci:4 (line 28)

JavaObject GlobalEscape(GlobalEscape) [ 144F 541F [ 90 95 192 191 525 526 527 540 ]]   78  Allocate  ===  62  59  47  8  1 ( 24  76  23  1  10  1  43  43  65  65 ) [[ 79  80  81  88  89  90 ]]  rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top ) TestIterativeEA::test0 @ bci:8 (line 28)  Type:{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address, 5:rawptr:NotNull} !jvms: TestIterativeEA::test0 @ bci:8 (line 28)

Comments
Changeset: a1dfe572 Author: Vladimir Kozlov <kvn@openjdk.org> Date: 2021-12-14 19:24:13 +0000 URL: https://git.openjdk.java.net/jdk/commit/a1dfe57249db15c0c05d33a0014ac914a7093089
14-12-2021

JMH data for PointerBenchmarkFlat: Benchmark Mode Cnt Score Error Units PointerBenchmarkFlat.test avgt 30 23.232 ± 6.507 ms/op PointerBenchmarkFlat.testFlat avgt 30 0.298 ± 0.001 ms/op Iterative EA: Benchmark Mode Cnt Score Error Units PointerBenchmarkFlat.test avgt 30 0.299 ± 0.001 ms/op PointerBenchmarkFlat.testFlat avgt 30 0.297 ± 0.001 ms/op
13-12-2021

Thank you, Tobias. I will look.
13-12-2021

Here is another example of an EA limitation that will be fixed by Iterative EA (I verified that with [~kvn]'s recent build): JDK-8278429 I would suggest to convert my simplified test (Test.java) to an IR verification test and also add the microbenchmark provided by [~mcimadamore].
13-12-2021

Eric C. suggested and I added JMH microbenchmark with case from Description and two other cases I found in `compiler/escapeAnalysis` tests. Before: Benchmark Mode Cnt Score Error Units IterativeEA.test1 avgt 5 11.489 ± 3.037 ns/op IterativeEA.test2 avgt 5 16.103 ± 3.686 ns/op IterativeEA.test3 avgt 5 1988.827 ± 217.831 ns/op With these changes: Benchmark Mode Cnt Score Error Units IterativeEA.test1 avgt 5 2.182 ± 0.022 ns/op IterativeEA.test2 avgt 5 2.375 ± 0.001 ns/op IterativeEA.test3 avgt 5 821.011 ± 8.268 ns/op
10-12-2021

Draft PR: https://github.com/openjdk/jdk/pull/6222
03-11-2021

Vladimir Ivanov tried to fix it but at the end suggested to invoke EA several times to solve the issue by eliminated allocations one by one.
02-11-2021