|
|
|||||||||||||||||||||||||||||||||||||||||||||
Rémi Forax's Blog
JSR292 backport - First releasePosted by forax on July 01, 2009 at 09:06 AM | Permalink | Comments (0)I've just released the first version 1.0.1 (1.0 is compiled for 1.6 only) of the JSR292 backport. So you can now test invokedynamic and method handle invocations without using the latest patch queue from mlvm repository and some wizard's black magic.
The primary usage of the backport is for dynamic language runtime
developers (JRuby, Jython, Groovy, etc),
they can now use JSR292 API to improve their perf without having to
maintain different codebases.
The backport (at least currently) is a Java agent which
modify (instrument) bytecodes at runtime to provide JSR 292 API
support on jdk11.5/1.6 VM.
Comparing to current state of JDK7, the backport run at the same
speed or faster than JDK7 depending on the benchmark used.
The twist is that currently the JDK7 doesn't provide
a full JIT support, that's why the backport is faster :)
Anyway, the JSR292 API provides you an infrastructure that is known to be good in order to be optimized by the VM. So If you are a language runtime developer, I think it worth a glimpse. How to get JSR292 backport ? The JSR292 backport is hosted by the JVM language runtime project on Google Code: http://code.google.com/p/jvm-language-runtime/. How to use it ?
You have an example in directory, examples.
[examples]$ /usr/jdk/jdk1.7.0/bin/javac -Xbootclasspath/p:../mock/jsr292-mock.jar -source 1.7 FidgetDemo.java [examples]$ java -javaagent:../lib/jsr292-backport.jar FidgetDemo Fidgety self-modifying call site... --- loop #0 [link] new call site: CallSite#970110[fidget(java.lang.String)java.lang.String => null] [link] set target to Guard:invoke(class java.lang.String itch[class java.lang.String]) fred can't get comfortable buster can't get comfortable ricky can't get comfortable --- loop #1 [link] set target to Guard:invoke(class java.lang.String fuss[class java.lang.String]) fred can't get comfortable buster is feeling moody ricky is feeling moody --- loop #2 fred is feeling moody [link] set target to Guard:invoke(class java.lang.String bore[class java.lang.String]) buster is feeling moody ricky needs a change of scenery --- loop #3 fred needs a change of scenery buster needs a change of scenery [link] set target to Guard:invoke(class java.lang.String itch[class java.lang.String]) ricky needs a change of scenery --- loop #4 fred can't get comfortable buster can't get comfortable ricky can't get comfortable --- loop #5 [link] set target to Guard:invoke(class java.lang.String fuss[class java.lang.String]) fred can't get comfortable buster is feeling moody ricky is feeling moody
If you want more examples, JSR292 Cookbook is your friend.
invokedynamically yours,
ASM now supports invokedynamicPosted by forax on June 11, 2009 at 10:42 PM | Permalink | Comments (2)
Great news, ASM 3.2 is released
(Extended changelog).
ASM supports of invokedynamic
From ASM point of view, invokedynamic is a
method call instruction emittable/trappable by
calling/overriding visitInsnMethod
of a MethodVisitor
like any other invoke* bytecode instructions.
Example This simple code transforms all invokevirtual to invokedynamic, registers a boostrap method and configure invokedynamic call site to perform an invokevirtual.
public class Invokedynamiker extends ClassAdapter {
boolean isStaticInitPatched;
public Invokedynamiker(ClassVisitor cv) {
super(cv);
}
@Override
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
return new MethodAdapter(mv) {
@Override
public void visitCode() {
super.visitCode();
if ("
The boostrap method creates a call site and links the call site target to a method handles performing an invokevirtual.
public static CallSite bootstrapMethod(Class<?> callerClass, String methodName, MethodType methodType) {
MethodType argumentType = methodType.dropParameterType(0);
MethodHandle mh = MethodHandles.lookup().findVirtual(methodType.parameterType(0), methodName, argumentType);
CallSite site = new CallSite(callerClass, methodName, methodType);
site.setTarget(mh);
return site;
}
The code of the bootstrap method can be changed to, by example,
log the arguments before calling the destination method using
method handle adapters :
convertArguments, spreadArguments, collectArguments
and a java.dyn.JavaMethodHandle.
The whole code is available as a zip :
indy-asm-sample.zip.
cheers,
JDK7 MilestonesPosted by forax on May 04, 2009 at 07:41 AM | Permalink | Comments (6)It seems that lot of people don't notice that there is a roadmap for jdk7. http://openjdk.java.net/projects/jdk7/milestones/. Rémi invokedynamic now lives in JDK7Posted by forax on April 25, 2009 at 07:11 AM | Permalink | Comments (7)invokedynamic (at least the main parts) now lives in JDK 7 ! You haven't perhaps notice it but John pushes the first patches from the Da Vinci Machine project to the hotspot workspace.
Method Handle support (meth):
Rémi For early adopters, on Linux you can build the source of the VM by cloning the hotspot workspace, on MacOs X (Intel CPU), Atilla Szegedi gently provides an already built binary. |
July 2009
Search this blog:CategoriesCommunity: JavaDesktopCommunity: JDK Swing Archives
July 2009 Recent EntriesJSR292 backport - First release ASM now supports invokedynamic | ||||||||||||||||||||||||||||||||||||||||||||
|
|