I'm confused about all of this - is WebAssembly related to the Google Native Client stuff they did and are now deprecating? Is there a write-up of how it works?
First there was NaCl which was a subset of x86 code leveraging x86 features to sandbox the execution. This x86 subset was produced by a special toolchain and could be verified before running. Then PNaCl came along with a platform-independent bitcode format based on LLVM IR, which was translated to host's native code in the browser. Then WASM (also platform-independent) came along striving to be a multi-vendor solutio…
WebAssembly Stack Machine
31–40 of 47 posts
Re: WebAssembly Stack Machine
#32Re: WebAssembly Stack Machine
#33If WASM runs on a stack machine, I wonder how hard it would be to map the instructions to JVM bytecodes? From the example in the document they look similar... It would be interesting to be able to take code compiled with Emscripten for example and run it as part of JVM applications, similar to what NestedVM can do.
The devil's in the details. Exception handling and garbage collection are different enough that a straightforward adaptation won't cut it.
In any case I don't have time to implement all of that but it seems like it could be any interesting way to run non-java libraries on the JVM
Re: WebAssembly Stack Machine
#34Earlier quoted context omitted.
I don't think it makes a big difference. It's not that difficult to reconstruct an AST from a stack machine that has the same stack types on every code path. It's mostly just a post-order serialization of the AST. push x push y add Evaluate this symbolically and you get (add x y) naturally. Writing a simple interpreter, I prefer register or stack machine over AST walker. It'll be faster, for one. And there's a chance…
WA doesn't get interpreted. It gets validated and passed over to the JIT (TurboFan). It comes over the wire so that validation has to be thorough (read that as expensive).
I also don't agree re expensive validation; I think you're wrong. Interface with APIs much more problematic than pure computation, which is not hard to validate. Interface safety is largely the same problem as with plain JS, as I see it. I don't see stack machine vs register machine making almost any difference at all.
Re: WebAssembly Stack Machine
#35It makes me sad to see the AST go. I was thinking of writing my own WASM compiler just for fun, purely as an AST transformer. Its funny how most of the WASM tools still use s-experssions as the text format. How does that even work, now that the AST is history?
You can think of the old s-expression format as a language that compiles into wasm, a language that is an AST and that happens to have the same types and operations etc. as wasm.
Re: WebAssembly Stack Machine
#36The WA stack machine was added late in the game. Before that it was an AST but they got pushback from browser backend people and pivoted to a stack machine. https://github.com/WebAssembly/design/issues/755 AST was a good idea and parsing as validation was excellent. Having a general stack machine makes validation much more difficult. This is a bad decision (stacks vs AST or register) made for the wrong reason (code s…
> AST was a good idea and parsing as validation was excellent. Having a general stack machine makes validation much more difficult. Why? This document suggests that it's not that different. "The main new changes to verification are: - All branches to the end of a block must have the same arity and same types, including the implicit fall-through to end. - The true block of if-end constructs must leave the stack at the…
(Those problems and their solutions haven't been documented yet AFAIK.)
Re: WebAssembly Stack Machine
#37Re: WebAssembly Stack Machine
#38The WA stack machine was added late in the game. Before that it was an AST but they got pushback from browser backend people and pivoted to a stack machine. https://github.com/WebAssembly/design/issues/755 AST was a good idea and parsing as validation was excellent. Having a general stack machine makes validation much more difficult. This is a bad decision (stacks vs AST or register) made for the wrong reason (code s…
> That's a 1990s design assumption when memory was expensive Memory is still expensive: * Spreading things out in memory more causes more cache misses, which lowers performance. * Using more memory increases page faults, which lowers performance. * I believe using more memory drains batteries faster on mobile devices, but I'm not sure exactly why. Maybe the effort spent shuttling stuff from virtual memory into real m…
Re: WebAssembly Stack Machine
#39The WA stack machine was added late in the game. Before that it was an AST but they got pushback from browser backend people and pivoted to a stack machine. https://github.com/WebAssembly/design/issues/755 AST was a good idea and parsing as validation was excellent. Having a general stack machine makes validation much more difficult. This is a bad decision (stacks vs AST or register) made for the wrong reason (code s…
> That's a 1990s design assumption when memory was expensive Memory is still expensive: * Spreading things out in memory more causes more cache misses, which lowers performance. * Using more memory increases page faults, which lowers performance. * I believe using more memory drains batteries faster on mobile devices, but I'm not sure exactly why. Maybe the effort spent shuttling stuff from virtual memory into real m…
There's also the issue of additional latency from tertiary caches, like the disk, when you are under memory pressure.
Re: WebAssembly Stack Machine
#40I just wanted to say Im really excited about this project. I hope it will come together and make software universal as the web we have today (if I understand it right). Anyways, how can I contribute?