JavaScript JVM runs Java
Written by Mike James   
Sunday, 20 November 2011

The world of software is made slightly crazy because of the huge flexibility within any computer language. Once you have absorbed the idea of a compiler written in the language it compiles what else is there left to gawp at? But... a Java Virtual Machine JVM written in JavaScript seems like another level of insanity.

In fact it is a quite reasonable idea which is only made mad by the usual positions that Java, the top dog, and JavaScript the underling, usually occupy. Java is compiled not to machine code but to a special byte code which is then run on a virtual machine which is usually implemented in native machine code. There is, however nothing stopping an intrepid programmer from implementing it in any language you can name. The only real problem is that you need the implementation to be fast so that the byte code runs at an acceptable speed.

 

javaandscript

Until recently implementing a JVM in JavaScript would have been difficult because of efficiency problems but there have been huge speed increases in JavaScript engines. So much so that a lone coder, Artur Ventura, has implemented a large part of the standard JVM using JavaScript and you can check the code out on Github.

The motivation for this effort is put very well in Artur's blog. He argues that rather than build JavaScript into web browsers they should have a virtual machine so that any language can be used. As well as this advantage, he also points out that with a JVM type approach you get automatic sandboxing and simply sending the JVM to the server provides browser independent persistence.

It really does make much more sense to have a JVM build into the browser but failing that why not simply emulate the JVM in JavaScript which is built into every browser. This is just another aspect of the steady conversion of features provided by plugins to JavaScript implementations - codecs, pdf, zipping and so on.

After 6 months of work the result is BicaVM which, it is claimed, runs 60% of byte code. It hasn't been optimized as yet, but it does run on the iPad/iPhone and it supports a JNI interface to the DOM.

Will this result in anything practical?

Probably not. It is a proof of concept and the idea that the browser should be treated as a virtual machine in its own right isn't at all crazy. It is a little strange however to think of JavaScript actually running Java programs. Perhaps it is the assembler of the internet age.

 

javaandscript

More Information

Surf the Edge (Artur Ventura's blog)

BicaVM

Related News

JavaScript H.264 decoder

 

To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter or Facebook or sign up for our weekly newsletter.

 

Banner


Actionforge Releases GitHub Actions VSCode Extension
09/04/2024

Actionforge has released the beta of its GitHub Actions tool as a VS Code extension. The extension consists of a suite of tools making up a visual node system for building and managing GitHub Actions  [ ... ]



Run WebAssembly Components Inside Node.js With Jco
28/03/2024

Jco 1.0 has been just announced by the Bytecode Alliance.It's a native JavaScript WebAssembly toolchain and runtime that runs Wasm components inside Node.js. Why is that useful?


More News

Last Updated ( Sunday, 20 November 2011 )