Deprecation of Nashorn :(

478 views
Skip to first unread message

Captain Starbuck

unread,
Jul 10, 2018, 5:19:54 PM7/10/18
to ScriptCraft - Scripting Minecraft

I haven't been in here a long time - haven't had time for gaming and was waiting for the world of MC v1.13-1.14 to shake out before getting re-involved.

 

But this did just catch my eye:

 

Intent to deprecate Nashorn: https://bugs.openjdk.java.net/browse/JDK-8202786

Related article, not much more info:https://jaxenter.com/nashorn-javascript-engine-deprecated-145320.html

The recommended replacement: https://www.graalvm.org/

 

Note the comment in JEP 335:

"This deprecation does not affect, in any way, the javax.script API."

 

For ScriptCraftJS, that could affect code that starts like this:

 

NashornScriptEngineFactory factory = new NashornScriptEngineFactory();

ScriptEngine engine = factory.getScriptEngine("--language=es6");

 

And without Nashorn it would simply be:

 

ScriptEngineManager manager = new ScriptEngineManager();

ScriptEngine engine = manager.getEngineByName("javascript");

So ScriptCraftJS might not be affected at all except where it's specifically making use of the Nashorn engine. In my initial fork for v1.12 I switched from Rhino to Nashorn. That worked, but was never pulled back to the SCJS core. At some point we'll have to experiment with the javax.script API to see what it does and does not provide.

 

Jonathan Perret

unread,
Aug 12, 2018, 4:51:57 AM8/12/18
to ScriptCraft - Scripting Minecraft
Note that if you are running ScriptCraft under Java 8 or better (which you should be doing if you're running Minecraft >= 1.12 as Mojang states that it requires Java 8: https://help.mojang.com/customer/en/portal/articles/325948-minecraft-java-edition-system-requirements), you're already using Nashorn. Rhino is simply not part of the Java 8 JRE so `manager.getEngineByName("javascript");` will always give you a Nashorn instance.

So by changing nothing, ScriptCraft is already using Nashorn through the non-deprecated javax.script API.

But of course this is of little use if Nashorn itself is deprecated. It's not clear if this means that `manager.getEngineByName("javascript")` will start returning `null`.

With a bit of luck, GraalVM will implement the javax.script API and return its JavaScript engine when requested by `manager.getEngineByName("javascript")`…

Jonathan Perret

unread,
Aug 13, 2018, 6:01:33 AM8/13/18
to ScriptCraft - Scripting Minecraft
Just for kicks I tried running Spigot 1.13 and ScriptCraft under GraalVM (1.0.0-rc5).

As I hoped, GraalJS is plugged into the javax.script API and `getEngineByName("javascript")` returns a GraalJS engine. So I didn't have to change a single line of ScriptCraft's Java code. I just had to add `-Dpolyglot.js.nashorn-compat=true` to the Java command line to enable Nashorn syntax compatibility.

Compatibility with Nashorn is not yet complete though, so there were a few roadbumps when unsupported features were used in the ScriptCraft's JavaScript code, such as:
  • explicit overload resolution: in Nashorn you can write `player['getTargetBlock(java.util.Set,int)'](null, 120)` to be explicit about which overload of a method you intend to call, but this is not yet supported by GraalJS;
  • property accessors: Nashorn lets you write `self.location` or `self["location"]` instead of `self.getLocation()`. GraalJS today supports `self.location` but not `self["location"]`;
Overall it was relatively quick to have ScriptCraft mostly running under GraalVM. So I'm quite optimistic that by the time GraalVM replaces Nashorn as the officially sanctioned way of running JavaScript under the JVM, it won't take a lot of work to keep ScriptCraft running.

Captain Starbuck

unread,
Sep 29, 2018, 3:04:26 PM9/29/18
to ScriptCraft - Scripting Minecraft
That's amazingly positive and informative. Thank you VERY much, Jonathan.

Let's try to define terms here because this is a huge world that's outside of the Minecraft game, and common Java and JavaScript development.

GraalVM is a "program" that can be run from the command line, or it can be embedded in databases and other applications.
One of the principle benefits of GraalVM is that it facilitates multi-language = polyglot development, much like Rhino/Nashorn. For our purposes that means having Java call JS, JS call Java, or (bonus!) making use of other languages like Ruby, Python, and C/C++. In other words, where Java+Nashorn=JavaScript, Java+GraalVM=JavaScript+Ruby+Python+...

GraalVM allows new languages to be added to its ecosystem. GraalJS is one of these and the source to support JavaScript is all FOSS (see GitHub repo below). GraalJS uses the hooks provided by GraalVM to integrate with Java in the exact way that we need with ScriptCraftJS. So our JavaScript code runs through GraalJS, which goes to Java, which goes into the game.

Where I'm not connecting dots here is how we get the GraalVM into Minecraft servers.
A Minecraft server admin will download, build, and install the Spigot executable. But I believe we're going to need Spigot to be built with GraalVM, not the default JDK. That means changes to the BuildTools script. For individuals this won't be a problem. For players who do not control their server, who just want to use ScriptCraftJS to add scripting to an existing server, I believe this all implies getting the Minecraft server host to load a different build of Spigot ... which will be very difficult for most players who individually don't have the "clout" to drive such an initiative.

I've opened discussion with the Spigot team to see what they're thinking about the topic. Honestly at this level my experience with the topic starts to waver. I'm not as intimate with Spigot requirements as one needs to be to have this discussion. I'm certainly not intimate enough with GraalVM to understand what it means to substitute that for the JVM.

That's what I have now. I'm hoping we can combine efforts here to document the details.
Jonathan, I believe you're further along on this than any of us.

Regards to all.

Some reading on the topic:

Captain Starbuck

unread,
Jul 7, 2020, 12:00:22 AM7/7/20
to ScriptCraft - Scripting Minecraft
There has been some buzz lately about what's happening with ScriptCraftJS now that Nashorn is not just deprecated but it has actually been removed from Java.
Anyone who updates to the latest Java JRE will lose ScriptCraft functionality.


As noted by Jonathan Perret in 2018, the answer still seems to be GraalVM.

See notes in this thread, and a very recent article on the topic (4/2020) :
This works from JVM 11 through 15 and beyond.
Also as noted in that article :

"The advantage of switching to the new engine, besides the point that your application runs on the latest JVM, is that you also get a more modern JavaScript engine. Nashorn only supports ECMAScript 5.1. GraalVM JavaScript, on the other hand, is in version 20.0.0 fully compatible with ECMAScript 2019, and it even supports most of the ES2020 features. Starting with GraalVM 20.1.0, ECMAScript 2020 is fully supported."

That's huge. It's much better than what we had.
And I dare say that for anyone inclined toward TypeScript, adding even more functionality to JavaScript, JS/TS plugins for Minecraft should be as powerful as any Java plugin, and more versatile.

If anyone experiments with these tools, please create new threads to discuss your experiences!
Reply all
Reply to author
Forward
0 new messages