-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
-
jdk-22+17-78-gf7deaf4bef2
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8318554 | 21.0.2 | Archie Cobbs | P4 | Resolved | Fixed | b05 |
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.
```
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.
- backported by
-
JDK-8318554 Combinatorial explosion during 'this' escape analysis
- Resolved
- relates to
-
JDK-8015831 Add lint check for calling overridable methods from a constructor
- Resolved
- links to
-
Commit openjdk/jdk21u/b59b560a
-
Commit openjdk/jdk/17535c34
-
Review openjdk/jdk21u/266
-
Review openjdk/jdk/16125
(1 links to)