my tiny "Hello, dynamic world!"
Raffaello Giulietti
raffaello.giulietti at gmail.com
Wed Jul 15 07:59:48 PDT 2009
Hello newbies pals,
I'm not sure this is the right place for this kind of posts, but here's
the tiny program I mentioned in my previous post.
Some notes:
* The method that will be eventually invoked via the call site target
handle has a *rich* name (#"a funny name").
* Since there is only one InvokeDynamic, bootstrapDynamic() is rather
simplistic and doesn't analyze its arguments.
* I'm using the b63 binary snapshot on Vista: I compiled with
-XDinvokedynamic and ran with -XX:+EnableInvokeDynamic.
* The current java.dyn API is sometimes quite different from what is
discussed in blogs and in the JSR 292 EDR. Of course, this reflects an
ongoing activity, so it's rather normal.
Hope this helps
Raffaello
----
package indy;
import java.dyn.CallSite;
import java.dyn.InvokeDynamic;
import java.dyn.Linkage;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
public class Main {
public static void main(String[] args) {
System.out.println(InvokeDynamic.<String>notExistentMethod());
}
private static String #"a funny name"() {
return "Hello, dynamic world!";
}
static {
Linkage.registerBootstrapMethod("bootstrapDynamic");
}
private static CallSite bootstrapDynamic(Class cl, String s,
MethodType type) {
CallSite site = new CallSite(cl, s, type);
site.setTarget(MethodHandles.lookup().findStatic(Main.class, "a
funny name", type));
return site;
}
}
More information about the mlvm-dev
mailing list