Bytecodes meet Combinators: invokedynamic on the JVM

Bytecodes meet Combinators: invokedynamic on the JVM. John Rose. VMIL'09.

The Java Virtual Machine (JVM) has been widely adopted in part because of its classfile format, which is portable, compact, modular, verifiable, and reasonably easy to work with. However, it was designed for just one language—Java—and so when it is used to express programs in other source languages, there are often “pain points” which retard both development and execution. The most salient pain points show up at a familiar place, the method call site.
To generalize method calls on the JVM, the JSR 292 Expert Group has designed a new invokedynamic instruction that provides user-defined call site semantics. In the chosen design, invokedynamic serves as a hinge-point between two coexisting kinds of intermediate language: bytecode containing dynamic call sites, and combinator graphs specifying call targets. A dynamic compiler can traverse both representations simultaneously, producing optimized machine code which is the seamless union of both kinds of input. As a final twist, the user-defined linkage of a call site may change, allowing the code to adapt as the application evolves over time. The result is a system balancing the conciseness of bytecode with the dynamic flexibility of function pointers.

The abstract is pretty vague, but this paper is actually quite interesting, particularly if you're interested in meta-object protocols and if, like me, you don't have the interest or patience to read JSRs. Of course, invokedynamic has been discussed many times over the years. The wheels of Java turn slowly...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Prior work

There was at least one (if not more) papers presented at Reflection '99 about something similar to invokedynamic: the invokevirtual_reflective byte code instruction, which was meant to replace invokevirtual and invokespecial. See: Jumping to the Metalevel: Behavioral Reflection Can Be Fast and Flexible by Michael Golm et al.

invokedynamic has a different design, though.

invokeDynamic and closures

For me the invokeDynamic and the combinators are a perfect way to implement closures. Opinions anyone?