News for hackers. Stuff that matters.
Re:WebAssembly: Docker Without Containers by pjmlp on Wednesday December 21, 2022 @06:13AM (#34079172)
Well, those that act like WebAssembly is reinvinting the world kind of do.

And applications get tied to the WebAssembly ecosystem, it is also a single one.

Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @06:26AM (#34079252)
While it’s true that it somewhat locks you into a single VM type (WASM), that’s very different from being locked into the JVM.

For one, the idea is that it should be fairly simple to compile an arbitrary program to WASM, allowing you to use a far wider variety of languages.

In this case, it’s more akin to “docker with extra steps” as opposed to “docker but you can only hire Java devs”

Re:WebAssembly: Docker Without Containers by pjmlp on Wednesday December 21, 2022 @08:14AM (#34080275)
Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @08:44AM (#34080611)
If the best counterpoint I could find is a dead proof of concept project from over a decade ago that only works on a compiler released 17 years ago, I would reevaluate my position
Re:WebAssembly: Docker Without Containers by pjmlp on Wednesday December 21, 2022 @11:07AM (#34082479)
Unfortunately it lacked the buzzwords of VC money to make it a trendy topic.
Re:WebAssembly: Docker Without Containers by sitkack on Wednesday December 21, 2022 @12:20PM (#34083485)
You realize nestedvm is compiling native code to MIPS and then inlining the MIPS interpreter into the generated class files? Had the JVM supported unsigned types, none of this would have been necessary.

Wasm is a refinement of the ideas in the JVM, with a couple good JVM on Wasm solutions already existing. The best of which is CheerpJ.

Instead of referencing NestedVM, you should link to GraalVM which I know you are aware of.

Re:WebAssembly: Docker Without Containers by layer8 on Wednesday December 21, 2022 @01:13PM (#34084246)
Unsigned types are trivially emulated using signed types. All arithmetic operations except division/remainder and comparison are identical on the bit level, and the latter are supported via `Long.divideUnsigned()` and friends, which can JIT to the native unsigned operations of the underlying platform.

The main difference with regard to compiling “arbitrary” programs between the JVM and WASM is that the JVM doesn’t have untyped linear memory like WASM does. WASM isn’t type-safe within the linear-memory regions (which is what allows C-like languages to be compiled more directly), whereas JVM ensures type safety for all objects.

Saying that “WASM is a refinement of the ideas in the JVM” is simply wrong, they have different design goals and therefore implement different design trade-offs.

Re:WebAssembly: Docker Without Containers by sitkack on Tuesday December 27, 2022 @08:06PM (#34156211)
> JVM and WASM [sic] is that the JVM doesn’t have untyped linear memory like WASM does.

As you say, it can be trivially emulated, no reason that linear memory couldn't be implemented on the JVM using an array of primitive (char,int,long).

The Wasm VM is more generic and has a better capabilities security model than the JVM. Had the JVM been more like Wasm (signed and unsigned primitives, capabilities model), it would have been a natural compilation target for sandboxing native code.

As Wasm gets more features it becomes more like the JVM (GC, reference types, component model). Eventually Wasm will subsume all the features that differentiates them.

Re:WebAssembly: Docker Without Containers by treis on Wednesday December 21, 2022 @08:40AM (#34080566)
>single VM type (WASM), that’s very different from being locked into the JVM.

Why is that different?

Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @08:51AM (#34080700)
You can’t run Postgres on the JVM.

WASM is pretty different to the JVM. The JVM deals with a lot of higher level constructs like objects, constructors, virtual methods, the GC etc. Which is fine if the language you’re hosting works in that way.

WASM is more like assembly - the raw intrinsics used by a hypothetical WASM CPU. So you can compile a lot more stuff to it, because it’s a more natural target than a much, much higher level VM like the JVM.

Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @09:14AM (#34080959)
Although that's true (ish... you can run WASM on the JVM now, and also LLVM bitcode), that takes you into the realm of why you'd want to.

On the browser side, you could maybe make a ChromeOS style argument of just wanting to run everything in a browser no matter what, it's nice for it to be sandboxed etc. But if you look at what your Postgres is doing it's sort of a Linux VM, and you can run those already at full speed: that's WSL and there are various solutions on macOS like Docker Desktop.

On the server side, the reason nobody bothered trying to run Postgres on the JVM before Graal is that it's unclear what the benefit is. Security? Processes and kernel isolation seems to work well enough on the server, and anyway Postgres is a highly trusted component anyway. CPU independence? That hasn't been useful since stuff like SPARC died, we are now just starting to see ARM chips appear on the server, but compiling native code for both intel and arm isn't hard and Linux distros have the infrastructure to do it for a long time already. For custom servers, well, not many are writing them in C/C++/Rust anyway these days. RISC-V remains mostly theoretical.

To what extent is this doing it because it can be done, vs delivering real benefits? My mind is open but the low level nature of the WASM instruction set also means the VM can't offer many benefits to the programs inside it, nor the users outside it.

Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @09:37AM (#34081234)
Let me rework and clarify my point here a bit.

The JVM has historically and famously sucked at sandboxing untrusted/partially trusted code. The JVM also isn’t a suitable compilation target for arbitrary and existing codebases.

WASM is built to sandbox untrusted/partially trusted code. WASM is built as a compilation target rather than a complete hosted VM with bells and whistles.

There are advantages and disadvantages to this. One advantage is language-agnosticism. Another might be around the ability to run user-supplied untrusted code in a much safer way. See Cloudflare functions.

One disadvantage is the lack of bells and whistles.

So, the answer to “why is this different to the JVM” is that.

Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @10:53AM (#34082255)
"The JVM has historically and famously sucked at sandboxing untrusted/partially trusted code. The JVM also isn’t a suitable compilation target for arbitrary and existing codebases."

We need to drill into this a bit more, because the WASM ecosystem can certainly learn lessons and do better than the JVM but this isn't quite the right set of lessons to learn.

The JVM spec was written from day one to sandbox arbitrary and partially trusted code. The SecurityManager architecture is now being removed, but that's a big project exactly because it was deeply integrated into everything. It's also embeddable and a compilation target (it interprets bytecode), and later it was extended with features designed to make it more language agnostic as well at least for everything at the same level of dynamism of Java or higher (so indeed not C/C++ but yes for most other langs).

So the interesting thing to debate here is not really the design goals, which are very similar, but what concretely will make WASM more successful at achieving these goals.

For example, what made the SecurityManager difficult wasn't something fundamental to the JVM but rather that code which is both useful and sandboxed needs APIs that let it do privileged things in controlled ways, and a lot of the bugs were in those API implementations or on the boundaries. That's especially the case on the desktop where sandboxed code had to call into a lot of OS libraries.

On the web this problem is solved with the browser makers exposing JS/renderers to WASM or just saying do the tricky stuff in JS, and then wrapping the whole thing with kernel sandboxes and IPC to handle the fact that the JS/WASM sandbox itself will inevitably fail in the same way. In other contexts this, well, doesn't seem to be solved, really? The moment you start exposing APIs to the WASM code you face the same problem. Also these days you have spectre to think about, so maybe you need a separate process sandbox anyway. Alternatively you can do what the GraalVM guys are doing (in their EE) and using Intel MPKs but that's pretty advanced and I didn't hear about anyone else doing that.

Now there are still some crucial differences! The JVM wanted to allow sandboxed code to interop smoothly with higher privileged code. This opened up a bunch of reflection-based bugs whereby you could reflect your way to the SecurityManager and switch it off, confused deputy attacks and so on. There's no equivalent in WASM, but that's partly because (current?) WASM doesn't really try to define a fine grained permissions model or a way to mark some bits of code in a program as more privileged than others. It also doesn't provide a large set of pre-implemented APIs. The sandbox is whatever the developer exposes to the context. This doesn't make WASM stronger, it just means it punts the really hard bits to the user i.e. browser devs. GraalVM's new JVM sandbox (not SecurityManager based) works mostly the same way, as do process sandboxes so this is definitely the trend, but of course there was a reason the SecurityManager was created that way and it's because it requires way more code and work by the developer to sandbox code if you don't have support for tight mixing. So maybe the sandboxes that do exist will be stronger, but there'll be less sandboxing overall and permission scopes will be much wider. Is that the right tradeoff? I'm not totally sure it is but eh, people really like all-or-nothing and that's the way the industry is heading now.

At any rate that discussion is a bit academic, because you can't do an OOP capabilities type architecture in C anyway.

What about language agnosticism? Again the hard part here isn't having a common bytecode - CPUs already provide that - it's all the engine bindings and semantic alignment required. If you want to pass a std::time into JavaScript then something has to bridge that gap, if you want to call into a dynamically typed language from a statically typed language, then something has to generate interfaces for the compiler to check against and so on. Here I don't see what WASM has to do with anything really, it's just not in scope. Compiling a Python interpreter to WASM doesn't make it any easier to call Python from C++, or Java, or JavaScript. The SOTA there is Truffle/JVM by far.

Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @11:09AM (#34082510)
I don’t really have much else to add to this discussion right now (it would require too much brain power whilst sitting next to a fire), but I would like to thank you for this very detailed and informative comment.
Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @11:17AM (#34082623)
Enjoy the fire, sounds lovely!
Re:WebAssembly: Docker Without Containers by sitkack on Wednesday December 21, 2022 @12:26PM (#34083562)
Wasm composes in the way that the JVM/SecurityManager did not. You can implement your proxy functions in wasm, not only defining the set of functions that a Wasm program uses to talk to the outside world, those proxy functions that you pass in can also be implemented in wasm inside of another context.

Wasm can learn from the JVM for sure, but if you went almost 30 years back in time, you would have some great tricks to teach the JVM, learned from Wasm.

Re:WebAssembly: Docker Without Containers by whimsicalism on Wednesday December 21, 2022 @09:35AM (#34081210)
LLVM on the JVM is news to me, have a link?
Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @10:07AM (#34081610)
Re:WebAssembly: Docker Without Containers by treis on Wednesday December 21, 2022 @09:09AM (#34080904)
But there's not much point to running Postgres in WASM. It's written in C to avoid the performance overhead of a VM in the first place.
Re:WebAssembly: Docker Without Containers by int_19h on Sunday December 25, 2022 @10:03PM (#34134108)
The problem isn't that JVM deals with higher level constructs. It's that it doesn't deal with low-level constructs.

Consider .NET / CLR for another example. Like JVM, it also deals with objects, methods etc conceptually on bytecode level. But it also deals with raw pointers and pointer arithmetic and other such stuff. As a result, you can efficiently compile e.g. C into that bytecode. So wasm isn't really new in that sense, either.

Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @08:45AM (#34080624)
Can you actually compile an arbitrary program to WASM? I thought they had to be ported to WASI first and can't use any operating system APIs. Otherwise, how can it be sandboxed? Arbitrary programs can call into arbitrary OS-native APIs and execute arbitrary native code outside the bounds of the WASM VM, including things like JITing native code.
Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @08:50AM (#34080693)
It depends on the program being compiled, but yes you can.

You can run Postgres using WASM in two different ways[1][2]. That’s a non-trivial codebase.

1. https://www.crunchydata.com/blog/learn-postgres-at-the-playg...

2. https://supabase.com/blog/postgres-wasm

Re:WebAssembly: Docker Without Containers by mike_hearn on Wednesday December 21, 2022 @09:06AM (#34080877)
That works by compiling some sort of Linux VM into WASM as well, which isn't arbitrary programs (that would have to include Windows and macOS programs too).
Re:WebAssembly: Docker Without Containers by orf on Wednesday December 21, 2022 @09:21AM (#34081044)
I feel like you’re nitpicking and ignoring the actual argument you originally made?

You can compile arbitrary programs to WASM, like you can compile arbitrary programs to x86 or ARM. It’s effectively a CPU target. You can take the whole of Python and SQLite, compile them to WASM and run a web framework on top of that via WASM in the browser[1].

If those programs utilise specific os-level behaviour that can’t be shimmed, or explicitly throw an error when being compiled to WASM then of course they won’t work without modifications.

Meanwhile, the JVM is not anything like a CPU target. It’s a very high-level VM designed for a particular type of language.

1. https://simonwillison.net/2022/May/4/datasette-lite/

Re:WebAssembly: Docker Without Containers by pbecotte on Wednesday December 21, 2022 @12:22PM (#34083515)
I don't think the statement "fairly simple to compile an arbitrary program" hasn't been true for any ecosystem, ever.
Re:WebAssembly: Docker Without Containers by kaba0 on Thursday December 22, 2022 @04:29AM (#34091503)
Making a big byte array and using some very basic jvm instructions will give you a very low-level compilation target for basically any language.
Re:WebAssembly: Docker Without Containers by imtringued on Wednesday December 21, 2022 @07:07AM (#34079587)
What's wrong with a "JVM but for everyone who isn't a Java developer"?

If the model works, why shouldn't there be competitors and wide spread adoption?

Re:WebAssembly: Docker Without Containers by pjmlp on Wednesday December 21, 2022 @08:07AM (#34080211)
Nothing, that is after all how CLR was designed, just lets not pretend it is something new.
Re:WebAssembly: Docker Without Containers by espadrine on Wednesday December 21, 2022 @08:36AM (#34080522)
JVM wasn’t just for Java developers (Kotlin, Clojure, Ruby could compile to it); but it was easiest for Java, and other languages didn’t elect to build on the JVM interface by default, rather adopting POSIX (and either a custom bytecode or assembly) as the interface.

WASM likely won’t convince all languages to switch to its bytecode by default. Its adoption story requires enough people to maintain this non-standard compilation pipeline.

Which is fine, but beyond the bytecode, the productivity will only be maintained if it offers an equal or superior interface to POSIX. Right now, WASI is not it. A lot of basic elements are experimental, like file seek, multi-process, threads, SIMD, GPU programming…

People will believe the hype, miss the caveats, use it at work, and have their project fail. Companies will blacklist the technology.

In my mind, it is too early for them to be so publicly dithyrambic. All WASM publications should link to a page that details all WASI features that are still experimental.

Re:WebAssembly: Docker Without Containers by fulafel on Thursday December 22, 2022 @01:38AM (#34090513)
"JVM but for everyone who isn't a Java developer" would be good but WebAssembly isn't really suited for it. It works for some static native-code targeting languges (C, C++, Rust, Zig, etc) but doesn't work well for languages that most application developers use (.NET languages, TypeScript/JavaScript, Python, Clojure, Java, Ruby, etc).
Re:WebAssembly: Docker Without Containers by dragonwriter on Thursday December 22, 2022 @01:52AM (#34090594)
> "JVM but for everyone who isn't a Java developer" would be good but WebAssembly isn't really suited for it. It works for some static native-code targeting languges (C, C++, Rust, Zig, etc) but doesn't work well for languages that most application developers use (.NET languages, TypeScript/JavaScript, Python, Clojure, Java, Ruby, etc)

.NET/Java/Clojure, maybe not. Ruby and Python work via an interpeter for the platform, just like they do on JVM/.Net, except that, unlike JVM/.NET, in both cases they can use the normal C-based interpreter, compiled for WASM.

Re:WebAssembly: Docker Without Containers by fulafel on Thursday December 22, 2022 @03:24AM (#34091079)
You can do it, but it remains to be seen if we get a lot of use cases where there are more positive than negative tradeoffs from targeting a VM implementation to WebAssembly and then running a VM inside a VM that way. I guess eg Python could be useful in cases where you want to use it as a glue language between WebAssembly components...
Re:WebAssembly: Docker Without Containers by ridruejo on Wednesday December 21, 2022 @07:10AM (#34079601)
One way of looking at it that helped me wrap my head of why “this time is different”, is that Wasm is not so much as a language but a compilation target (as say x86) so it can really run anything
Re:WebAssembly: Docker Without Containers by pletnes on Wednesday December 21, 2022 @07:45AM (#34079984)
That’s what JVM promised! They just made Java so there would be at least one familiar-looking (to C++ devs) language for it. Indeed, there are quite a few JVM languages out there, just not as many as some had hoped in 1995.
Re:WebAssembly: Docker Without Containers by cle on Wednesday December 21, 2022 @08:01AM (#34080142)
The JVM executes Java bytecode, which is a compilation target for Java and many other languages. In this regard, architecturally it is exactly the same.
Re:WebAssembly: Docker Without Containers by acdha on Wednesday December 21, 2022 @08:27PM (#34088603)
Kind of - it was designed for Java so other languages were suboptimal for a long time, especially dynamic ones. Combined with the low quality of Java application servers and tooling, that approach was unpopular by the time things like InvokeDynamic matured and then Oracle’s licensing moves gave a lot of places reason for caution.
Re:WebAssembly: Docker Without Containers by int_19h on Sunday December 25, 2022 @10:04PM (#34134116)
The biggest problem when compiling to JVM bytecode isn't dynamic languages - even if they are slower, it's tolerable. It's stuff like C++, where the whole point is being fast, but JVM simply lacks the necessary primitives to compile to.
Re:WebAssembly: Docker Without Containers by FlyingSnake on Wednesday December 21, 2022 @08:37AM (#34080531)
Scala, Kotlin, Groovy proved that JVM can be used as a compilation target. Same was proven with Iron* languages on CLR. How is it different this time?
Re:WebAssembly: Docker Without Containers by pbecotte on Wednesday December 21, 2022 @12:36PM (#34083727)
It can run "anything" ... so long as someone has set up that project to correctly compile to a wasm target. "docker build" lets you build a package out of any software, without having to know much about it. "setting up a compiler for a new project, given the source code and maybe a separate toolchain for some other target that works", is a much more involved task.

There is no world where people are just grabbing an existing app and saying "hey, I'm gonna drop this into my wasm runtime real quick"