7 ms·
WebAssembly for the Java Geek
- stevefan1999 4y agoalso take a look in .NET counterpart: https://dev.to/azure/exploring-net-webassembly-with-wasi-and-wasmtime-41l5 https://dev.to/azure/exploring-net-webassembly-with-wasi-and...
- singularity2001 4y agoThis seems a bit outdated. There was a recent blog post by intellij Raider that showed that you can just compile to wasm by adding the wasi nuget package, no extra steps required.
- stevefan1999 4y agoIt's JetBrains Rider not Raider...Plus the blog post I posted also talked about the out of the box experience with just installing one Wasi.Sharp package to get WASI WebAssembly support out of the box for most scenarios...except it is still too big to put into Cloudflare workers because it contains the entire Mono runtime...
- evacchi 4y agohuh, author here, I didn't expect this to be on HN please don't roast me too much :P
- lifthrasiir 4y agoNot sure why, but some links in the article seem to be missing, for example one to the draft GC spec for WebAssembly (which should probably link to https://github.com/WebAssembly/gc https://github.com/WebAssembly/gc).
- evacchi 4y agoyou are right, I spotted a couple more links being broken. They should be fixed now. Thanks!
- ridruejo 4y agoIt is actually a pretty good article and I learnt quite a bit. Thanks for taking the time to write it. The only two things I would add are that, unlike Java, the industry has rallied unanimously behind it (in the 90s it was Java vs .NET and Applets vs ActiveX, etc.) and the big difference that Wasm comes pre-integrated in the browser, has a focus on security and is a proper W3C standard. Everything else that came before it felt like some after-the-fact bolt-on (Flash, Applets, etc.) and had big security issues and often got out of sync with browser releases
- evacchi 4y agothanks! some of those consideration I made in the article I linked at the beginning of this post: "A History of WebAssembly" https://evacchi.github.io/posts/2022/11/23/a-history-of-webassembly/ https://evacchi.github.io/posts/2022/11/23/a-history-of-weba...
- ridruejo 4y agoI missed clicking on it, thanks for sharing!
- deleted 4y ago[deleted]
- kaba0 4y agoI mean, Applets are just really old, security itself wasn’t considered all that “important” at the time. There is no real difference on a purely runtime level between wasm and the JVM to make one safer than the other. And regarding release strategy, that’s just politics.
- usrusr 4y agoWasm could start out as a "function runner" box with no outside interface at all besides arguments and return value, with everything UI, storage or networking conveniently out of scope. Applet, in its day, had to be so much more than just the bytecode VM...
- bullen 4y agoI'm considering building a Java compatible VM that only has static memory allocation to avoid GC. Why hasn't this been done by anyone yet? Also confused why this does not have a binary windows release yet: https://github.com/bytecodealliance/wasm-micro-runtime https://github.com/bytecodealliance/wasm-micro-runtime Edit: Epsilon is not the answer here you can stop mentioning that.
- beardyw 4y agoNot sure how that would play out. Just not running the GC is an unsatisfactory answer. Otherwise what?
- bullen 4y agoBasically you enforce static heap allocation. Meaning you cannot type new in a method only in the class definition. I don't even know if this can be enforced from the bytecode VM... just playing with it in my head.
- ako 4y agoSo the only place you really define what objects get created is in the class containing the main method? Seems fairly limited that you’d have to know upfront what your memory needs are? An app would have to allocate a large block of memory in the main class, and then handle memory management itself from this piece of memory?
- bullen 4y agoYes, you would have to overallocate and reuse. This is the way I code C now allready.
- ako 4y agoThat would remove a lot of the benefits of using Java, might as well use something like c. Garbage collection has been highly optimized in the jvm, and most would consider it a benefit of a jvm compared to managing memory yourself.
- torginus 4y agoGenuine question about GC'd languages on Wasm - how does the GC run? When running a GC language in its own runtime, usually there is at least 1 GC thread, that runs concurrently with the app code and pauses/preempts the main thread. Afaik, in WASM, your application only has CPU time when you are inside a WASM function and threading is incredibly hacky and may be disabled due to security reasons related to side-channel attacks (read up on `SharedArrayBuffer` and cross-origin site isolation).
- pjmlp 4y agoIt runs alongside the application, basically you're back to using RC as GC algorithm or only when memory needs demand a full GC.
- bullen 4y agoReference Counting, ok!
- titzer 4y agoVirgil compiles its tracing semi-space collector into the application. It's the same code as the native GC. The major difference is that the call stack is not visible, so the compiler must spill all live references on the stack into a shadow stack in memory. That last part was the trickiest and most inefficient part of porting.
- kaba0 4y agoWhile it is an informative article, I fail to be convinced that wasm is somehow superior (even for its current role). Validation is faster due to it being structured, but stackmaps make it fast for class files as well. It is lower level, but is that really a good thing? It is quite trivial to just assign a huge ‘long’ array to some jvm byte code for the same result, and while I will look at the linked GC proposal, because haven’t been kept up-to-date on that, I think having a good GC is the single most important thing, as that is much harder to do than just providing a linear array. Which will in turn decimate the implementations (or at least mark a toy vs prod ready divide). Also, will that structured nature not make it a less than great compilation target? This means that certain, more niche languages will have to use ugly (and slow) hacks to get implemented. And it being lowish level it is much harder to optimize it well (in that you express the exact semantics).
- kodablah 4y agoFor many, language freedom/portability outweigh other concerns and this is where WASM has value. Running an algorithm written in Rust, Go, C, Zig, etc on the JVM with no JNI has value vs rewriting. > It is lower level, but is that really a good thing? It is quite trivial to just assign a huge ‘long’ array to some jvm byte code for the same result That's basically what the WASM implementations on the JVM currently do. But it is actually _higher_ level from a dev POV due to language choice (at a not-huge performance expense).
- sandGorgon 4y agoJust fyi - there is an open bug to target wasm for Graal java compilation. https://github.com/oracle/graal/issues/3391 https://github.com/oracle/graal/issues/3391 to a very large extent, it is open till LLVM upstream is more functionally complete to support GC. wasm doesnt support GC to the way Java and Graal does. Which is why Graal is seriously impressive piece of tech. so it is not wasm vs java. Because that is really apples verus oranges. it is just a matter of time before java gets compiled to wasm. that's what makes me puzzled about this article. Maybe its really about rust or golang vs java.
- nilslice 4y agoFor anyone who want to experiment with WebAssembly in Java, we just shipped a Java Host SDK[0] for Extism[1] which makes it about as easy as possible to call wasm functions from your Java programs. 0: https://extism.org/docs/integrate-into-your-codebase/java-host-sdk/ https://extism.org/docs/integrate-into-your-codebase/java-ho... 1: https://github.com/extism/extism https://github.com/extism/extism
- TeaVMFan 4y ago+1 for TeaVM. Not only is there the Fermyon friendly fork, but WASM/WASI/debugging is seeing a large number of checkins in recent weeks in the main fork. However, true "Java Geeks" should try the JavaScript support in TeaVM. It is mature and battle-tested. The resulting code runs great in a browser. Live TeaVM-based game: https://frequal.com/wordii https://frequal.com/wordii Getting started with TeaVM: https://frequal.com/TeaVM/ https://frequal.com/TeaVM/ Performance Comparison: https://frequal.com/java/TeaVmPerformance.html https://frequal.com/java/TeaVmPerformance.html