Nashorn is a JavaScript Engine developed in the Java programming language by Oracle. It’s based on the Da Vinci Machine (JSR 292) and was released with Java 8.

JavaScript is very popular on server-side programming (such as with Node.js). And Nashorn allows the integration of JavaScript and Java applications by accessing JavaScript functions in Java. It instantly compiles the JavaScript code in-memory and passes the Java bytecode to the JVM. Support for server-side scripting is one of the handiest tools in programming, as programmers can easily fulfill requirements without having to recompile each time.

Bad news for Nashorn users, though. JEP 372 will remove Nashorn in a future JDK version. It all started when criticism against Nashorn came in JDK 11 by JEP 335 in 2018. Ever since all Java developers started seeking alternatives to Nashorn.

Readers find the justification for removing Nashorn in JEP 372, as follows:

“The Nashorn JavaScript engine was first incorporated into JDK 8 via JEP 174 as a replacement for the Rhino scripting engine. When it was released, it was a complete implementation of the ECMAScript-262 5.1 standard.
With the rapid pace at which ECMAScript language constructs, along with APIs, are adapted and modified, we have found Nashorn challenging to maintain.”

The removal of Nashorn may prove to be a big blow to the Java developer community. A large number of Java coders use it. As do various onsite development companies, as their primary technology due to the popularity of JavaScript.

The alternative most likely to succeed it is GraalVM’s modern JavaScript Engine.
GraalVM JavaScript comes with a modern, compatible, and highly performant JavaScript engine. Unlike Nashorn, this engine is compatible with the latest ECMAScript specifications. In other words, it doesn’t have the problem that caused Nashorn’s scheduled phaseout.

It also allows interoperability with Java code just like Nashorn. It also provides almost all the extensions Java coders have been using with Nashorn. (Although some modifications will be needed in the previous code to run on GraalVM JavaScript).

Why Use GraalVM JavaScript?

GraalVM JavaScript offers functionality like Nashorn. But that’s not the only reason to consider it. Better features. Performance enhancements. The list goes on. Here are five reasons that make GraalVM look like an appropriate alternative.

1. GraalVM JavaScript Is Compatible With ECMAScript

As mentioned before, GraalVM JavaScript is a fully compatible JavaScript/ECMAScript Engine. This has been verified with test suites like ECMAScript’s Official Test262 Suite. GraalVM JavaScript is also compatible with the latest ECMAScript 2019 specification. It already supports all features expected in the upcoming ECMAScript 2020 specifications. In other words, compatibility is not a major concern now. Or likely to be one in the future.

2. Compatible With Nashorn’s Extensions

Nashorn extensions will also be removed due to compatibility issues. But some go beyond the ECMAScript specification. The top talent behind GraalVM kept that in mind. That’s why it included interoperability with Java and some non-standard built-in objects and functions mostly around Java interoperability. GraalVM JavaScript supports almost all these extensions. While most Nashorn code will run as it is on GraalVM, some of it might need minor tweaking. Especially in the case of some security-related features. i.e. GraalVM uses security by default. And it may need more flags to enable less secure ‘old’ features.

3. GraalVM JavaScript Is Faster Than Nashorn

GraalVM JavaScript was developed by top software engineers, who wanted the highest possible application performance. Its performance is already on par with many other JavaScript Engines. Tests prove that GraalVM JavaScript is roughly four times faster than the Nashorn Community Edition. And six times faster than Nashorn Enterprise Edition. (As measured by the Octane JavaScript Benchmark Suite).

The top developers in the GraalVM team are very focused on the performance of all supported programming languages. They track performance improvements in every release. So we can be sure that performance improvements will keep coming in future releases.

4. GraalVM Is A Supported Product

There are currently two versions of GraalVM available. An open-sourced Community Edition and an Oracle product, Oracle GraalVM Enterprise Edition. With the Enterprise Edition, users will get the expected maintenance service of Oracle (including 24/7 support and updates).

5. GraalVM Is Also Compatible with Node.Js

GraalVM JavaScript can also execute Node.js applications. This is not possible with Nashorn, by the way. GraalVM can execute almost any application written for the original Node.js platform. This was verified by testing it against more than 100,000 npm modules. GraalVM can execute both JavaScript-based modules and C-based modules. Any normal web application will work perfectly on GraalVM. Thanks to its compatibility with Node.js, GraalVM gives you the opportunity to take advantage of tools and support from the Node.js ecosystem.

Conclusion

With all these promising features, the shift to GraalVM JavaScript Engine doesn’t appear to be as difficult a decision for Java developers as we thought.

Author

Shaharyar Lalani is a developer with a strong interest in business analysis, project management, and UX design. He writes and teaches extensively on themes current in the world of web and app development, especially in Java technology.

Write A Comment