Last weekend I’ve been in Codebits and Made a presentation about computer languages that you can watch here. Like this post, its was presented in poor english, I know that.
The gist of it is: I don’t have the same hard on that everyone else is apparently is having with JavaScript. Sure is cute language. Every one likes its functional nature, the prototype base inheritance, but it lacks crap that we decided decades ago that are essential (eg. Modularization) and even has some serious problems (eg. == vs === is a lousy way to handle identity).
So what?
I believe that the browser should have some kind of virtual machine, in which one of the languages would be JavaScript, but if you are writting a project in some other language, why wouldn’t you want to write the client side in that same language as long you provide the runtime for that language. More so, like I attempted to point out in my talk, I truly see languages as a tools. You should the best one for every problem.
Beyond langauges
Having a virtual machine on the browser also has some interesting side effects. The first one is that you have automatically sandboxing so you can allow untrusted foreign code to run on you page without problem. You also can froze the virtual machine running on your client and send it back to the server, allowing you to have a very easy way of implementing browser independent state persistence. Portable devices have no plug in architecture and can’t run Java Apples (not that I want to but its a fact). A more exoterical one is that if your code blows up you can package your virtual machine and send it back to the server for post mortem analysis. But with out a doubt that the most important reason to write something like this is: Because I can.
Because of some of the projects I’ve been thinking about starting, I’ve been searching for some kind of Virtual Machine in JavaScript. I was more inclined to JVM due having a large ecosystem. However the only JVM in JavaScript available in JavaScript was Orto. There was no documentation or code to begin with and from what I’ve could gather, it was a bytecode to source translator, and translators have problems (in GWT for instance you can’t use reflexion because during the translation you loose all class information). Because of that I decided to implement from scratch a JVM and that is how BicaVM was born. BicaVM is a JVM implementation in JavaScript that I started writing 6 months ago and released last friday.
Fast or slow?
One of the most common complains I’ve heard when reading the comments from the original post is that Java & JVM is slow and having it in JavaScript will be even slow. I could spend countless words telling you that you can use preemptive code transformations, or JIT is actually simple to implement in this kind of of VM, you could download initialization blobs that would speed up the init process, but I would like to leave you with the words of Dr. Knuth: “Early optimization is the root of all evil”.
So at this point BicaVM can run Java Code. You can now change the DOM using Java because I have support for JNI (that maps to JavaScript functions). Oh and does run on iPad/iPhone.
You can get it here.
Comments
6 responses to “BicaVM: JVM in JavaScript – Why?”
[…] Представлен новый проект BicaVM, в рамках которого создана реализация Java VM (JVM), написанная на JavaScript и способная выполняться в любом современном браузере. […]
[…] “BicaVM: JVM in JavaScript – Why?” by Artur Ventura (Surf The Edge blog; 2011.11.20) – http://www.surf-the-edge.com/2011/11/15/bicavm-jvm-in-javascript-why/ […]
[…] Представлен новый проект BicaVM, в рамках которого создана реализация Java VM (JVM), написанная на JavaScript и способная выполняться в любом современном браузере. […]
非常伟大的设计啊
棒
厉害啊。。哈哈。原来那个js版的虚拟机运行linux内核,现在又有了jvm。