12 ms·
Java Virtual Machine in pure Node.js
- stevekinney 13y agoAtwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript.
- almosnow 13y agoJavascript's Rule 34
- bsg75 13y agoJS.js
- mtdewcmu 13y ago...and, eventually, there will be no other language than JavaScript.
- tlrobinson 13y agotlrobinson's Law: any submission to Hacker News about a novel JavaScript program will contain a comment referencing Atwood's Law.
- angersock 13y agoFinally, I can run JRuby on my node server!
- adlpz 13y agoTHE HORROR
- angersock 13y agoHey, if you want your precious node back, you can then just run Rhino on the JVM on the node.
- mtdewcmu 13y agoWhy not just use the javascript x86 emulator that somebody posted to boot an OS? Then you can run the Hotspot JVM, v8, ad infinitum. Piece of cake.
- TheZenPsycho 13y agoHotspot runs the program faster than V8? no problem. Emulate x86 in v8 run hotspot inside emulator. now you got your performance back.
- mtdewcmu 13y agoYes, it's like a beautiful perpetual motion machine. Only one problem. Where's node.js?
- knappador 13y agoI'm thinking the next big step is to build ASIC's with hierarchical memory sub-systems that can quickly load and execute either x86 or ARM instructions, kind of like binary run-times implemented in hardware, and then boot operating systems on them so that programs don't have to worry about the physical memory address layout or disk file-systems, and then finally run a compiled version of the JVM that includes hot-spot. Then we would all be able to run Java, and it would be pretty fast, probably faster than any other implementation, and totally capable of integrating with the entire Java ecosystem.
- drtse4 13y agoJust 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.
- xentronium 13y agoShould be renamed to node-java instead of node-jvm, I think.
- deleted 13y ago[deleted]
- mooreds 13y agoWhat version of java does it handle? Does it support java.lang.*? What other standard libraries?
- drtse4 13y agoIt's too early to talk about java versions, but i suppose he used the latest jvm specification to implement his classfile parser. Only a few methods of some classes of java.lang and java.io (screen output and some basic stuff like String methods,etc..).
- abhididdigi 13y agoPlease feel free to fork it, improve and post back.
- drtse4 13y agoI respectfully decline the offer :)
- danbruc 13y agoCan 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?
- ilaksh 13y agoWould be interested in seeing a JVM written in Go.
- niclupien 13y agoIt's exactly what I thought whem I saw this.
- bronxbomber92 13y agoWhy? I must be missing the connection between Node and Go.
- MrBuddyCasino 13y agoFor 15 minutes of fame on HN, of course.
- film42 13y agoConsidering 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.
- pkolaczk 13y agoOnce the JVM emits machine code for the bytecode, it doesn't matter what language the JVM is coded in.
- pron 13y agoI think that the other way round, Go on the JVM, might be nice. It could actually be faster than native Go; Go function dispatch might benefit from the HotSpot JIT inlining optimizations.
- dlsym 13y ago18ms 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!
- derleth 13y ago> JAVA Why did you spell it in all-caps here?
- mitchty 13y agoEverything 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.
- KennyCason 13y agoAt least now in java things are going from XML to annotations :)
- mbreese 13y agoHasn't that transition been going on for 6+ years now? I guess that's what counts as agile in the enterprise space.
- angersock 13y agoXML is like violence: if it isn't working, you aren't using enough.
- mtdewcmu 13y agoWho doesn't wish it was still 1999? Hot stock market, millenium mania, cheap gas, dot-coms. Really slow Java makes it all come rushing back.
- ahoge 13y ago
- orokusaki 13y agoWhy... :/
- nonchalance 13y agoThe example makefiles appear to use javac. Next step: Java compiler in node
- adultSwim 13y agoFor anyone interested in the details: -Reads in real .class files -Uses the JS run-time to implement the Java run-time (e.g. there isn't a garbage collector written in JS, the JS collector is used) -Only implemented part of java.lang and java.io
- drtse4 13y agoA handful of classes with a few of their methods, in java.lang and java.io.
- tzaman 13y agoNow I'll have even bigger problem explaining what the difference between Java and Javascript is! :)
- golergka 13y agoIt's like Car and Carpet. But it's also the kind of car that you can build out of carpets.
- egeozcan 13y ago...or the carpet that you can build out of cars, considering the Ringojs.
- ahoge 13y agoJava 6.0 comes with JSR 223 ("scripting for the Java platform"). It's a framework for hosting scripting engines. 6.0+ is shipped with a JavaScript engine based on Mozilla's Rhino. http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29 http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29
- jmpe 13y agoWith GWT you can translate the Java application to standalone JavaScript files ... and with this implementation you can run Java in a Javascript environment. Which one would perform best?
- robmcm 13y agoGWT with out a doubt. It's running on a smaller stack and the translation is done at compile time not runtime.
- big_lou 13y agoThis is the worst thing that ever happened
- antonpug 13y agoAgreed. He must have done it for fun, just to prove that it could be done. I don't think anyone legitimately would actually want this...
- cmbaus 13y agoWorse than the last worst thing that ever happened? https://news.ycombinator.com/item?id=6581323 https://news.ycombinator.com/item?id=6581323
- szatkus 13y agoI created something similar some time ago. https://github.com/szatkus/js2me https://github.com/szatkus/js2me Although I targeted only J2ME subset. Also I found few similar projects: https://github.com/nurv/BicaVM https://github.com/nurv/BicaVM http://plasma-umass.github.io/doppio/about.html http://plasma-umass.github.io/doppio/about.html
- CmonDev 13y agoSo now I can use one of those Java libraries that implement a JavaScript engine and finally have JavaScript running on node.js?
- duiker101 13y agoNow you just need to run Rhino(https://developer.mozilla.org/en/docs/Rhino https://developer.mozilla.org/en/docs/Rhino) on it and you will be totally meta.
- jvilk 13y agoMy current research project, Doppio, can already run Rhino in the browser using JavaScript. :) Demo: http://doppiojvm.org/ http://doppiojvm.org/ Code:https://github.com/int3/doppio https://github.com/int3/doppio
- mdellabitta 13y agoWhy run Rhino when you can run Nashorn and Node.jar? http://kaeff.net/posts/why-ruby-and-nodejs-folks-should-care-about-project-nashorn.html http://kaeff.net/posts/why-ruby-and-nodejs-folks-should-care...
- antonpug 13y agoNow, my question is. WHY!? I might be crazy, but does anyone see a legitimate use for this?
- base698 13y agoI 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.
- dshefchik 13y agoYes, yes and you can't DJ without crates of vinyl and 2 turntables. I'll get off your lawn now
- saraid216 13y agoThis question on this kind of topic needs to stop being asked on Hacker News. It's fair to ask whether or not there was a material usage intended for the project, but if isn't one, we really need to stop implying that there should be.
- aryastark 13y agothat's not a chance I'm willing to take. This is how PHP started. It was a reject experiment that escaped the lab. Then some poor souls took it seriously. Now all of humanity suffers.
- saraid216 13y agohttp://php.net/manual/en/history.php.php http://php.net/manual/en/history.php.php Um. No.
- suyash 13y agoIn Contrast, there is already a project called Avatar-js - It' s Node.JS like solution written in Java 8 and meant for Java developers to write JavaScript code in a seamless manner. https://java.net/projects/avatar-js https://java.net/projects/avatar-js
- jvilk 13y agoInteresting! 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/ http://doppiojvm.org/ Code: https://github.com/int3/doppio https://github.com/int3/doppio
- ajross 13y agoSeems like the "reimplemented" portions are bits that need to interact directly with the script environment -- String is implemented in terms of V8's native strings, etc... That seems like a feature, not a bug -- you wouldn't want the interpreter needlessly doing bytewise diddling of an abstraction that is already very robust in the host environment.
- jvilk 13y agoIn the Java Class Library, any function that needs to interact with the environment outside of the JVM itself (OS/file system/network/threading/etc.) is implemented in C and is marked as 'native'. Those are the functions that we explicitly implement for the JavaScript/browser environment. You are right that we could extract more performance by mapping particular classes directly onto efficient browser functionality -- such as String. In the future, we could implement specific classes such as String directly in JavaScript for a performance boost. :) As a side note, ASM.js itself does not have a String type, which leads me to believe that this particular optimization might not be beneficial if we switch to an efficient JIT strategy.
- gsnedders 13y ago
- mariusz79 13y agoI'm waiting for a JavaScript interpreter written in Javascript. Edit: It's already here :) https://github.com/jterrace/js.js/ https://github.com/jterrace/js.js/
- jokoon 13y agoI hate java, I hate javascript, I hate node.js, so basically, I just leave a comment here, and you can make a conclusion about what I think about all this.
- Osiris 13y agoJust out of curiosity, what are your preferred languages and server environments?
- WoodenChair 13y agoBased on his HN profile, my guess is Python.
- jokoon 13y agoC, C++, Python, Lua
- AsymetricCom 13y agoWhy all the hate but none of the conceptualization?
- jokoon 13y agowhat
- cpeterso 13y agoMozilla has written pdf.js to replace Adobe's PDF plugin and shumway.js to replace Adobe's Flash plugin. When will we see a java.js that replaces Java applets on the web?
- mtdewcmu 13y agoI have a feeling James Gosling choked on his coffee this morning. :)
- ghostdiver 13y agoWhat's the point of doing this, why not just use Mozilla Rhino?
- chc 13y agoRhino is the opposite of this.
- ghostdiver 13y agoIt is the right tool for mixed JS and Java codebase.
- 6ren 13y agoHow hard is it to write a JVM? I'd think it pretty easy, as it's intended to be small and easily portable. You could even write one in Java (and I'm sure it's been done, many times). EDIT e.g. http://igormaznitsa.com/projects/mjvm/index.html http://igormaznitsa.com/projects/mjvm/index.html Of course, doing all the tricky JIT etc of the JVM is a different story...
- diek 13y agoIt depends on what you consider the JVM. If you're just talking about something that can load class files and do some instruction interpretation (like this project) then that's one thing... if you're talking about implementing all of the JNI functions within the JVM standard library (awt, net) along with the concurrency primitives (conforming to the Java memory model?) then that is a significant multi-year, multi-developer project.
- zshprompt 13y agoI made a house out of butter yey!!!!
- tlrobinson 13y agoWhat does Node have to do with it (besides perhaps a little IO)? Isn't it just JavaScript?
- bane 13y agoReally cool hack, and yet I can't help but think that the mile-high software stack between the developer and the CPU continues to grow meaning we're stuck in a perpetual game of filling up spare CPU cycles with nothing in particular. I'm sure I'll see a demo showing off something that barely runs on modern hardware that we were more than capable of running with good performance in 1990. sigh I feel like I'm being such a Debbie-downer even if this is a really cool hack.
- TheZenPsycho 13y agothe differences are in how quickly the software can get written, and where that software can go to be run, and in how many different places. It could be we haven't improved those either, but there's more to life than raw performance you see.
- bane 13y agoI agree, but then again, I remember the days when any given piece of software was ported to a dozen competing home computing platforms with wildly different architectures and operating systems as a matter of course. These days we basically have 2 architectures and 3 or 4 different OSs and that's about it. Looking at lots of "web-scale" technologies, I can't help but think that lots of what we're trying to solve with racks of computers could probably be handled with ease by a single modern machine if the software wasn't so inefficient.
- TheZenPsycho 13y agoYou have a point. But then, what I remember about that software that was ported to all the different architectures was: 1. the software was an order of magnitude or two less complex- in terms of features and platform. That is, there was maybe a dozen different kinds of (highly predictable,testable) home computers instead of a combinatorial infinity of videocards/motherboards/soundcards/operating systems/etc.., plus, the GUI/Evented model is more conceptually difficult for programmers to cope with than straightforward "I own the machine" imperative blocking code. If we want to have guis, we need languages that either abtract away events, or at least provide tools to more easily handle events than C or assembler could provide. Such languages tend to be fairly complex (in implementation)/"inefficient"/garbage collected (since events link to memory/state that must be disposed of eventually,somehow, safely,without segfaulting). Failing that, we need programmers that are smart and capable enough to just plow through the complexity of events in plain C or C++. It's a different caliber of programmer than those who could singlehandedly make simple computer games on an 8-bit home microcomputer. 2. In cases of more complex software, ports were achieved by first designing and implementing a one off virtual machine, then simply porting the virtual machine to the different platforms. See ScummVM, Z-machine, Another World, etc. Surely that threw away some notion of efficiency. You made up for it by implementing the performance sensitive routines inside the VM itself. 3. The inefficiency of software is usually a tradeoff for development speed. To make a virtual platform work consistently across the many different real platforms they must run on, the efficiency of the virtual platform becomes (roughly) a function of ( platform implementors / platform count ) * time. We're only 5 years down the road of this round of serious javascript optimisation. At the end of the day, the curve of that function isn't that different from java, or C or C++ or anything else. those other things just have a huge head start.
- knappador 13y agoIs PyJNIus support coming anytime soon? The ability to use Python to script Java calls into the JS run-time to access Cordova API's on top of Android libraries is really important for developers who have Python, Cython, and Java skills, but find P4A too daunting compared to Cordova. It's only three more layers of nonsense.
- catwell 13y agoFor comparison, here is a recent JVM in Lua: https://cowlark.com/luje/doc/stable/doc/index.wiki https://cowlark.com/luje/doc/stable/doc/index.wiki