Slashdot Mirror


Linux Kernel Running In JavaScript Emulator With Graphics and Network Support

New submitter warmflatsprite writes "It seems that there have been a rash of JavaScript virtual machines running Linux lately (or maybe I just travel in really weird circles). However until now none of them had network support, so they weren't too terribly useful. Sebastian Macke's jor1k project uses asm.js to produce a very fast emulation of the OpenCores OpenRISC processor (or1k) along with a HTML5 canvas framebuffer for graphics support. Recently Ben Burns contributed an emulated OpenCores ethmac ethernet adapter to the project. This sends ethernet frames to a gateway server via websocket where they are switched and/or piped into TAP virtual ethernet adapter. With this you can build whatever kind of network appliance you'd like for the myriad of fast, sandboxed VMs running in your users' browsers. For the live demo all VMs connect to a single private LAN (subnet 10.5.0.0/16). The websocket gateway also NATs traffic from that LAN out to the open Internet."

43 of 177 comments (clear)

  1. Bored with layers of indirection game now. by Joining+Yet+Again · · Score: 2, Insightful

    Can we go back to trying to target for time+space efficiency rather than buzzwords?

  2. Re:So...? by sirber · · Score: 3, Informative

    What does one use this for?

    Self-achievement? Learning? To get chicks?

    --
    Be or ben't
  3. Re:is javascript faster than java? by DragonDru · · Score: 5, Informative
    javascript != java http://en.wikipedia.org/wiki/JavaScript

    The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. The final choice of name caused confusion, giving the impression that the language was a spin-off of the Java programming language, and the choice has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web programming language.

    --
    20 characters max for the password? How will I use my favorite poems as passwords?
  4. Re:So...? by DragonDru · · Score: 3, Interesting

    Infect Windows with Linux Viruses?
    Make firefox faster?
    Simpler BotNet design?

    It was likely a learning project, and is kind of cool. But it is more reason to run NoScript and similar.

    --
    20 characters max for the password? How will I use my favorite poems as passwords?
  5. Yes, network support. by ArbitraryName · · Score: 5, Insightful

    A lack of network support was what was holding back a JavaScript VM running Linux from being useful. No other reason whatsoever.

    1. Re:Yes, network support. by Anonymous Coward · · Score: 4, Funny

      2014 will be the year of the Javascript emulated Linux Desktop

    2. Re:Yes, network support. by Trepidity · · Score: 3, Funny

      Just as long as we get a year of the Linux desktop, I'm willing to settle for it at this point.

  6. Re:So...? by Sockatume · · Score: 4, Funny

    As a component of a Beowulf cluster, obviously.

    --
    No kidding!!! What do you say at this point?
  7. Yeah, but does it run... by sl4shd0rk · · Score: 3, Funny

    ..er, forget it.

    --
    Join the Slashcott! Feb 10 thru Feb 17!
  8. Even runs on iPhone 5s... by OlivierB · · Score: 3, Interesting

    The most incredible thing is the speed at which it runs: 11.5 MIPS.

    My desktop dual-core Xeon W3503@2.40Ghz barely manages 40 MIPS in Chrome.

    The iPhone 5s is crazy fast by most standards

    --
    Artificial intelligence is no match for natural stupidity
    1. Re:Even runs on iPhone 5s... by WilyCoder · · Score: 2

      "my desktop dual core"

      isnt multiple cores irrelevant in the single threaded javascript environment?

    2. Re:Even runs on iPhone 5s... by bensyverson · · Score: 2

      With the introduction of Web Workers, JavaScript is no longer single threaded. It's pretty nice!

    3. Re:Even runs on iPhone 5s... by vux984 · · Score: 2

      Yes, the 5s is incredibly fast. With a Geekbench score of 2523, it's faster than a 2011 Mac Mini (which were not slow machines by any means).

      Which 2011 mac mini are you talking about?

      http://browser.primatelabs.com/geekbench2/search?page=2&q=mac+mini+2011&utf8=%E2%9C%93

      The scores for a 2011 macbook range from 5500 to 9500 depending on the model.

      So... less than half as fast as a low end computer from 2 years ago? Ok... I'll buy that.

      And the 5S is in the same ballpark as a Galaxy Note 3, Sony Xperia Z1, or LG Nexus 5... sure I'll buy that too.

      Smartphones have the general performance of entry level PCs from 5+ years ago? Sounds plausible.

    4. Re:Even runs on iPhone 5s... by BZ · · Score: 2

      It depends.

      Once you're in steady state, and if you don't use workers and don't use the new parallel processing primitives people are proposing for JS, you're right.

      But during JIT warmup, and any time you have to JIT a new function or new codepath it matters because on multicore hardware you can do background compilation.

  9. Re:is javascript faster than java? by SJHillman · · Score: 2

    Comparing Java and JavaScript is like comparing a bicycle and a space shuttle. Sure, they're vaguely related as means of transportation but are otherwise completely unrelated.

  10. Re:is javascript faster than java? by elfprince13 · · Score: 4, Interesting

    JavaScript faster than Java? No. It's not. Not even close. Java has fantastic performance when used correctly. It just happens to be a common intro-course language, so lowest-common-denominator sorts of programmers write a lot of crap code with it. The HotSpot VM JIT is basically magic, and the garbage collection beats out everything else.

  11. Turtles all the way down by barlevg · · Score: 3, Insightful

    Can this Linux kernel run a Javascript VM? If so, can that VM run the Linux kernel? And if so, can that kernel run a Javascript VM? And if so...

  12. Re:So...? by Sloppy · · Score: 5, Funny

    It lets you be a VPS provider, using nothing other than a copy of Chromium. No need for fancy processors and virtualizing instructions, no hypervisors, no containers, whatever.

    Scales beautifully: Got a new customer? Just open another tab!

    --
    As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
  13. Any nerds left on /.? by Anonymous Coward · · Score: 5, Interesting

    It's amazing to me that "tech for the sake of tech" posts like this elicit much the same responses I would expect from a non-nerdy audience. At what point did slashdotters become mostly a group of curmudgeonly old-men who care only about what use can be made of new things and who find NO INTEREST what-so-ever in new and different ideas?

    THIS is why it takes that ex-jock-turned-business man to make money on technology. Somebody who isn't an old-fart slashdotter who "ho-hum"s everything new. This community is SUCH a disappointment.

  14. Re:So...? by David_Hart · · Score: 5, Funny

    What does one use this for?

    The same thing we do every night, Pinky - try to take over the world!

  15. Re:is javascript faster than java? by Anonymous Coward · · Score: 2, Insightful

    Um, Javascript can also have fantastic performance if you "use it correctly". Neither is particularly fantastic if you use like like an average programmer, though.

  16. Re:is javascript faster than java? by goombah99 · · Score: 2

    I'm just learning javascript. I'm puzzled how one makes it "fast". When my highly active programs run in a browser they tend to glitch and halt after a while if they have been doing lots and lots of quick object instantiation and destruction. My guess was this was some memory leak or deferred garbage collection. I see inconsistent results across browsers.

    I'm enjoying learinging at how easy it makes doing graphics in a browser window. however It's a weird mishmash of incomplete grammars and high level commands. For example the lack of a class statement or a defined way to access a superclass is bewildering. It's even less complete that perl objects in many ways. Listing all the keys in a hash (associative array) gets conflated with all the other attributes of the hash, so there's weird kludges like "hasOwnProperty" that smack of being bandaid and afterthoughts. On the other hand it's got things like timed thread execution and some quite high level concept built in as primitives.

    What perplexes me the most is I haven't figured out how to debug it yet. I've been relying on a particular package called "processing.js" which has some very simple graphics. since processing.js acutally re-writes your javascript at run time, the messages in the browser console log are worthless. they don't even tell you the line number where the error occurs most of the time. The other debugging problem Ihave is that often the javascript one is writing only can work in the context of a web page (for example to play loaded sounds). so I don't see how one runs or debugs this outside of a browser. I don't get what the IDE's offer. I'm a noob so give me a clue not heckling please.

    Anyone have any advice on how to debug in java, especially when using processing.js.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  17. First post! by Fwipp · · Score: 4, Interesting

    From my OpenRISC ORK Javascript Emulator Running With Network Support

    i.imgur.com/zJPsjCT.png

    1. Re:First post! by BaronAaron · · Score: 2

      Hope you realized you just sent your Slashdot password through some dude's hacked together relay server in, most likely, clear text... Also there are a bunch of other Slashdotters on the same virtual subnet with full root access to theirs, yours, and everyone else's virtual machine on that very subnet.

      Very cool post, but you may want to change your password now.

      and ...

      Just don't do any online banking that way. ;-)

  18. Re:So...? by mlts · · Score: 5, Interesting

    I wonder how useful it would be for security sensitive applications. For example, even though it sounds goofy to run a Web browser in a Linux kernel running in a window, the difficulity for malware to get out of rings of context (including multiple instruction sets) would be enormous. Not impossible, but highly unlikely.

    Something like this would provide a decent defense against browser-based (or browser add-ons) attacks (which is a significant vector for malware these days.)

  19. Re:So...? by Anonymous Coward · · Score: 2, Informative

    All we need now is JS acceleration built in to cpus.

    Yo dawg, I heard you like VMs so..

  20. Re:is javascript faster than java? by Nerdfest · · Score: 2

    Someone here had a sig that was "Java is to Javascript as Car is to Carpet".

  21. Re:is javascript faster than java? by Immerman · · Score: 2

    Lots of small quick memory allocations/releases is generally a performance killer regardless of language or environment - if you use a garbage collecting environment it tends to be even worse, but regardless you're asking a memory manager that has to be able to deal with memory requests of all sorts of sizes and use-cases, to deal with an extreme special case that demands near-maximum amount of effort to mitigate memory fragmentation. In almost all cases your performance and stability will increase substantially if you instead allocate a sufficiently large pool of objects and manage their usage yourself.

    Here's hoping someone can suggest a decent Java debugger - I abandoned it after a while in part because of the lack of something I would consider only slightly less vital than the compiler itself. Of course that would be of absolutely no use to somebody programming in the unrelated Javascript language.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
  22. Re:is javascript faster than java? by erikkemperman · · Score: 3, Interesting

    JavaScript != Java indeed. I'm still amazed at the silliness of the choice.

    I've actually seen a newbie developer paste a snippet of one into the other... Finally I had an occasion to use the phrase "that's not even wrong" in an actual conversation.

    The dev didn't last at our company.

    --
    Gosh, thanks. That must be why the other ships call me Meatfucker -- GCU Grey Area (Eccentric)
  23. Re:is javascript faster than java? by jones_supa · · Score: 3, Insightful

    javascript != java

    But you can still ask the question whether JavaScript is faster than Java.

  24. Re:is javascript faster than java? by SJHillman · · Score: 2

    You can ask a lot of questions, but that doesn't mean they're good questions.

  25. Re:is javascript faster than java? by GodWasAnAlien · · Score: 2

    > Comparing Java and JavaScript is like comparing a bicycle and a space shuttle.

    which one is the space shuttle?

    Your comparison comparison is like comparing monkeys with the Eiffel tower.

  26. Re:So...? by s-macke · · Score: 5, Interesting

    A year ago, when I started the project it was simply interest in learning Javascript. I was fascinated by the emulator from Fabrice Bellard http://www.bellard.org/jslinux/
    I am a programmer focused on simulations/emulations and performance. I was also interested in learning the internals of how a computer nowadays works. The x86 CPU is way to compilcated. You lose the clear sight for stupid details like the A20 gate. The OpenRISC project is perfect. It is a CPU with a very easy and clear CPU. Nothing historic. It has even some similarities with byte code, which makes it very fast if you emulate it properly. I optimized especially for running Linux violating the specification a bit.
    The whole CPU with MMU fits in around 1000 lines of code. During that day I never expected to get that far. Now with all three cores and devices it needs around 7000 lines of code.

    I have a list of useful things you can do with it:
    1. Use it as an education system of the Linux system or other tools. For example you could write a git tutorial with live examples.
    2. This emulator provides an alternative way to port old software to run on modern systems. In direct comparison to the project Emscripten it is slow, but the porting could be much easier. For terminal applications probably no porting is neccessary at all (e. g. Frotz).
    3. The emulated OpenRISC CPU is very easy and contains around 1000 lines of code. So it is the perfect example to learn how emulation works.
    4. With network support it allows you to access other computers within the Web Browser providing ready to use tools. (Even an encrypted chat is possible if you run the sshd daemon)
    5. Use it as a speedtest for Javascript engines.
    6. It is an advertisement for the OpenRISC project.

    You can also read the motivation of Ben Burns in his Blog: http://www.benjamincburns.com/2013/11/10/jor1k-ethmac-support.html
    And I have to admit that I did the wayland support last time only to get some news. :)

  27. Re:So...? by Will.Woodhull · · Score: 2

    Idunno. Can you even call them runtime errors in a setup like this?

    This is using a Linux VM, emulated in Javascript, in a sandbox, inside your browser. I don't think the thing could possibly run. Or even walk. I think the fastest it could go would be a slow crawl.

    --
    Will
  28. Re:So...? by DocSavage64109 · · Score: 2

    I'm sure they'd be all over some guy because he managed to run a VM in a web browser.

  29. Re:is javascript faster than java? by narcc · · Score: 3, Interesting

    I'm puzzled how one makes it "fast". When my highly active programs run in a browser they tend to glitch and halt after a while if they have been doing lots and lots of quick object instantiation and destruction.

    You've almost figured it out!

    Recycle your objects. Enjoy instant performance improvements. (While this is not just true for JavaScript, it's obviously the advice you need.)

    Oh, and try learning the language. It's not like Java and C#. If you try to treat it that way, you'll end up writing crap. You can break yourself out of that easily enough by working through The Little Schemer in JS instead of Scheme.

  30. Re:is javascript faster than java? by DdJ · · Score: 2

    Depends on where the heavy lifting is.

    If you've got a JavaScript that implements web SQL and web GL, well, those are implemented in low-level languages and you're just going to call them from JavaScript. If that happens to be where the bulk of the work is for a given program, you might get better performance out of JavaScript than Java.

    (The devil is in the details. I do not know the details in this specific case.)

  31. recylcing objects for speed and memory savings by goombah99 · · Score: 2

    I'm puzzled how one makes it "fast". When my highly active programs run in a browser they tend to glitch and halt after a while if they have been doing lots and lots of quick object instantiation and destruction.

    You've almost figured it out!

    Recycle your objects. Enjoy instant performance improvements. (While this is not just true for JavaScript, it's obviously the advice you need.)

    Oh, and try learning the language. It's not like Java and C#. If you try to treat it that way, you'll end up writing crap. You can break yourself out of that easily enough by working through The Little Schemer in JS instead of Scheme.

    How one does that is not obvious to me. let's take an example. Suppose I create a function like this:

    var recylceObj = function( oldObj, newAttitributes) {
              for (var i in newAtritutes) {
                                oldObj[i] = newAttributes[i];
              };
    }

    var foo = recycleObj( oldObj, { x:1, y:2, z:3} );

    so superficially I just reused an old memory allocated object oldObj by overwriting it's attributes with new ones. But wait, to do that I had to instantiate the temporary hash { x:1, y:2, z:3} to transfer in those attributes. Which is memory allocation and object creation. It would in fact be simpler to write:

    var foo = { x:1, y:2, z:3};
    foo.prototype = oldObj.prototype;

    I would in fact think this latter way would be more efficient in both speed and memory. So How do I save anything by recylcing?

    is there a better way to recycle? what am I missing

    --
    Some drink at the fountain of knowledge. Others just gargle.
  32. Re:is javascript faster than java? by gl4ss · · Score: 2

    it can run anything, inside it's browser vm it's quite "complete" computing platform so why not.

    just not anything in parallel ;) so you have to be sneaky...

    and java can run in parallel and is superior in just about every way but due to politics of days past they integrated javascript and not java as the language the browser has facilities to run.

    on both of them it's what you code and how that make them choke, try to do something that does things slowly and it will do them slowly.

    using a websocket is kind of a cheat though, with the same technique(and simpler) you could launch nuclear missiles from javascript in browser. sure it would depend on a gateway to actually launch them....

    --
    world was created 5 seconds before this post as it is.
  33. Re:Rich applications by ArsonSmith · · Score: 2

    I've found it to be faster than running Linux directly on hardware under certain circumstances.

    --
    Paying taxes to buy civilization is like paying a hooker to buy love.
  34. Re:So...? by Anonymous Coward · · Score: 2, Interesting

    A nerd rides up to his friend on a shiny new bike.
    His friend asks, "where'd you get the bicycle?"
    The first nerd relates, "a beautiful woman came up to me, dropped the bike to the ground, tore off her clothes and said "take anything you want!", so I took the bike."
    His friend insightfully notes, "yeah, the clothes probably wouldn't fit you."

  35. need help with WINE by locopuyo · · Score: 2

    I am having trouble setting up WINE with this. Can someone help me setup WINE so I can play Crisis on my Nexus?

  36. Re:So...? by nemesisrocks · · Score: 2

    What does one use this for?

    To get chicks?

    Unlikely -- doesn't work in Internet Explorer.