First draft of translation document

Rémi Forax forax at univ-mlv.fr
Tue May 18 16:40:00 PDT 2010


Le 17/05/2010 19:31, Brian Goetz a écrit :
> We've posted a document describing a (somewhat naive) translation strategy for
> translation of lambda expressions by javac here:
>
>     http://cr.openjdk.java.net/~mcimadamore/lambda_trans.pdf
>
>    

Summary:
- if there is no function types, lambda are handles by interfaces,
   in that case a lambda is created by a LDC (+ an optional bind) 
followed by a asSam()
   to avoid to create multiple inner classes

- if function types exist, a lambda is a method handle (created by a LDC +
   an optional bind) and asSam() is used when interoperate which legacy 
code.

A lambda can use
  - parameters,:
    in that case a LDC is sufficient
-  local variables:
    variables need to be bound to the method handle after a LDC
-  surrounding objects fields
    the surrounding objects need to be also bound.

Up to here I'm okay.
So for the JSR292 expert group, we have to correctly specifies
asSam() and provides a polymorphic bindTo/insertArguments.

Now the not agree part:
Local variables can also be accessed by reference (with "shared"),
in that case the compiler needs to construct a frame object to store the 
local variables,
bind the frame to the method handle and retrieve the value after the call.

I don't like it because:
  - there is no support offered by the VM for that, so each compiler 
(version of compilers)
    will choose a different ways to optimize or worst "perhaps optimize".
    Remember how the scheme to compile inner-classes changes over the 
time in javac.
  - it's not Java, as far as I know, there is no pass by reference in Java
  - the proposed scheme introduces a hidden allocation (perhaps !)
  - in term of design, we are trying to hide a mutable object, doesn't 
sound good.
  - the impact on the memory model is far from clear, one day shared 
vars will have to
    be specified in term of happen-before.
  - I don't want to explain why you can not use the keyword shared on a 
field,
    or why it doesn't work with anonymous/inner classes.


I know that it's cool to have a feature like shared, above all if C# 
already have this feature
but Java is not C# because the JVM is not a .Net VM.

Rémi


More information about the lambda-dev mailing list