I've been a zone leader with DZone since 2008, and I'm crazy about community. Every day I get to work with the best that JavaScript, HTML5, Android and iOS has to offer, creating apps that truly make at difference, as principal front-end architect at Avego. James is a DZone Zone Leader and has posted 639 posts at DZone. You can read more from them at their website. View Full User Profile

Project Nashorn: JavaScript's Second Chance on the JVM

12.17.2012
| 9270 views |
  • submit to reddit

Throughout 2012, JavaScript seems to be solving problems across the industry, causing some justifiable hype across a number of libraries and frameworks.  Oracle's Project Nashorn  was recently announced, due for release with Java 8 in late 2013, which will allow JavaScript to be embedded in Java applications and to develop standalone JavaScript applications.

It makes sense that the JVM maintains it's relevance by providing an improved JavaScript engine: there have been indications that performance is up to five times faster than the current Rhino implementation and the engine footprint is five times smaller. 

We spoke to Henrik Stahl, senior director of Java product management at Oracle to find out more.

DZone: Where did the motivation for Nashorn come from?  

Henrik Stahl: Oracle recognizes that multi-language support is important to Java

  • The Rhino engine currently used is dated and not architected together with the JVM
  • Writing a new engine allows us to validate the Invokedynamic (JSR-292) feature in JDK 7, leverage all new language and JVM features in JDK 8, as well as provide a seamless way of using Javascript and Java code in the same program.

DZone: How long have Oracle been working on it internally?

Henrik: We have been working on Nashorn for the past year and a half.
 
DZone: Was it originally for any other purpose or products?

Henrik:
No. The goals have remained the same since the project's inception, although we have found ways to use it that we hadn't originally anticipated; such as using it as a backend for the Javascript development and debugging features in Netbeans.

DZone: How much of Nashorn is already complete?

Henrik: The Nashorn engine is passing all ECMAScript 5.1 compliance tests.  Early access users have been able to switch their application from Rhino to Nashorn without major issues.
 
 DZone: And what still needs to be added?

Henrik: The team is currently focused on robustness and performance as well continuing to evaluate potential JVM optimizations.  The team is also starting to explore support for upcoming ECMAScript 6.0 features.
 
 DZone: Why do you think that Nashorn will be more successful than Rhino, the previous JS implementation on the JVM? 

  • Nashorn significantly outperforms Rhino, and the gap will increase even more as we now move focus from spec compliance and stability to performance
  • Nashorn implements a new meta-object protocol that simplifies calling Java APIs from JavaScript, and enables seamless interactions between JavaScript and Java.
  • Nashorn enables infrastructure providers to consolidate their JavaScript and Java workloads on single virtual machine technology, and leverage the JVM management, debugging and profiling capabilities.