Skip to content
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

8328649: Disallow enclosing instances for local classes in constructor prologues #18416

Closed
wants to merge 3 commits into from

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Mar 21, 2024

A local class declared in a static context is not supposed to have an immediately enclosing instance (§15.9.2). That includes local classes declared in constructors prior to super() (during the "constructor prologue" in the new lingo).

However, the compiler is allowing code like this to successfully compile:

import java.util.concurrent.atomic.*;
public class Test extends AtomicReference<Object> {
  
    public Test() {
        super(switch (0) {
          default -> {
              class Local { { Test.this.hashCode(); } }   // this should fail
              yield null;
            }
        });
    }
}

This patch fixes the "leak".


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
  • Change requires CSR request JDK-8328706 to be approved

Issues

  • JDK-8328649: Disallow enclosing instances for local classes in constructor prologues (Bug - P4)
  • JDK-8328706: Disallow enclosing instances for local classes in constructor prologues (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18416

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 21, 2024

👋 Welcome back acobbs! 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 Mar 21, 2024

@archiecobbs 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:

8328649: Disallow enclosing instances for local classes in constructor prologues

Reviewed-by: vromero

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 36 new commits pushed to the master branch:

  • 4276d5c: 8329637: Apparent typo in java.security file property jdk.tls.keyLimits
  • 6382a12: 8326666: Remove the Java Management Extension (JMX) Subject Delegation feature
  • d90e5b5: 8329546: Assume sized integral types are available
  • f3db279: 8327410: Add hostname option for UL file names
  • 21867c9: 8313332: Simplify lazy jmethodID cache in InstanceKlass
  • b9da140: 8329594: G1: Consistent Titles to Thread Work Items.
  • a169c06: 8329580: Parallel: Remove VerifyObjectStartArray
  • 8efd7aa: 8328786: [AIX] move some important warnings/errors from trcVerbose to UL
  • f26e430: 8327110: Refactor create_bool_from_template_assertion_predicate() to separate class and fix identical cloning cases used for Loop Unswitching and Split If
  • e5e21a8: 8328702: C2: Crash during parsing because sub type check is not folded
  • ... and 26 more: https://git.openjdk.org/jdk/compare/6ae1cf12cee268ac7599eb9ade9c0861a89748f9...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Mar 21, 2024

@archiecobbs 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 Mar 21, 2024
@archiecobbs archiecobbs marked this pull request as ready for review March 21, 2024 02:12
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 21, 2024
@mlbridge
Copy link

mlbridge bot commented Mar 21, 2024

Webrevs

@liach
Copy link
Member

liach commented Mar 21, 2024

Thanks for this change! This unification of outer instance handling of inner and anonymous class declaration paves the way for Valhalla's value classes and makes things more straightforward.

According to #13656 (comment) this change will affect the class file generated, such as for your given example. Should this patch get a CSR then?

@archiecobbs
Copy link
Contributor Author

According to #13656 (comment) this change will affect the class file generated, such as for your given example. Should this patch get a CSR then?

Well, this change only affects generated classfiles in the sense that it will be no longer possible to generate certain classfiles because compilation will fail instead :)

But regardless I think a CSR is probably warranted so I'll add one. Thanks.

@archiecobbs
Copy link
Contributor Author

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 21, 2024
@openjdk
Copy link

openjdk bot commented Mar 21, 2024

@archiecobbs has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@archiecobbs please create a CSR request for issue JDK-8328649 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

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

looks good to me

@archiecobbs
Copy link
Contributor Author

@vicente-romero-oracle, would you (or anyone) mind reviewing the associated CSR per @jddarcy's request?

Thanks.

@vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle, would you (or anyone) mind reviewing the associated CSR per @jddarcy's request?

Thanks.

looks good

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Apr 4, 2024
@vicente-romero-oracle
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 4, 2024

@vicente-romero-oracle The change author (@archiecobbs) must issue an integrate command before the integration can be sponsored.

@archiecobbs
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 4, 2024
@openjdk
Copy link

openjdk bot commented Apr 4, 2024

@archiecobbs
Your change (at version c9d399d) is now ready to be sponsored by a Committer.

@archiecobbs
Copy link
Contributor Author

Hi @vicente-romero-oracle , thanks for reviewing & sponsoring. Please sponsor one more time as the bot got confused somehow. Thanks.

@vicente-romero-oracle
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 4, 2024

Going to push as commit d80d478.
Since your change was applied there have been 38 commits pushed to the master branch:

  • 83eba86: 8329332: Remove CompiledMethod and CodeBlobLayout classes
  • 28216aa: 8328366: Thread.setContextClassloader from thread in FJP commonPool task no longer works after JDK-8327501
  • 4276d5c: 8329637: Apparent typo in java.security file property jdk.tls.keyLimits
  • 6382a12: 8326666: Remove the Java Management Extension (JMX) Subject Delegation feature
  • d90e5b5: 8329546: Assume sized integral types are available
  • f3db279: 8327410: Add hostname option for UL file names
  • 21867c9: 8313332: Simplify lazy jmethodID cache in InstanceKlass
  • b9da140: 8329594: G1: Consistent Titles to Thread Work Items.
  • a169c06: 8329580: Parallel: Remove VerifyObjectStartArray
  • 8efd7aa: 8328786: [AIX] move some important warnings/errors from trcVerbose to UL
  • ... and 28 more: https://git.openjdk.org/jdk/compare/6ae1cf12cee268ac7599eb9ade9c0861a89748f9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 4, 2024
@openjdk openjdk bot closed this Apr 4, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 4, 2024
@openjdk
Copy link

openjdk bot commented Apr 4, 2024

@vicente-romero-oracle @archiecobbs Pushed as commit d80d478.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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

Successfully merging this pull request may close these issues.

3 participants