As an implementor of Pnuts, I have to write about JSR292, a.k.a invokedynamic.
My conclusion is that invokedynamic definitely won't help. If I were a member of EC,
I'd vote NO, because it is not worth adding a new mnemonic to the VM spec. Even if
the capability is provided as an API, it will rarely be used by JVM languages.
(I'm not talking about hotswapping here.)
Pnuts is one of the fastest scripting language on JVM. One secret of the efficient
implementation is sophisticated method caching. Pnuts usually does not use Reflection
API to call methods, even when accessing JavaBeans properties. Pnuts generates method
proxies on-the-fly and reuse them. Reflection API is used only when method proxy
can't be used because of classloader mismatch. It is true that searching appropriate
methods from actual arguments is expensive, but the impact is almost completely invisible,
thanks to the method cache. In fact, method call in Pnuts is even faster than that of
Ruby. Is it still worth adding a new mnemonic? Or the mnemonic is for other language
implementors?
In Pnuts, it is possible to give a hint to select a particular method, assuming
that the method is overloaded and two or more methods match the actual arguments.
When some of the actual arguments have "cast" to some type, the information is
used to choose an appropriate method. e.g. String.valueOf((char[])array). How can it
be achieved using invokedynamic?
Also, Pnuts searches methods through JavaBeans method descriptors, but not Class.getMethods(..).
And the way of searching methods/constructors can be customized. Under some configuration, private methods
can be selected. This kind of flexibility can be achieved only at application-level.
The cause of slow down is not just invoking methods. Some other JVM languages
don't generate bytecode and interpret the code in their implementation. They
can't be faster unless a bytecode compiler is implemented. Even JVM languages with
bytecode compiler, the generated code and the runtime library should be efficient.
If the generated code and the runtime library is not efficient, invokedynamic
would have no effect.