Hi john, hi gang.

I tried to understand how to implement closure with method handles.
So correct me if i'm wrong:
- a method handle is a Java Object with a special header
  let say it's a 3 words header, the last word is a pointer to
  the signature of the method handle.
- in order to use covariance/contravariance, you need
  to use an adapt method that create a *new* method handle

Because adapt create a new handle, closures are not method handles.

Example using the BGGA syntax:
private static void f({String=>void} closure) {
  closure.invoke("hello");
}

public static void print(Object o) {
  System.out.println(o);
}

...
{Object=>void} h1=#print(Object);
f(h1); // here the method handle need to be adapted
          // so the local parameter closure is not == to h1

So closures are not method handles.


Ok, let now say a closure is an object that contains a  method handle  and
invoke is performed by using the new invokedynamic bytecode.

public class Closure {
  private final MethodHandle handle;

  private MethodHandle invokeDynamicFailure(MethodType signature) {
    checkIfSignatureCompatible(signature);
    return MethodHandles.adaptArguments(handle,signature);
  }
}

When invoke is called using the invoke dynamic bytecode,
the default behavior failed (if there is one), the VM called 
invokeDynamicFailure
with the method signature of the invoke dynamic call site.
This method returns the method handle that should be used as fallback.
The returned handle is stored in an inline cache to avoid to lookup each 
time.

ok, this seems to work, is is the general idea ?

Rémi








  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to