Quantcast
Channel: Scratch Where It's Itching
Viewing all articles
Browse latest Browse all 73

InvokeDynamic for all?

$
0
0
I spent Tuesday evening at the Paris JUG listening to Remi Forax about his ideas of a new keyword for Java 9. It was an interesting presentation, followed by an even more interesting Q&A session.

The main point to remember is that JEE frameworks, such as Spring or JBoss or others, are using the same approach that made dynamic languages on top of Java slow, and the trick to make them quick is to use the same approach again as for dynamic languages: invokeDynamic. This would have two benefits. One, the JVM will be able to optimize the code. Currently, the JVM does not optimize Dynamic Proxies or Reflexion. But it knows how to optimize invokeDynamic and MethodHandles. And the chain of call need to be created only once per method, not at every call. Two, the stack trace will be shorter.

I am not sure about the idea of adding a special keyword for JEE in Java. I would rather have an annotation @InvokeDynamic that you could add on an interface. From this point, any method of this interface would be an invokeDynamic instead of an invokeVirtual. And that would allow a lot more than just JEE. You could do AOP-like stuff such as adding profiling information on a method call, or logging. You could rewrite some test frameworks such as Mockito using invokeDynamic. Any place you use a Dynamic Proxy can be turned into an invokeDynamic.

Let's hope it can make it into Java 9...


Viewing all articles
Browse latest Browse all 73

Trending Articles