Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Java to asm.js

Tags:

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!

like image 696
Sebastien Diot Avatar asked Aug 01 '13 11:08

Sebastien Diot


2 Answers

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

like image 152
brettw Avatar answered Oct 09 '22 22:10

brettw


As of 2020, you probably want to transpile to web assembly instead of asm.js. These tools are currently available:

  • Bytecoder
  • JWebAssembly (no garbage collection with current WASM implementation)
  • TeaVM (support for WASM is experimental)
like image 32
Marco Lavagnino Avatar answered Oct 09 '22 22:10

Marco Lavagnino