Transposit is built on a Java backend uses Nashorn. We wanted to support ES6 syntax, so we investigated alternatives.
Sarah Brown · Jan 2, 2019
We considered introducing NodeJS into our stack, but decided it would take more time and effort than we wanted to invest just to be able to use ES6 syntax. So we chose GraalVM instead because the migration path from Nashorn is clear and fast.
While some things were well documented (such as Nashorn compatibility mode), adopting such a new technology unsurprisingly had areas that lacked documentation and included a few hurdles to jump. We want to share with you all some lessons learned from our adventure.
GraalVM is a collection of many projects, not all of which need to be used at the same time. In the case of migrating from Nashorn to GraalVM, we used:
Truffle: A Java library for building language implementations.
GraalVM Polyglot API: The API that enables the embedding of Truffle languages (the guest language) within the JVM (the host language).
Graal Compiler: A JIT Java compiler that shows impressive performance benefits generally, and specifically it provides optimized performance for Truffle-based languages running on the JVM.
The Graal SDK looks for languages to use under META-INF/truffle/language. The published GraalJS library comes with its own list of languages, but 1.0.0-rc8 and rc9 don’t include the regex language that it’s dependent upon. For the moment, we wrote our own truffle/language file:
Nashorn does not provide the CommonJS require() syntax and unfortunately neither does GraalJS. There’s a popular solution for Nashorn called nashorn-commonjs-modules. Graal tooling is less evolved, so we created our own commonjs fork for our Graal solution.
While most of the hype around GraalVM has been around compiling JVM projects to native, we found plenty of value in its Polyglot APIs.GraalVM is a compelling and already fully useable alternative to Nashorn, though the migration path is still a little rocky, mostly due to a lack of documentation. Hopefully this post helps others find their way off of Nashorn and on to the holy graal.