[Nestmates] Lambda proxy class should use invokeVirtual/invokeInterface when invoking a private nestmate instance method

Mandy Chung mandy.chung at oracle.com
Fri Nov 16 21:09:16 UTC 2018

Hi Remi,

This patch should resolve the CNFE issue you run into.   The nestmates 
branch changes lambda metafactory to use Lookup::defineClass to define 
the lambda proxy classes as a dynamic nestmate.    The lambda proxy 
class forwards to the call to the MethodHandle specified in the BSM for 
the lambda expression.  For a class that is compiled with javac prior to 
the dynamic nestmate change and the lambda is an instance method, the 
MethodHandle argument of the BSM entry is invokeSpecial a private 
instance method [1].  The nestmates branch javac is updated to generate 
invokeVirtual/invokeInterface MH to invoke a private nestmate instance 

Previously when defined as VM anonymous class, VM workarounds the 
verifier invokespecial subtyping requirement.  With Lookup::defineClass, 
it follows the normal verification rules as it should and hence it fails 
verification of the proxy class.  So we need it to work with existing 
compiled classes using lambdas.

The proposed fix is to generate invokeVirtual/invokeInterface if the 
impl method is a private nestmate instance method.


[1] BSM with invokeSpecial a private instance method

   0: #106 REF_invokeStatic 
     Method arguments:
       #107 ()Ljava/lang/Object;
       #108 REF_invokeSpecial 
       #109 ()Ljava/lang/String;

More information about the valhalla-dev mailing list