JavaScript JVM Runs Java
mikejuk writes "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. 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. Notice this isn't a Java to JavaScript translator but a real JVM that runs byte code. This means it could run any language that compiles to byte code." Bonus: on Ventura's website is a set of visual notes from a talk he gave titled "My Language Is Better Than Yours."
So you could write a browser that supports JavaScript in Java, and then run the browser in itself?
then I was like :D
Sounds lame for about 2 seconds, then it hits you... run software in a browser with no plugins (albeit at a very low rate of speed...)
... will be eventually written in JavaScript. ~ Atwood's Law (circa 2007)
Never trust a spiritual leader who cannot dance -- Mr. Miyagi
Forty years ago, a major software system for operating unmanned space satellites for the U.S. Air Force was written in a language called JOVIAL J4. The JOVIAL J4 compiler was itself written in JOVIAL J4.
Originally intended for a lifetime of 10-15 years, the system was actually in use for 20 years.
So we heard you like java...
...I heard you like Java in your script so I wrote you a JVM in Javascript so you can run Java while you're scripting.
Joking aside, this is not going to help the amount of confusion people have with regards to Java not being the same as Javascript *at all*.
The CB App. What's your 20?
For years I've been saying that we need a DOM-Interface for byte code in Browsers and everytime I get downvoted. Nice to see people exploring in these directions now.
"we do need DOM-Bindings for Bytecode now more than ever. It would be so great to write code in a language of my choice and compile it to Browser-Bytecode with DOM-Bindings. This would make it possible to deliver more proprietary code without making browser-plugins or something similar."
"What we really need are DOM-Bindings for Bytecode. So you can use every language you want that is capable of compiling to bytecode and send it to a browser. This would make it easier for the developer and bytecode is easier and faster for the browser to execute."
Javascript != Java. "Javascript" is just a naming rip-off. So what's the big deal?
It's like writing a C compiler in Bourne shell. The point is less about the name than about the complexity and absurdity.
Advice: on VPS providers
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.
I think it would have been easier to build a VM into a browser but I doubt it would have gotten this much attention. Still. It is a cool project.
Having to work for a living is the root of all evil.
created by Java which was created with Java-script. Have the planets aligned?
by TheSpoom (715771) Uncaring Linux user here. I have nothing to add to this but please continue. *munches popcorn*
Names have nothing to do with it. They could have just as well written their JVM in Python, Perl or PHP - except that none of those languages have undergone ten years of browser vendors fighting head to head to shave off another few microseconds on benchmarks, so their interpreters would be too slow to run an effective virtual machine.
The C# compiler was written in C++.
For now it is, sure.
-1 overrated isn't the same thing as "I disagree".
I doubt that Javascript accelerators are good at optimizing this, but it's not fundamentally impossible to run it close to JVM speeds. JS is a language that in nutshell is self modifying code, so it can act as a translational layer which in the end enables running Java in a Javascript engine (interpreter,VM or whatever). It could be compared to Dart which also runs another type of language in JS.
{yo,sup} dawg, I heard you like Java, so I put an Java Virtual Machine on top of your your Java, so you can compile Javascript while running the JVM.
I'd love to see it done in PHP. Anything to avoid running a Tomcat installation would be useful.
I wrote a runtime in a scripting language so you can code while you script and I can debug while I debug.
Umm... seriously, comparing JS to the Bourne Shell is a bit unfair.
... so I've put bloat in bloat, so you can wait while you wait.
This
This means it could run any language that compiles to byte code.
shoud read as
This means it could run any language that compiles to Java byte code.
Sent as ripples into the electromagnetic field. No single photon has been harmed in the process.
JVM is a run time environment not a compiler (although the environment includes a JIT compiler).
Also I think the point was javascript is seen as a less powerful language
null
Sun already made a JVM written in Java, so it can run java. see Maxine
... you understand that a computer language, is a mapping of human readable symbols -> cpu instructions, either direct or indirect. If the mapping results in a set of cpu instructions that implements another language, you get another language.
It's not rocket science people, its just math. Wait, maybe it is rocket science.
What's that I hear? Steve jobs spinning in his grave? He can't be happy looking down at his consumers and them having some choices in what they want to run on "his" hardware. Oh well...
Fabrice Ballard already wrote an x86 emulator in javascript. Just install the standard x86 JVM inside of that and you're good to go.
... justifying tera-hertz processors!
I can see a use case: Once we have a mostly complete JVM interpreter with satisfactory performance written in Javascript, we can use any language that supports the JVM instead of Javascript.
(+1, Disagree)
To the bourne shell
Legit question from a programming novice: Why are all these discoveries coming up now? Hasn't JavaScript been around for 10+ years now? Is there something that has changed recently that makes people pursue these strange coding goals?
It's like writing a C compiler in Bourne shell. The point is less about the name than about the complexity and absurdity.
Isn't it more like writing a C compiler in C-shell - at least name-wise :-)
What a gigantic waste of time.
But not surprise, since javaScript can implement a Y combinator (a Y-combinator is a function that operates other functions to enables recursion when it can't refer to itself from within itself.)
Ok, that's about the most amusing hack since someone wrote a fully working web server in postscript: http://www.pugo.org:8080/
(Still think the postscript web server leads the list of odd hacks)
"a Java Virtual Machine JVM written in JavaScript"
A Java Virtual Machine Java Virtual Machine written in JavaScript..... really?
A JVM JVM written in JS?
Right, I need to go and try to rememeber by Personal Identification PIN Number so that I can use the Automated Teller ATM Machine.
More like writing a Python interpreter in Perl. It'll work, but you'll feel a little dirty afterwards.
You have bunch of developers who are bored and want some attention - that's all.
After years of designing and coding, everything starts to look the same: problems you're solving, technology, techniques, languages .... it's all more of the same. So, what does one do? Crazy shit like this for the sake of just doing it.
Also I think the point was javascript is seen as a less powerful language
It's Turing-complete. You can implement any language in it. That's not what people mean when they say it's less powerful, they mean some combination of:
The fact that you can run a slow JVM written in JavaScript doesn't address any of these.
I am TheRaven on Soylent News
"Computers languages are how we tell computers what to do"
That's so in the past.
Nowadays, computer languages nowadays are (minus some exceptions) all about telling people what computers do.
Let me introduce you to Jetty.
That's not what people mean when they say it's less powerful, they mean some combination of: Implementing the same algorithm in JavaScript and another language requires a more complex JavaScript compiler to reach the same speed.
That or reaching the same speed turns out to be halting-complete due to the complexities of trying to squeeze static typed performance out of a dynamic typed language.
It lacks access to operating system features via standard APIs (e.g. no threads)
Exactly. Without threads, how is a JavaScript JVM supposed to implement JVM threads? And without WebGL (which at least one major browser maker refuses to implement for security reasons), how is Java 3D implemented?
Say I have an existing application, and it is cleanly separated into logic and presentation. How do I automatically translate the source code of the application's logic part into JavaScript so that I can write a new DOM-based presentation for it?
I think aglider's point is that there exist notable bytecodes other than JVM bytecode, such as Microsoft CIL, UCSD p-code, Infocom Z-code, SCUMM bytecode, LLVM bitcode (which is already handled by Emscripten), and more.
Provided JavaScript is Turing-complete (and there are very few useful languages that aren't)
No language is Turing-complete because no machine has unbounded memory. A linear bounded automaton (LBA-complete) is a better model of computers that exist in the physical world.
Note the keyword here is possible. Desirable and practical are totally different matters altogether.
Especially because even once you've ignored speed, neither Turing completeness nor LBA completeness makes any guarantee about I/O capability.
But does it work in IE or does it need browser detection and a bunch of conditionals before it will play nice? Seriously, JS is tolerable when you write it for a "compatible" browser, but once you throw IE into the mix it turns into the code equivalent of a water boarding session
So does this mean instead of giving the nasty java warning pop-up when running an unsigned applet using jvm, I can do driveby using javascript that implements a jvm...? Oh that sounds great....
Now all we need is a version of Flash that runs under Java and we can reach a new low for mobile speed and power consumption!
That's the stupidest thing I ever heard of. Write a vm for a compiled language in an interpreted, non-standard piece of crap. Great job, NOT!
Aw... THIS IS SLASHDOT, for God's shake!
What are you waiting for, guys?
IN SOVIET RUSIA, JAVASCRIPT RUNS YOU!
Crap, someone had to say it....
doesn't mean that it should be done. I'm just saying.
I have excellent Karma and I am not afraid to Troll it.
It's also seen as less powerful because it's more confusing (dynamically types and the wacky cross-browser implementations being the main sources of this in my experience). Some of that is also legacy leftover of javascript as a scripting language being conflated with "that script you use to do rollovers" in the ie-netscape days.
As you say, javascript as a language is plenty powerful, see what can be done in unity and flex for examples.
That's a byproduct of Perl. What you write has nothing to do with it.
Sad day - your comment is the only one that comes up in a browser find for 'Turing' on my default page view and that's because I have my friends scoring +4...
My God, it's Full of Source!
OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
Go on, keep trying to correct the troll... I'll give you a hint: It will only make you more mad and the troll will be even more successful.
No, it's consonant, you idiot.
PyPy implements Python in Python. Apparently it's a great way to test new features before undertaking an implementation in the C interpreter.
OK bear with me. I'm old school and do a lot of embedded development. I do pretty much everything in C or C++.
I am not even slightly in tune with the kitchen sink mindset and all technologies you internet-everything developer types use. I've always thought you guys do way too much layering and usually end up making some heavyweight, overcomplex and slow monster with all sorts of dependencies on stuff like web servers and databases to just to do something I could do in a few lines of native C++.
A JVM based on Javascript seems a perfect example of extreme bloat to me. I'm genuinely interested in whats the benefit of this approach that can outweigh its no doubt massive resource usage and relatively sucky performance, even compared to native JVM?
This discussion of compilers written in their own language makes me think of the Ken Thompson Hack, wherein the hacked compiler forever propagates malicious content that is not contained in the source code.
"This hack can propagate transparently across languages and language generations. In the case of cross compilers it can leap across whole architectures."
27 years later it's still the most devious backdoor I've ever heard of.
It's worth noting that Microsoft Research had the exact same idea back in 2007 with Volta, which was an implemention of the .NET CLR in Javascript so you could take the same .NET compiled assembly files that you run on your PC and run them without any plugins in a Javascript-capable browser.
They eventually ditched the idea in favor of a different approach with Script#, which is a C# compiler that compiles to Javascript instead of .NET bytecode; similar in concept to Google' GWT Java source to Javascript compiler.
NO CARRIER
Don't we "program" our brains in English using English or whatever is your native language with no initial bootstrap compiler? Yes, I know linguists have studied how much of language ability is hardwired into our brains.
Go on, keep trying to correct the troll... I'll give you a hint: It will only make you more mad and the troll will be even more successful.
Actually, given how long that troll has been around- everyone should be clued in by now- I strongly suspect that the "oblivious" corrections made by other *anonymous* posters are now part of the troll itself, designed to attract comments like yours.
:-)
Of course, maybe *your* comment was itself part of the troll designed to get a response from people like me... but I doubt it.
Instead of slashdotting the web site where the action is, linking to the web site that broke the story before Slashdot did?
I knew I should have held on to my hot applet related domain name.
Just when I'd given up on Applets ever making a comeback, here we are.
God damn Microsoft's evilness and Sun's incompetence for destroying Java applets in the browser.
Imagine if you dare, a beautiful world where web GUI design doesn't include worrying about how style sheets and javascript work on dozens of different version of dozens of different browsers.
A magical world where you can get direct access to the screen pixel data and implement everything from widgets to real time vector and 3D renderers, and know that it will appear consistently for all your users. A world where Flash is totally unnecessary.
In all seriousness, web programming is for chumps.
My old client just asked me if I was interested in making some changes to the web application I wrote them. I'm busy, but I told them what desirable experience they would want for my replacement...
Java, GWT, JEE, EJB, JBoss Seam, JSF, Facelets, Richfaces, HTML, JavaScript, AJAX, JPA, JPQL, EL, Oracle SQL, XML, CSS (targeting desktop and mobile devices)
If applets had of come to dominate the web, that list might instead be...
Java, JEE, EJB, Oracel SQL.
C compilers have been implemented in C before. Nothing new here.
No, it's consonant, you idiot.
Careful, you'll put the troll in a vowel mood!
A better use case is for pointing out the unsatisfiability of apple's developer restrictions, regarding interpreted languages/emulation.
This javascript jvm would allow you to run "anything you want" inside the stock idevice browser, since said browser needs to support javascript for a huge number of reasons.
It wouldn't be as good as a native arch jvm, or even better, native arch software, but the abstraction capability would render *all* modern browsers into a nonconforming state with the developer agreement. Apple would have to either forbid modern browsers, or remove the restriction.
So, is Oracle gonna sue this time?
Javascript has nothing to do with Java, or the other way around. The javascript language is implemented by browswers that are often written in java, but it doesn't have to be. It could just as easily be implemented elsewhere.
From wikipedia "JavaScript uses syntax influenced by that of C. JavaScript copies many names and naming conventions from Java, but the two languages are otherwise unrelated and have very different semantics."
This isn't insanity, it just is.
Actually.. I'm getting quite sick of this one.(including the inevitable 'correction threads').It's clearly not having the effect i imagine it's supposed to. It's not even interesting or funny..
My students implemented this as a class project: http://plasma.cs.umass.edu/emery/grad-systems-project-1. One month, 100% of the bytecodes.
It seems it's based on GWT: http://jainja.thenesis.org