The fourth and last novelty brought by Java 7 and presented in the “Moving Java Forward” event (and also in this series of articles) was the addition of a new JVM instruction –
invokedynamic. This instruction was added to improve the support to dynamic programming languages running on top of the Java Virtual Machine, in the context of JSR 292 – Supporting Dynamically Typed Languages on the JavaTM Platform.
A long time ago, the performance of programs written in Java was a big concern and a priority of the developers of the virtual machine. When Java was still in version 1.2, Sun released HotSpot, which analyzes pieces of code that were repeated several times and optimized them, converting their bytecode to native code using Just In Time (JIT) compilation. Nowadays, there are a series of strategies that can be used by the JVM to increase the performance of programs written in Java.
(If you want to learn more about Java, go to our
Java online courses)
With the growth of popularity of dynamic programming languages (JavaScript, Ruby, Python, Groovy, etc.), it was expected that support for them in the JVM would be built, combining, in this way, the advantages of dynamic programming languages with all the existing technology in the Java Virtual Machine. However, the JVM was optimized for the programming model used by Java and, therefore, languages that are distant from this model cannot enjoy these improvements. Dynamic languages, for example, require special types of function calls, which require the creation of simulations that inhibit the JIT optimizations. In other words, despite the fact that many of these languages could already be executed over the JVM before Java 7, they couldn't harness the full potential of the virtual machine.
For Java 7, the development team of the JVM worked in the improvement of this integration, adding to the virtual machine a new bytecode instruction called
invokedynamic and a new behavior unit called method handle, which works as a pointer to a function inside the virtual machine.
This new feature interests mainly the development teams of other languages that wish to execute their programs over the Java Virtual Machine. For these programmers, there's not only an increase of performance in this integration, but the new bytecode instruction made the job of building the integration much easier. For example, Roos Instruments reported on the implementation of the integration fo Smalltalk to the JVM: the idea came up before the addition of
invokedynamic and was dismissed as being too complex; however, after JSR 292, two developers dedicating half their work hours to the project managed to port all Smalltalk commands with just three thousand lines of Java code.
Programmers that don't work with programming language development can also benefit, indirectly, from the creation of more and more projects that integrate dynamic languages to the JVM, which ultimately increases the breadth of languages that can be chosen for the development of applications that will execute in the same platform, the Java platform. This way, it will be easier to choose the best tool for the job at each case.
Finally, the new features of the JVM prepare the terrain for what's coming in Java 8, such as, for instance, project Lambda, cited in the first article of this series. For more details about the changes already made and those that are coming visit the website of the Da Vinci Machine Project (see
Links), which was created to address the expectations of JSR 292.
Conclusion of this series
Java 7 didn't bring the revolution that was long expected from it. However, as can be seen in this series of articles, many new features were included that can bring practical improvements to the day-to-day use of the Java platform, be it in a professional environment or in volunteer, open source projects. The little changes of Project Coin increase the writability, readability and reliability of Java code; the Fork/Join framework facilitates the creation of programs that execute parallel tasks; NIO.2 improves the support for file system manipulation; finally, the support for dynamic programming languages increases the number of tools that can be used with high performance over the virtual machine.
It's expected, then, that the Java platform and language continue to evolve, always bringing more benefits to all of those that work with it, directly or indirectly. Each member of the community can also do their part, be it by participating in discussions to raise issues and opportunities of improvements of the platform, be it participating directly in the Java Community Process (JCP) or the OpenJDK project. It's up to each of us to accept the invitation to
Move Java Forward!
Links
The Da Vinci Machine Project