BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Nashorn Proposed as Replacement JavaScript Engine for OpenJDK

Nashorn Proposed as Replacement JavaScript Engine for OpenJDK

This item in japanese

Oracle's multi-language lead Jim Laskey has proposed a new JVM-based JavaScript implementation, Nashorn, as an OpenJDK project. Nashorn is billed as a successor to Rhino, the current JVM JavaScript implementation that was started at Netscape in 1997, and which has shipped, albeit in a slightly modified form, since the release of Java SE version 6 in December 2006. Nashorn is planned to ship as part of Java 8.

"The goal is to provide a lightweight high performance JavaScript on a native JVM," Laskey said in his project proposal to the OpenJDK:

The scope of this project will include, but is not limited to, a parser API for scanning JavaScript source code, a compiler to convert ASTs [Abstract Syntax Trees] from the parser to JVM byte code, and a runtime to support the execution of said generated byte code. Execution of JavaScript in this environment will be in conformance with ECMA-262 Edition 5.1 and will adapt to newer guidelines as standards evolve.

Despite the Rhino-related name, Nashorn (the German word for rhinoceros) is an entirely new code-base that makes extensive use of Java 7's InvokeDynamic byte code instruction. The resulting implementation is both smaller and considerably faster than Rhino making it more suitable to run on embedded/mobile devices; it runs on both the Beagle Board and Raspberry Pi for example.

Speaking at JavaOne in September, Laskey stated that the team are tracking the performance of other JavaScript implementations, so the performance should be comparable to that of a modern browser. Also at JavaOne, Twitter's Sam Pullara described how he used Nashorn to render Mustache.js templates.

I was blown away that first of all everything just worked - I never ran into a correctness bug with the Nashorn stuff. And on the performance side on the most challenging tests it was more than 20 times faster than Rhino.

Elsewhere the NetBeans team have completely re-written their JavaScript implementation on top of Nashorn. For projects with a lot of JavaScript files to scan, the change has resulted in a significant reduction in IDE start-up time.

As well as the performance gains when compared to Rhino, Nashorn has the advantage over other alternative JavaScript implementations that it has access to the rich set of Java libraries, including JavaFX on the client-side, and JSP on the server-side. To support the interop Nashorn uses Dynalink, the Apache-licensed open-source metaobject protocol built on top of InvokeDynamic and developed by Attila Szegedi, who joined Oracle from Twitter. Dynalink provides a set of agreed conventions for specifying higher level operations on objects in a program execution environment, and ships with a linker for plain Java objects.

A blog has been created to go with the Nashorn proposal. Voting has now begun and runs until 6 December. With Nashorn already 100% compliant with ECMA-262, initial work within the OpenJDK project would concentrate on performance and hardening the platform for general use. Potential OpenJDK collaborators include Twitter, IBM and Red Hat.

Rate this Article

Adoption
Style

BT