Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Jun 7, 2024

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8333766: Stack overflow with anonymous class in super() parameter (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19604/head:pull/19604
$ git checkout pull/19604

Update a local copy of the PR:
$ git checkout pull/19604
$ git pull https://git.openjdk.org/jdk.git pull/19604/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 19604

View PR using the GUI difftool:
$ git pr show -t 19604

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19604.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 2024

👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 7, 2024

@mcimadamore This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

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

Reviewed-by: jlahoda

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 123 new commits pushed to the master branch:

  • 0d3a377: 8333887: ubsan: unsafe.cpp:247:13: runtime error: store to null pointer of type 'volatile int'
  • 9d8439c: 8211854: [aix] java/net/ServerSocket/AcceptInheritHandle.java fails: read times out
  • f521367: 8211847: [aix] java/lang/ProcessHandle/InfoTest.java fails: "reported cputime less than expected"
  • f8c657f: 8334123: log the opening of Type 1 fonts
  • 57b6481: 8333277: ubsan: mlib_ImageScanPoly.c:292:43: runtime error: division by zero
  • 5528ad7: 8334179: VMATreeTest.TestConsistencyWithSimpleTracker_vm runs 50+ seconds
  • 5d2a19d: 8333684: C2 SuperWord: multiple smaller refactorings in preparation for JDK-8332163
  • 301bd70: 8311110: multichar warning in WinAccessBridge.cpp
  • 238162a: 8322064: Remove expired flags in JDK 24
  • fcedde8: 8330846: Add stacks of mounted virtual threads to the HotSpot thread dump
  • ... and 113 more: https://git.openjdk.org/jdk/compare/3cbdf8d4d4604c92d3760ba4e069216564306bcf...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

if (currentClass != null && typesUnderConstruction.contains(currentClass)) {
// reference must be to enclosing outer instance, mutate capture kind.
Assert.check(sym != currentClass); // should have been caught right in Attr
if (currentClass != null && currentClass != sym && !outerThisReachable(currentClass.type, sym)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a subtle change here - note that now if currentClass == sym we just skip this part (in this case just using this is enough).

@openjdk
Copy link

openjdk bot commented Jun 7, 2024

@mcimadamore The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Jun 7, 2024
} else if (current.tsym.isSubClass(target, types)) {
return true;
} else {
return current.tsym.hasOuterInstance() &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that hasOuterInstance takes into account the NOOUTERTHIS flag, that is, whether the inner class can have an enclosing instance at all.

@@ -2130,6 +2131,17 @@ void addSymbol(Symbol sym, LambdaSymbolKind skind) {
}
}

private boolean outerThisReachable(Type current, Symbol target) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is: if we can reach the target symbol from the current one w/o traversing any type under construction, or any type for which NOOUTERTHIS is set, then we can consider the target T.this reachable.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 7, 2024
@mlbridge
Copy link

mlbridge bot commented Jun 7, 2024

Webrevs

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 13, 2024
@mcimadamore
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants