From 17535c34bc7853f8e73dfdec2c4da49d78b37bea Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Thu, 12 Oct 2023 22:39:03 +0000 Subject: [PATCH] 8317818: Combinatorial explosion during 'this' escape analysis Reviewed-by: vromero --- .../tools/javac/comp/ThisEscapeAnalyzer.java | 4 +-- .../tools/javac/warnings/ThisEscape.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index 2dd054619e0..0dd32fd8eca 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -167,7 +167,7 @@ class ThisEscapeAnalyzer extends TreeScanner { /** Used to terminate recursion in {@link #invokeInvokable invokeInvokable()}. */ - private final Set>> invocations = new HashSet<>(); + private final Set>> 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> invocation = Pair.of(site, refs.clone()); + Pair> invocation = Pair.of(methodInfo.declaration, refs.clone()); if (!invocations.add(invocation)) return; diff --git a/test/langtools/tools/javac/warnings/ThisEscape.java b/test/langtools/tools/javac/warnings/ThisEscape.java index d6ae9f8e8f4..25402c2c547 100644 --- a/test/langtools/tools/javac/warnings/ThisEscape.java +++ b/test/langtools/tools/javac/warnings/ThisEscape.java @@ -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; + } + } }