JDK-8317818 : Combinatorial explosion during 'this' escape analysis
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 21,22
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2023-10-10
  • Updated: 2023-10-19
  • Resolved: 2023-10-12
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 21 JDK 22
21.0.2Fixed 22 b20Fixed
Related Reports
Relates :  
Description
The 'this' escape analyzer takes forever analyzing this class:

```
public class Test {
    private Object obj;
    public Test() {
        getObject();
    }   
    private Object getObject() {
        if (this.obj == null) {
            this.obj = new Object();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
            getObject().hashCode();
        }
        return this.obj;
    }
}   
```
The problem is that the recursion detector keys on the method call site, not the target method itself, so if there are multiple recursive call sites inside the target method then you end up recursing through all possible combinations of call sites before stopping the recursion.

The fix is simple - key on the method itself, not the call site.
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/266 Date: 2023-10-17 13:41:53 +0000
17-10-2023

Sure thing. I just marked these issues for our own tracking, so that we are sure these fixes get backported eventually :) Thanks for doing the backports!
16-10-2023

FYI, I am waiting for https://github.com/openjdk/jdk21u/pull/252 to be committed before submitting this as another backport. The reason is that these two fixes conflict with each other, so they need to be applied one at a time.
16-10-2023

> This is caused by JDK-8015831, right? I linked that one up. Yes - thanks.
16-10-2023

This is caused by JDK-8015831, right? I linked that one up.
16-10-2023

Fix Request Backport rationale: This issue should be backported to 21 because the bug is severe and the backport risk is minimal. Patch applies cleanly
13-10-2023

Changeset: 17535c34 Author: Archie Cobbs <acobbs@openjdk.org> Committer: Vicente Romero <vromero@openjdk.org> Date: 2023-10-12 22:39:03 +0000 URL: https://git.openjdk.org/jdk/commit/17535c34bc7853f8e73dfdec2c4da49d78b37bea
12-10-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16125 Date: 2023-10-10 16:55:22 +0000
10-10-2023