Reputation: 7359
asm.js is in coming. Now there is even rumors of Chrome soon supporting it fully.
But so far it has been used to compile C/C++ source into JavaScript that would run with near native speed (depends on how you define near native ...)
I have been planning to use GWT to turn my Java code to JavaScript, but now I was wondering if there is currently an existing path/procedure to compile plain Java source code to ASM.JS, and what would that be?
One more reason why one might want that: Java-to-ASM.js might very well run faster then Java-to-Dalvik on some Android phone!
Upvotes: 21
Views: 7588
Reputation: 11114
asm.js (currently) is designed as a target for languages that manually manage memory allocation and release -- like C/C++. It cannot currently handle languages with garbage collection semantics, silly as that may seem given that it is JavaScript which is a garbage collected runtime.
If you really wanted to go the round way about, pass the Java code through j2c and then pass that C++ output through emscripten which will compile to asm.js.
Another possibility would be to pass the Java code through the LLVM compiler using the VMKit and pass that through the emscripten asm.js llvm backend...
Upvotes: 10
Reputation: 1229
As of 2020, you probably want to transpile to web assembly instead of asm.js. These tools are currently available:
Upvotes: 3
Reputation: 1876
Not only the garbage collecting but the Java VM is written in C/C++, asm.js comments on the possibility of compiling "entire VMs from C/C++ to JavaScript, and implement JavaScript-emitting JITs.".
Right now (June 2015) this possibility is far from real, so stick to GWT (I wouldn´t recommend it) if you feel like it.
Upvotes: 1