BT

InvokeDynamic and Javascript: New Compiler Dyn.js, Oracle Nashorn and Rhino

by Werner Schuster on Oct 02, 2011 |

A new implementation of Javascript has been announced at jsconf.eu: dyn.js. Dyn.js compiles Javascript code to Java bytecode and requireѕ the new dynamic language features in Java 7 such as invokedynamic and Method Handles.

Java 7 comes with invokedynamic and Method Handles which can help with the implementation of dynamic languages on the JVM. The JRuby team has worked to integrate invokedynamic and some experiments with improving Rhino's speed on Java 7 were started too.
Another project to improve dynamic languages on Java 7 is Attila Szegedi's Dynalink, "an implementation of invokedynamic-based multi-language linking and metaobject protocol framework", which should allow cross-language integration of different language runtimes on the JVM. Attila works on Rhino, the Javascript implementation for the JVM.

Oracle has announced Nashorn (PDF Link), a Javascript implementation for Java which will use Java 7's dynamic language features. Nashorn has not been released yet and, according to the linked slides, is planned to be shipped with Java 8.

Another Javascript implementation for the JVM has now been announced at JSConf.eu by Douglas Campos: dyn.js, (GitHub Repository). 

InfoQ talked to Douglas Campos about dyn.js, the reasons for its creation and more.

InfoQ: What's dyn.js?

dyn.js is a new implementation of the ECMAScript 5 specification. My main motivation on creating dyn.js was to have a friendlier codebase, taking advantage of the latest cool JVM stuff, like invokedynamic, MethodHandles & friends.

InfoQ: Are you working on an ahead-of-time compiler or a dynamic runtime? 

We started building an ahead-of-time compiler to bytecode, but this can definitely change over time, as we continue to implement the spec.

InfoQ: How is dyn.js different from Rhino or Oracle's Nashorn?

Rhino is an truly piece of art - back when Rhino was born, the JVM was not cool as today, so they really made miracles getting performance by hand-crafting almost all aspects of their runtime. So dyn.js is kinda like we were starting Rhino again in 2011 - with a much powerful JVM and not worrying about backward compatibility.

I announced dyn.js during BrazilJS 2011 (braziljs.com.br), and Oracle announced Nashorn at JVM Language Summit 2011 (http://openjdk.java.net/projects/mlvm/jvmlangsummit/). The main difference is that Oracle's implementation is commercial and AFAIK, they haven't decided if it will ever be opensource (To Be Defined status). dyn.js is opensource software (Apache 2 like license).

InfoQ: How are you using invokedynamic and Attila Szegedi's Dynalink?

The main reason to be using invokedynamic is to be able to have a smaller runtime, as you can have polymorphic method signatures (that will be linked only at runtime), and JIT-friendly dynamic code.

Szegedi's dynalink is core to the dyn.js runtime, as we route all dynamic invocations through dynalink's machinery, which has many features, like type conversion (I'm using it for autoboxing/unboxing of JS primitives right now), inline cache (it has a monomorphic inline cache), and the most interesting feature, the Meta Object Protocol, that can revolutionize how dynamic JVM-based languages interact, allowing even JIT inlining between language runtimes.

InfoQ: Any plans on integrating Node.js-style frameworks, maybe RingoJS?

That's definitely a good target, I'm looking already towards node.x framework , but I believe that once we get closer to spec compliance that kind of stuff will be a natural path.

InfoQ: Who's behind dyn.js?

I started working on the project with Alexandre Porcelli (@porcelli) (the parser guy), and after that I began inviting more friends to help. The geek appeal is definitely strong, but I'm really into language runtime development (I'm a JRuby contributor), and found a place to get my feet wet with Java 7 features - that unfortunately, don't have that much documentation available (we're exploring the cool new stuff the hotspot/mlvm guys did).

The dyn.js repository is available at GitHub and requires Java 7 as well as Jitescript, a Java API for bytecode creation inspired by BiteScript. For more technical details, see Douglas' slides for the dyn.js talk at JSConf.eu.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT