hg: lambda/lambda/langtools: Handle non-static method references from static context. More specifically, if f is an instance method of Z whose signature is A, B->C, then #obj.f is of type A, B->C and #Z.f is of type Z, A, B->C.

John Rose john.r.rose at oracle.com
Fri Aug 20 23:03:36 PDT 2010


On Aug 4, 2010, at 8:22 AM, Brian Goetz wrote:

>> And the coolest thing is that #Employee.isPartTime is just a LDC.
> 
> Yep!  Tastes great AND less filling!
> 
>> Predicate<Employee>   p = #Employee.isPartTime;
>> 
>> will be compiled to
>> 
>> ldc #Employee.isPartTime
>> ldc Predicate.class
>> invokestatic MethodHandles.asSam
>> (Ljava/lang/MethodHandle;Ljava/lang/Class;)LObject;
>> checkcast LPredicate;
>> 
>> knowing that asSam() should always return an instance of the same class
>> for the same SAM.
> 
> Has the 292 EG made any progress in defining the semantics and nonfunctional 
> behavior (i.e., performance) of asSam()?  I am curious to hear.  Will 
> MethodHandles.asSam(methodHandle, clazz) allocate a fresh MH on each 
> invocation, or will they be cached somehow so that the above is 
> allocation-free (and subsequent invocation is indirection-free)?

I expect to cache at least some of those adapted MHs in the Hotspot implementation.  (The present rev. 0 draft implementation is a placeholder built on Proxy.)  A one-element cache per direct method handle should be sufficient.  Such things need to be invisible optimizations.  In order for this to be so, the Lambda spec. has to be very "shy" about specifying when new objects are created, along the lines of Integer.valueOf.

Of course, none of this needs to matter when a JIT gets the bytecode sequence above.  It can use the right constant directly in the machine code.

Expect the 292 performance to ramp up over time.  It is a deep addition to the JVM, which will get faster with careful, empirically driven optimization work.

-- John


More information about the lambda-dev mailing list