RFR: 8268192: LambdaMetafactory with invokespecial causes VerificationError [v2]

Dan Smith dlsmith at openjdk.java.net
Tue Jun 8 15:30:36 UTC 2021


On Tue, 8 Jun 2021 15:17:44 GMT, Dan Smith <dlsmith at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java line 191:
>> 
>>> 189:         useImplMethodHandle = (Modifier.isProtected(implInfo.getModifiers()) &&
>>> 190:                                !VerifyAccess.isSamePackage(implClass, implInfo.getDeclaringClass())) ||
>>> 191:                                implKind == H_INVOKESPECIAL;
>> 
>> Won't this make regular private instance method calls use condy as well, as they are invokespecial?
>
> 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.)

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

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

PR: https://git.openjdk.java.net/jdk/pull/4403


More information about the core-libs-dev mailing list