--- a/meth.txt Fri Sep 12 20:17:53 2008 -0700
+++ b/meth.txt Mon Sep 29 19:33:33 2008 -0700
@@ -1,9 +1,9 @@ 0000000: writing libraries in Java for n
-0000000: writing libraries in Java for non-Java languages requires method handle invocation
+6754038: writing libraries in Java for non-Java languages requires method handle invocation
Summary: javac recognizes implicit methods assigned by JVM to MethodHandle and Dynamic
javac needs to support library development for non-Java langauges
-http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6746458
+http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754038
Features:
- the method java.dyn.MethodHandle.invoke(AAA)Object exists, even if not explicitly found
@@ -16,9 +16,41 @@ Examples from the unit test:
Examples from the unit test:
void test(MethodHandle mh) {
mh.invoke("world", 123);
+ // previous line generates invokevirtual MethodHandle.invoke(String,int)Object
((Dynamic)"hello").greet("world", 123);
+ // previous line generates invokedynamic greet([Object,]String,int)Object
}
-
+
+Note that actual argument types can be overridden by casts, as in:
+ mh.invoke((Object)"foo", (Integer)123)
+ // previous line generates invokevirtual MethodHandle.invoke(Object,Integer)Object
+
+The return type defaults to Object, unless specified by a type argument.
+
+The syntax for return type specification is:
+ mh.<R>invoke(AAA) // generates signature (AAA)R
+ mh.<String>invoke("foo", 123) // signature is (String,int)String
+ mh.<void>invoke("foo", 123) // signature is (String,int)void
+
+The syntax for the receiverless formulation of invokedynamic is:
+ Dynamic.zzz(AAA) // return type is Object by default
+ Dynamic<R>.zzz(AAA)
+ Dynamic.greet((Object)"hello", "world", 123)
+ // previous line generates invokedynamic greet(Object,String,int)Object
+ Dynamic.<void>greet("hello", "world", 123)
+ // previous line generates invokedynamic greet(Object,String,int)void
+ // or (in a later JVM version) invokedynamic greet(String,String,int)void
+
+Notes & Status:
+- The return type arguments are not yet implemented.
+- The receiverless formulation is not yet implemented.
+- Either the receiverless or receiver-based syntax should be eliminated.
+ The future-proof choice is to keep only the receiverless syntax,
+ with a proviso that that the first argument is cast to Object in JDK7.
+ (The issue is the encoding of the invokedynamic instruction as invokeinterface,
+ which requires the first stacked argument to be a typeless reference.
+ The receiverless formulation would not require this, but would be
+ a breaking change to the verifier.)
Authors:
- John Rose (Sun)