Live data from Hacker News

Java Virtual Machine in pure Node.js

github.com

41–50 of 143 posts

Re: Java Virtual Machine in pure Node.js

#41
Interesting! It looks like you've reimplemented portions of the Java Class Library rather than use e.g the existing class files from OpenJDK.

My current research project, Doppio [1], implements the native portions of the OpenJDK Java Class Library so it can use an unmodified copy of the OpenJDK JCL. As a result, it can run a bunch of nontrivial programs (javac/javap/Rhino/Kawa-Scheme).

One issue you will run into is with multithreading. Since JavaScript has no true threading implementation with shared memory, you'll need to be able to suspend and resume virtual JVM threads. For this reason, Doppio maintains an explicit JVM stack representation.

Anyway, feel free to check out our code, reuse portions of it, or contribute if you're interested; it's MIT Licensed and under active development. :)

[1] Demo: http://doppiojvm.org/ Code: https://github.com/int3/doppio

Re: Java Virtual Machine in pure Node.js

#42
post #5

Would be interested in seeing a JVM written in Go.

Considering Go is slower than C, and the JVM is written in C/C++, I'd say the JVM would be slower.

I'm not trying to say I wouldn't like to see it, but I don't think anyone would use it, is all. And it's sad when cool software doesn't get used.

Re: Java Virtual Machine in pure Node.js

#43

Now, my question is. WHY!? I might be crazy, but does anyone see a legitimate use for this?

I would argue you haven't really learned how to program until you implement some kind of machine yourself or at least written a compiler. He probably has a very intimate understanding of how all that works now, and I bet he did it for that reason alone.

Re: Java Virtual Machine in pure Node.js

#44
post #17
post #4

Just a toy implementation[1], if someone is wondering. [1]The basic .class file attribute parsers are located in libs/classfile, while a simple bytecode interpreter can be found in jvm.js. It doesn't load a real runtime library (classpath, apache harmony,openjdk,etc...) but it partially implements a few java.* classes in pure javascript under libs/java.

Can someone point out what it can do and what it can not do; I am curious what 2.000 lines of JavaScript can do. How much more code would it take to get a full featured implementation?

It has a java bytecode interpreter and an initial implementation of a classfile loader. As said above it doesn't have a full implementation of the java runtime, just a few classes to be able to print out to standard output and su things with string and not much else (at least from what i've seen of the content of libs/java).

Regarding the loader, it can load a few sections from a classfile, the one containing methods bytecodes, the exceptions table and the constant pool (i.e. where all your string are stored with some other "constants"). How much it could take for a full implementation? It depends of what you mean by full. Even using one of the opensource runtime library like openjdk,classpath,harmony/android i'd say a few years done solo, and not much less with more people, to build something complete and stable enough for general use. Definitely not a simple project.

Re: Java Virtual Machine in pure Node.js

#45
post #11

Earlier quoted context omitted.

THE HORROR

Hey, if you want your precious node back, you can then just run Rhino on the JVM on the node.

This provides a highly scalable, highly available infrastructure for running the JVM in Rhino on the JVM in Node.

Re: Java Virtual Machine in pure Node.js

#46
post #37
post #25

This is the worst thing that ever happened

Worse than the last worst thing that ever happened? https://news.ycombinator.com/item?id=6581323

I thought that that was the worst thing that ever happened, and I turned out to be wrong. No inconsistency here.

Re: Java Virtual Machine in pure Node.js

#47

Earlier quoted context omitted.

Hey, if you want your precious node back, you can then just run Rhino on the JVM on the node.

This provides a highly scalable, highly available infrastructure for running the JVM in Rhino on the JVM in Node.

Scalable in the sense that you can try and climb up the layers of abstraction in the same way you'd scale a mountain of rubble, yes.

Re: Java Virtual Machine in pure Node.js

#49
post #23
post #12

18ms for calculating Fibonacci numbers from 1 to 10. This is definitily bringing JAVA back to the good old days of enterprise execution speeds. :-) Really cool proof of concept! I would really enjoy seeing more projects like this!

> JAVA Why did you spell it in all-caps here?

Everything enterprisey has to be in all caps and mean something that's trying to be cool.

JAVA = Just Another Vague Acronym.

That and you need to use xml for everything to be enterprise.

Re: Java Virtual Machine in pure Node.js

#50

Earlier quoted context omitted.

Hey, if you want your precious node back, you can then just run Rhino on the JVM on the node.

This provides a highly scalable, highly available infrastructure for running the JVM in Rhino on the JVM in Node.

It's turtles all the way down.
Post reply on HN