WebAssembly (wasm) Target Platform: Difference between revisions

From JogampWiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 32: Line 32:
= Java Support =
= Java Support =
Java bytecode compiler to wasm including some ''runtime envelop''  
Java bytecode compiler to wasm including some ''runtime envelop''  
* [https://github.com/google/j2cl/blob/master/docs/getting-started-j2wasm.md J2wasm] within [https://github.com/google/j2cl J2CL] emits naïve Wasm using the text format and it relies on Binaryen toolchain to assemble, link, and optimize
** [https://www.wingolog.org/pub/epfl-wasm-gc-feb-2024-slides.pdf 2024 Slides]
* [https://github.com/konsoletyper/teavm TeaVM] [https://teavm.org/docs/intro/overview.html overview]
* [https://github.com/konsoletyper/teavm TeaVM] [https://teavm.org/docs/intro/overview.html overview]
* [https://github.com/i-net-software/JWebAssembly JWebAssembly] [https://github.com/i-net-software/JWebAssembly/wiki doc]
* [https://github.com/i-net-software/JWebAssembly JWebAssembly] [https://github.com/i-net-software/JWebAssembly/wiki doc]
Line 37: Line 39:


Further interesting bits & pieces
Further interesting bits & pieces
** [https://openjdk.org/jeps/457 JEP 457: Class-File API ]
* [https://openjdk.org/jeps/457 JEP 457: Class-File API ]
** [https://openjdk.org/projects/babylon/articles/linq Babylon]
* [https://openjdk.org/projects/babylon/articles/linq Babylon]


== GraalVM ==
GraalVM experimentally hosts wasm only,  
GraalVM experimentally hosts wasm only,  
but is not producing a wasm target for the wasm (browser) runtime.
but is not producing a wasm target for the wasm (browser) runtime.
* [https://www.graalvm.org/latest/reference-manual/wasm/ GraalVM + wasm]
* [https://www.graalvm.org/latest/reference-manual/wasm/ GraalVM + wasm]
** with the help of emscripten
** with the help of emscripten
** [https://www.graalvm.org/22.0/reference-manual/native-image/JNI/ GraalVM + JNI]
** [https://www.graalvm.org/22.0/reference-manual/native-image/JNI/ GraalVM + JNI]
[https://github.com/oracle/graal/issues/3391 Request for enhancement about wasm target in GraalVM].


= Java Browser Outlook =
= Java Browser Outlook =

Latest revision as of 07:35, 4 April 2024

Extracted from Feature & Objectives.

Overview

See Bug 1506 describing this feature.

Since Java Applets are not more supported within browser or by OpenJDK for years, it may seems feasible to evaluate the WebAssembly target running within e.g. web browser nowadays.

An initial evaluation on small C++ projects using the emscripten front-end for LLVM's clang++ to wasm compiler, which supports many ported system libraries like SDL, OpenGL, .. has been undertaken successfully with variable results.

The wasm target is comparable to Java bytecode but the wasm virtual machine is not as performant, efficient or flexible as actual native code. The lack of hassle free native threads and native high-performance may remind one of the first JVM steps. The wasm code runs within a virtual machine like the JVM and additionally lacks of native binding capabilities.

Some limitations may be overcome, others are likely by design as it usually runs on the same browser virtual machine as the JavaScript companion. Compromises must be made on shared memory and native threads, cached non-local file I/O and socket communication - while other native features will simply never work, e.g. operating system ioctl-calls, etc.

Opening the door for any language to be compiled to a platform independent intermediate representation (IR) like Java’s bytecode suitable for a versatile runtime environment including its virtual machine is surely still desirable.

Initial C++/wasm Evaluation

Our little gfxbox2 games compiled to wasm run about 40-60% slower within a browser than in native code, depending on coding strategy of our graphics (pixelmap vs SDL/OpenGL primitives).

The used emscripten frontend allowed us to use memory-growth, envelop files used in the wasm file, add cheap stack-overflow cockies and nullptr writes and so forth. Utilization of OpenGL ES via SDL2 was a breeze.

The underlying LLVM compiler did an excellent job and overall, the transition was easy and almost involved no code changes but dropping native thread (std::thread) usage.

The overall program structure had to be adapted to align to the single-thread main-loop workflow and specific emscripten-javascript hooks added to allow seamless interaction. All in all, nothing to be too afraid of and depending on the class of applications to be ported to the browser these days, a feasible procedure.

Java Support

Java bytecode compiler to wasm including some runtime envelop

Further interesting bits & pieces

GraalVM

GraalVM experimentally hosts wasm only, but is not producing a wasm target for the wasm (browser) runtime.

Request for enhancement about wasm target in GraalVM.

Java Browser Outlook

So far the only question arises why reinventing the wheel once again? Dropping utilization of a well working JVM for the web had no technical reasoning.

However, in case no suitable wasm target for the Java bytecode and the Java Runtime pieces can be established, one might either want to also look into bringing back the JRE into the browser or painfully drop Java for C++, as the latter is already close to have acceptable (slower and limited) wasm target runtime properties.