Skip to content

8268192: LambdaMetafactory with invokespecial causes VerificationError #4403

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 18 commits into from

Conversation

dansmithcode
Copy link

@dansmithcode dansmithcode commented Jun 7, 2021

Small bug fix.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8268192: LambdaMetafactory with invokespecial causes VerificationError

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4403/head:pull/4403
$ git checkout pull/4403

Update a local copy of the PR:
$ git checkout pull/4403
$ git pull https://git.openjdk.java.net/jdk pull/4403/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4403

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4403.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 2021

👋 Welcome back dlsmith! 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 8, 2021

⚠️ @dansmithcode This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 8, 2021
@openjdk
Copy link

openjdk bot commented Jun 8, 2021

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Jun 8, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 8, 2021

Webrevs

// generating bridges in the target class)
useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) &&
!VerifyAccess.isSamePackage(implClass, implInfo.getDeclaringClass())) ||
implKind == H_INVOKESPECIAL;
Copy link
Member

Choose a reason for hiding this comment

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

Won't this make regular private instance method calls use condy as well, as they are invokespecial?

Copy link
Author

Choose a reason for hiding this comment

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

See this code from the AbstractValidatingLambdaMetafactory constructor:

            case REF_invokeSpecial:
                // JDK-8172817: should use referenced class here, but we don't know what it was
                this.implClass = implInfo.getDeclaringClass();
                this.implIsInstanceMethod = true;

                // Classes compiled prior to dynamic nestmate support invokes a private instance
                // method with REF_invokeSpecial.
                //
                // invokespecial should only be used to invoke private nestmate constructors.
                // The lambda proxy class will be defined as a nestmate of targetClass.
                // If the method to be invoked is an instance method of targetClass, then
                // convert to use invokevirtual or invokeinterface.
                if (targetClass == implClass && !implInfo.getName().equals("<init>")) {
                    this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
                } else {
                    this.implKind = REF_invokeSpecial;
                }
                break;

We turn all same-class invocations into invokevirtual. (And all <init> invocations have kind newInvokeSpecial, mentioning them here is actually useless.)

Copy link
Author

Choose a reason for hiding this comment

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

Actually, I think I'll fix up this code and the comment...

// to pass the live implementation method handle to the proxy class
// to invoke directly. (javac prefers to avoid this situation by
// generating bridges in the target class)
useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) &&
Copy link
Author

Choose a reason for hiding this comment

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

Switched from !Modifier.isPublic to Modifier.isProtected. Access errors from the caller Lookup should already be caught by validation when the implementation is cracked. Protected and super calls are the only cases where the access from the nestmate is not equivalent.

// generating bridges in the target class)
useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) &&
!VerifyAccess.isSamePackage(implClass, implInfo.getDeclaringClass())) ||
implKind == H_INVOKESPECIAL;
Copy link
Author

Choose a reason for hiding this comment

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

See this code from the AbstractValidatingLambdaMetafactory constructor:

            case REF_invokeSpecial:
                // JDK-8172817: should use referenced class here, but we don't know what it was
                this.implClass = implInfo.getDeclaringClass();
                this.implIsInstanceMethod = true;

                // Classes compiled prior to dynamic nestmate support invokes a private instance
                // method with REF_invokeSpecial.
                //
                // invokespecial should only be used to invoke private nestmate constructors.
                // The lambda proxy class will be defined as a nestmate of targetClass.
                // If the method to be invoked is an instance method of targetClass, then
                // convert to use invokevirtual or invokeinterface.
                if (targetClass == implClass && !implInfo.getName().equals("<init>")) {
                    this.implKind = implClass.isInterface() ? REF_invokeInterface : REF_invokeVirtual;
                } else {
                    this.implKind = REF_invokeSpecial;
                }
                break;

We turn all same-class invocations into invokevirtual. (And all <init> invocations have kind newInvokeSpecial, mentioning them here is actually useless.)

// generating bridges in the target class)
useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) &&
!VerifyAccess.isSamePackage(implClass, implInfo.getDeclaringClass())) ||
implKind == H_INVOKESPECIAL;
Copy link
Author

Choose a reason for hiding this comment

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

Actually, I think I'll fix up this code and the comment...

// Classes compiled prior to dynamic nestmate support invoke a private instance
// method with REF_invokeSpecial. Newer classes use REF_invokeVirtual or
// REF_invokeInterface, and we can use that instruction in the lambda class.
if (targetClass == implClass) {
Copy link
Author

Choose a reason for hiding this comment

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

The name <init> can't appear here. It's only used by newInvokeSpecial.

@openjdk
Copy link

openjdk bot commented Jun 9, 2021

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

8268192: LambdaMetafactory with invokespecial causes VerificationError

Reviewed-by: psandoz, mchung

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

  • b41f3f8: 8268478: JVMCI tests failing after JDK-8268052
  • 7ff6e7b: 8267954: Shared classes that failed to load should not be loaded again
  • 991ca14: 8267430: GraphicsDevice.setDisplayMode(REFRESH_RATE_UNKNOWN) throws IAE: Unable to set display mode!
  • bf29a01: 8228343: JCMD and attach fail to work across Linux Container boundary
  • 408e0a9: 8255148: Confusing log output: SSLSocket duplex close failed
  • bbd0313: 8263203: jconsole Online User Guide has wrong URL
  • 33d34c6: 8263323: Debug Agent help output includes invalid URL
  • 79010f2: 8266835: Add a --validate option to the jar tool
  • db45ff0: 8268052: [JVMCI] non-default installed code must be marked as in_use
  • bb3d226: 8238213: Method resolution should stop on static error
  • ... and 43 more: https://git.openjdk.java.net/jdk/compare/fc08af58cb0571ed375a7937aac7a951ba224644...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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 9, 2021
Copy link
Member

@mlchung mlchung 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.

@dansmithcode
Copy link
Author

/integrate

@openjdk openjdk bot closed this Jun 9, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 9, 2021
@openjdk
Copy link

openjdk bot commented Jun 9, 2021

@dansmithcode Since your change was applied there have been 53 commits pushed to the master branch:

  • b41f3f8: 8268478: JVMCI tests failing after JDK-8268052
  • 7ff6e7b: 8267954: Shared classes that failed to load should not be loaded again
  • 991ca14: 8267430: GraphicsDevice.setDisplayMode(REFRESH_RATE_UNKNOWN) throws IAE: Unable to set display mode!
  • bf29a01: 8228343: JCMD and attach fail to work across Linux Container boundary
  • 408e0a9: 8255148: Confusing log output: SSLSocket duplex close failed
  • bbd0313: 8263203: jconsole Online User Guide has wrong URL
  • 33d34c6: 8263323: Debug Agent help output includes invalid URL
  • 79010f2: 8266835: Add a --validate option to the jar tool
  • db45ff0: 8268052: [JVMCI] non-default installed code must be marked as in_use
  • bb3d226: 8238213: Method resolution should stop on static error
  • ... and 43 more: https://git.openjdk.java.net/jdk/compare/fc08af58cb0571ed375a7937aac7a951ba224644...master

Your commit was automatically rebased without conflicts.

Pushed as commit 58ba48b.

💡 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
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants