Slashdot Mirror


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."

30 of 234 comments (clear)

  1. Javaception by embolalia · · Score: 5, Funny

    So you could write a browser that supports JavaScript in Java, and then run the browser in itself?

    1. Re:Javaception by linuxgeek64 · · Score: 5, Informative

      It doesn't implement that much of the standard JVM.

    2. Re:Javaception by DigiShaman · · Score: 4, Funny

      Ouroboros?

      --
      Life is not for the lazy.
    3. Re:Javaception by afabbro · · Score: 4, Funny

      10 Write Browser in Java

      20 Write Javascript engine in Browser

      30 GOTO 10

      --
      Advice: on VPS providers
    4. Re:Javaception by game+kid · · Score: 4, Funny

      Now we just have to do all of that in a Minecraft map so the CPU collapses under its own virtual weight!

      --
      You can hold down the "B" button for continuous firing.
    5. Re:Javaception by Joce640k · · Score: 4, Funny

      Ummmm, Java != Javascript.

      I thought that bit of confusion was cleared up by now. I was wrong.

      --
      No sig today...
    6. Re:Javaception by TheInternetGuy · · Score: 5, Funny

      Think before posting please.

      Seriously, if we are going to put that kind of requirement on posters, I will probably have to cancel my slash dot account

      --
      If my comment didn't sound as good in your head as it did in mine, then I guess we all know who's to blame
    7. Re:Javaception by sydneyfong · · Score: 4, Funny

      but it wouldn't be "virtually impossible"

      Exactly. It'd literally be virtually possible if you control the whole virtual machine...

      --
      Don't quote me on this.
    8. Re:Javaception by alexhs · · Score: 5, Interesting

      So you could [...] run the browser in itself?

      Old news. Try chrome://browser/content/browser.xul in Firefox (doesn't seem to work as a clickable link, though).
      See here for more options.

      --
      I have discovered a truly marvelous proof of killer sig, which this margin is too narrow to contain.
    9. Re:Javaception by StripedCow · · Score: 4, Funny

      This is modded "funny", but actually this would be very useful. Because you could send the browser along with your HTML and be done at once with all browser-compatibility problems. Plus you could make browsers supporting other languages (e.g., Python, Haskell, you name it).

      Of course javascript would not be the appropriate target-language for this (I guess, due to efficiency issues), but the idea in itself is very interesting. A better target-language would be closer to the machine (no closures, and no garbage collection); the NaCl project might actually be a better candidate.

      I'm betting that somewhere, somebody is already writing a browser in NaCl.

      --
      If Pandora's box is destined to be opened, *I* want to be the one to open it.
    10. Re:Javaception by Zortrium · · Score: 5, Interesting

      Warning: shameless self-promotion ahead: I've also written my own JVM interpreter in JavaScript, which supports a substantial amount (perhaps most?) of the standard JVM, including threading, synchronization, reflection, rudimentary I/O, and most of the standard library classes (e.g., HashMap and Random). There's a lot of hackery involved but it's totally doable.

      Also, mine runs on Rhino, which is itself written in Java, so it's C (JVM) running Java (Rhino) running JavaScript (JSava, my interpreter) running Java (the user program). How's that for meta-execution?

  2. Anything which can be written in JavaScript ... by Musically_ut · · Score: 5, Funny

    ... will be eventually written in JavaScript. ~ Atwood's Law (circa 2007)

    --
    Never trust a spiritual leader who cannot dance -- Mr. Miyagi
  3. yo dawg by Anonymous Coward · · Score: 4, Funny

    So we heard you like java...

  4. Hey Bro... by bennomatic · · Score: 4, Funny

    ...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?
    1. Re:Hey Bro... by Mitchell314 · · Score: 5, Funny

      Of course there's a difference. Java is defined as the language that runs on top of javascript. This is simple, it's just a compiled language that runs atop of an . . . interpreted . . . of an interpreted . . . it's a compiled . . . it's a compiled language that runs on an interpreted . . . okay guys, really, what the fuck? I think I just heard the sound of part of the universe and a good chunk of logic spontaneously imploding. I'm going to go cry now, and thanks to these dipshits my tears will probably fall sideways upwards now.

      --
      I read TFA and all I got was this lousy cookie
  5. Re:Not A New Concept by bucky0 · · Score: 5, Interesting

    I feel like that sort of bootstrapping is normal. GCC's written in C, afterall.

    --

    -Bucky
  6. DOM-Interface for byte code by maweki · · Score: 5, Interesting

    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."

    1. Re:DOM-Interface for byte code by devent · · Score: 4, Insightful

      Yes, would make sense, wouldn't it? Instead that every browser have to interpret the slow JS language (yes, JS language is slow to interpret, because of the design choices. Just watch some of Doug Crockford videos), we could all just agree on a byte code standard like the Java byte code standard.

      Then you could develop web applications in your choice of language and not just in JS. On the server you upload just the byte code, like the compiled Java source code (.class).

      For example, you could develop in Ruby, Python or Java, and compile the code to the byte code for browsers. Then you deploy the byte code on the server.

      But the web-developers are so stubborn with their JS language, I don't know why.

      --
      http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
    2. Re:DOM-Interface for byte code by martin-boundary · · Score: 4, Interesting

      I'd rather have source code than byte code. The web was built on visible code like HTML. Do you think it would have exploded if people couldn't look at the source to figure out how some neat web page was written?

  7. Re:This is nonsense. by afabbro · · Score: 4, Insightful

    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
  8. Yo dawg, I heard you like bloat by wye43 · · Score: 4, Funny

    ... so I've put bloat in bloat, so you can wait while you wait.

  9. Really? by aglider · · Score: 5, Informative

    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.
  10. This is completely unnecessary. by DamnStupidElf · · Score: 5, Funny

    Fabrice Ballard already wrote an x86 emulator in javascript. Just install the standard x86 JVM inside of that and you're good to go.

    1. Re:This is completely unnecessary. by jenic · · Score: 4, Funny

      Fabrice Ballard already wrote an x86 emulator in javascript. Just install the standard x86 JVM inside of that and you're good to go.

      Yes, that's why this is completely unnecessary.

  11. Why now? by thegarbz · · Score: 4, Interesting

    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?

    1. Re:Why now? by sydneyfong · · Score: 4, Informative

      Javascript speeds have increased greatly due to the reheated competition by browser vendors (it wasn't too long ago that the only thing really existed was IE6). Thus in the past 10 years, nobody in their right mind would expect a x86 emulator, a JVM etc. to be implementable in Javascript at tolerable speed.

      In fact, few expect these "discoveries" to happen so soon and so quickly, but since somebody proved it possible to do crazy things on Javascript, everyone with too much time on their hands are jumping on board and having fun with these projects.

      --
      Don't quote me on this.
  12. Re:This is nonsense. by deniable · · Score: 4, Funny

    More like writing a Python interpreter in Perl. It'll work, but you'll feel a little dirty afterwards.

  13. Re:Not A New Concept by TheRaven64 · · Score: 4, Informative

    Most compilers work like that. The Java compiler is written in Java (as you discover when it crashes and you get a Java stack trace). Smalltalk was written in Smalltalk and even modern Smalltalk implementations like Pharo are written in Smalltalk. The typical trick is to write a small compiler for a subset of the language in another language and then use it to compile the rest of the compiler. For example, the core of the Squeak VM is written in a subset of Smalltalk that is fairly easy to translate to C. This is then translated to C and compiled with the target system's C compiler. You then have enough of the VM running for it to load the rest. Early Pascal compilers did the same. In the '70s, having the compiler written in the language was considered a test of whether something was a 'real' language (since then we've learned that languages that are good for writing compilers are not necessarily good for other things. Well, some of us have...)

    --
    I am TheRaven on Soylent News
  14. Re:Not A New Concept by Just+Some+Guy · · Score: 4, Interesting

    The JOVIAL J4 compiler was itself written in JOVIAL J4.

    Want something really mind-blowing? PyPy is a Python interpreter written in Python. It includes a tracing JIT compiler to optimize hotspots as it runs to get about 5 times faster than the native C Python. I've used it and I still can't quite believe it.

    --
    Dewey, what part of this looks like authorities should be involved?
  15. Re:This is nonsense. by Oligonicella · · Score: 4, Funny

    That's a byproduct of Perl. What you write has nothing to do with it.