RFR: 8333766: Stack overflow with anonymous class in super() parameter

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Jun 21 14:25:16 UTC 2024


On Fri, 7 Jun 2024 18:00:50 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch fixes an issue in `LambdaToMethod` where the wrong code is generated to access a symbol in the enclosing scope.
> 
> `LambdaTranslationContext::addSymbol` has some logic to avoid referring to `T.this` when `T` is a type under construction. This fix works well when a lambda is directly enclosed in a `super` or `this` call, but does not scale to more complex cases, such as the one in this issue.
> 
> A more complete fix needs to check whether the target `T.this` is really available via a chain of enclosing `this$n` fields. If that's not the case, then `T.this` must be captured by the lambda more directly, as there's no *path* to it from the innermost enclosing this.
> 
> To detect that, I've added a method (`outerThisReachable`) which more or less mimic the lookup logic in `Lower::makeOwnerThisN`.

Closing this PR. This issue is related to other issues such as https://bugs.openjdk.org/browse/JDK-8334037, which can only be fixed reliably with a more invasive refactoring which moves Lower ahead of LambdaToMethod.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19604#issuecomment-2182854079


More information about the compiler-dev mailing list