meth, quid: update patch repo consistently with yesterday's push to JDK7 of 6829189
1 6829189: Java programming with JSR 292 needs language support
2 6754038: writing libraries in Java for non-Java languages requires method handle invocation
3 Summary: javac recognizes implicit methods assigned by JVM to MethodHandle and InvokeDynamic
5 javac needs to support library development for non-Java langauges
7 Language changes are documented in http://wikis.sun.com/display/mlvm/ProjectCoinProposal
9 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6754038
12 - the method java.dyn.MethodHandle.<T>invoke(AAA)T exists, even if not explicitly found
13 - the static method java.dyn.InvokeDynamic.<T>zzz(AAA)T always exists, even if not explicitly found
14 - the return type parameter <T> may be a primitive type or void
15 - the return type parameter <T> may be omitted and defaults to Object
16 - the signature of the implicit method is obtained by erasing actual argument types
17 - null arguments are treated as of type java.lang.Void (which can only be a null reference)
18 - no implicit conversions are performed on these calls; use a cast if you want conversion
21 See, for example, April-May 2009 discussions like the following:
22 http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001617.html
23 http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001418.html
25 Examples from the unit test:
26 void test(MethodHandle mh) {
27 mh.invoke("world", 123);
28 // previous line generates invokevirtual MethodHandle.invoke(String,int)Object
29 InvokeDynamic.greet("hello", "world", 123);
30 // previous line generates invokedynamic greet(Object,String,int)Object
33 Note that actual argument types can be overridden by casts, as in:
34 mh.invoke((Object)"foo", (Integer)123)
35 // previous line generates invokevirtual MethodHandle.invoke(Object,Integer)Object
37 The return type defaults to Object, unless specified by a type argument.
39 The syntax for return type specification is:
40 mh.<R>invoke(aaa) // generates signature (AAA)R
41 mh.<String>invoke("foo", 123) // signature is (String,int)String
42 mh.<void>invoke("foo", 123) // signature is (String,int)void
44 The syntax for the receiverless formulation of invokedynamic is:
45 InvokeDynamic.<R>zzz(obj,aaa) // generates signature (Object,AAA)R
46 InvokeDynamic.zzz(AAA) // return type is Object by default
47 InvokeDynamic.greet((Object)"hello", "world", 123)
48 // previous line generates invokedynamic greet(Object,String,int)Object
49 InvokeDynamic.<void>greet("hello", "world", 123)
50 // previous line generates invokedynamic greet(Object,String,int)void
51 // or (in a later JVM version) invokedynamic greet(String,String,int)void
54 - The syntax for invokedynamic is receiverless; the signature describes all stacked args.
55 - The instruction uses a new code point (186) and takes a NameAndType reference, plus two zero bytes.
56 - The flag -XDinvokedynamic also enables the new instruction, without otherwise changing the target.
62 - unit tests test/tools/javac/meth/*
66 ---- Using the Command Line ----
68 This does not require a full JDK build.
75 $ ./dist/bin/javac -d dist/cp1 -target 7 test/tools/javac/meth/Invoke{Dyn,MH}.java
76 $ ./dist/bin/javap -c -classpath dist/cp1 meth.Invoke{Dyn,MH} # observe call sites
78 (Note: Your $PATH may need to include a $JAVA_HOME for Java 6.)
80 ---- Using NetBeans ----
82 (Assuming a link farm folder at ~/env/.)
83 $ ln -s <some copy of jtreg> ~/env/JTREG_HOME
84 $ ln -s <some java6 JRE> ~/env/JAVA6_HOME
85 $ ln -s <some java6 JRE> ~/env/TARGET_JAVA_HOME
86 $ ln -s <langtools dir> ~/env/LANGTOOLS
88 Also, make sure your NetBeans is running Java 6 not Java 5.
89 $ mkdir ~/.HOME/.netbeans/6.5/etc
90 $ echo >> ~/.HOME/.netbeans/6.5/etc/netbeans.conf \
91 "netbeans_jdkhome = $HOME/env/JAVA6_HOME
93 Configure the OpenJDK build file properties:
94 $ echo >> ~/.openjdk/build.properties boot.java.home = ~/env/JAVA_HOME
95 $ echo >> ~/.openjdk/build.properties target.java.home = /Users/jrose/env/TARGET_JAVA_HOME
96 $ echo >> ~/.openjdk/build.properties jtreg.home = /Users/jrose/env/JTREG_HOME
97 $ mkdir ~/env/LANGTOOLS/dist/cp0
99 Right-click on the "langtools" project in NetBeans Project window, get 'select-tool'.
100 Actually, the resulting config file changes like this:
101 $ echo >> ~/env/LANGTOOLS/make/netbeans/langtools/nbproject/private/langtools.properties \
102 javac.args = -d ~/env/LANGTOOLS/dist/cp0 -XDinvokedynamic ~/env/LANGTOOLS/test/tools/javac/meth/InvokeDyn.java