Why the JVM cannot be used in place of WebAssembly?

A quote from the High-Level Goals of WebAssembly:

a Minimum Viable Product (MVP) for the standard with roughly the same functionality as asm.js, primarily aimed at C/C++;

So their original goal was running C/C++ program in a web browser, not running Java code.


There are a great many reasons why the JVM was not deemed a suitable runtime in place of WebAssembly ...

  • WebAssembly was designed with delivery-over-HTTP and browser-based in mind. For that reason, it supports streaming compilation - i.e. you can start compiling the code while downloading.
  • WebAssembly was designed to have rapid compilation times (resulting in web pages that load quickly), this is supported by having very simple validation rules compared to Java / JVM languages.
  • WebAssembly was designed with the concept of a 'host' environment, i.e. the browser.
  • WebAssembly was designed to be secure and simple, minimising the overall attack surface.
  • WebAssembly was designed to support a great many languages (C, C++, Rust, ...), whereas the JVM was initially design for a single language, Java.

As a general observation, WebAssembly was designed to support multiple languages on the web. The JVM was designed to support Java on the desktop. It doesn't make either one better than the other in a more general sense.

Finally, the JVM was integrated with the browser (Java Applets), but that didn't work out in the end!