Dynamic Dispatch in Java
I thought it would be useful to create a way to indicate that a method dispatch should be performed dynamically in Java so it’s easy to test my experimental invokedynamic implementation. To do this I have added little bit of extra syntax to the Eclipse JDT Core Java compiler as follows,
int a;
String b;
// Dynamically invoke someMethod on this, expecting it to have an int
// return type and taking arguments of a int & String
someMethod`<int>(a,b)
// Dynamically invoke someMethod on object aObject, expecting it to have a
//String return type and taking arguments of a int & String
aObject.someMethod`<String>(a,b);
The `<type> syntax is the indicator that you want to perform dynamic dispatch and are expecting a return type of type. The invokedynamic instruction also encodes the argument types but the compiler can infer these from the arguments actually supplied. The second form covers all Primary expressions, I have just given the most obvious example here.
I have not supplied any syntax for making super or static dispatches as the semantics of these are undefined at the moment. The syntax also does not support the generics dispatch syntax but this is just because I wanted to avoid dealing with that yet. I suspect I will try an address these three issue in the next version. You will also note that I did not make a distinction between primitive and object types as some of the earlier work has done. I thought this distinction was pretty arbitrary from a programmers perspective so have assumed that run-time auto-boxing will be employed on primitives if its needed.
This syntax is really just to aid experimentation and not a genuine suggestion for how invokedynamic may be exposed in Java (assuming it is at all).
I am hoping to be able to release the patch that implements this in the next few days.
invokedynamic
There has been some interesting comment on the proposed new JVM instruction, invokedynamic. I have been doing some work on an experimental implementation of invokedynamic which I will talk about later but here is a summary of some interesting posts elsewhere.
The Pnuts Addict (as do others) raise the concern that invokedynamic won’t have enough performance advantage. I am not so sure it’s its possible to make a general claim about this but his comment on the need for flexibility in how the dispatch target/methods are identified is very important.
A. Sundararajan has pointed out that there is likely a need for an invokespecialdyanmic. His argument appears pretty solid although it does not look like there would be a major difficulty in providing this type of feature.
And finaly but not least there is a great entry from Charles Oliver Nutter on how usefull invokedynamic might be in a JRuby context. This is something I think we need to explore more via some practical performance experiments.
Being Proud
It’s not often I have occasion to be publicly proud about something I was involved in but at the bottom of this page you will see that my employer is planning to release a software XSLT processor. This was my baby for longer than I care to think about. It takes a large group these days to create a production ready product, and to those involved I have to be very grateful for the care and diligence they have shown in creating something quite unique.
For those using XSLT I hope you will be glad to see another commercial implementation and one that is very firmly focused on delivering the best possible performance both now and into the future.
leave a comment