8317818: Combinatorial explosion during 'this' escape analysis

Reviewed-by: vromero
This commit is contained in:
Archie Cobbs 2023-10-12 22:39:03 +00:00 committed by Vicente Romero
parent 61ce739ac8
commit 17535c34bc
2 changed files with 32 additions and 2 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/warnings

@ -167,7 +167,7 @@ class ThisEscapeAnalyzer extends TreeScanner {
/** Used to terminate recursion in {@link #invokeInvokable invokeInvokable()}.
*/
private final Set<Pair<JCTree, RefSet<Ref>>> invocations = new HashSet<>();
private final Set<Pair<JCMethodDecl, RefSet<Ref>>> invocations = new HashSet<>();
/** Snapshot of {@link #callStack} where a possible 'this' escape occurs.
* If non-null, a 'this' escape warning has been found in the current
@ -590,7 +590,7 @@ class ThisEscapeAnalyzer extends TreeScanner {
return;
// Stop infinite recursion here
Pair<JCTree, RefSet<Ref>> invocation = Pair.of(site, refs.clone());
Pair<JCMethodDecl, RefSet<Ref>> invocation = Pair.of(methodInfo.declaration, refs.clone());
if (!invocations.add(invocation))
return;

@ -617,4 +617,34 @@ public class ThisEscape {
;
}
}
// Verify no infinite recursion loop occurs (JDK-8317818)
public static class ThisEscapeRecursionExplosion {
private Object obj;
public ThisEscapeRecursionExplosion() {
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;
}
}
}