-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
👋 Welcome back dlsmith! A progress list of the required criteria for merging this PR into |
|
@dansmithcode The following label will be automatically applied to this pull request:
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. |
Webrevs
|
// generating bridges in the target class) | ||
useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) && | ||
!VerifyAccess.isSamePackage(implClass, implInfo.getDeclaringClass())) || | ||
implKind == H_INVOKESPECIAL; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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()) && |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
@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:
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
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 |
There was a problem hiding this 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.
/integrate |
@dansmithcode Since your change was applied there have been 53 commits pushed to the
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. |
Small bug fix.
Progress
Issue
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