Stream: wasm

Topic: class/object structures in wasm


view this post on Zulip Justin Lee (Apr 14 2023 at 20:24):

i'm trying to wrap my head around wasm representation of different structures. how would one define/represent an object definition in wasm? would that be a module? or would a module more closely align with the application itself?

view this post on Zulip Justin Lee (Apr 14 2023 at 20:25):

i.e., is a module an application? or does an application consist of multiple modules linked together? it feels more like the former.

view this post on Zulip Lann Martin (Apr 14 2023 at 20:30):

In the pre-components world, a WASI "command" module is an application

view this post on Zulip Lann Martin (Apr 14 2023 at 20:31):

There are various ways to link modules together, but nothing really standardized

view this post on Zulip Lann Martin (Apr 14 2023 at 20:32):

The component model aims to standardize a particular way of linking modules together

view this post on Zulip Justin Lee (Apr 14 2023 at 20:32):

ok so that sounds like roughly object == module in that sense. (coming from a jvm background)

view this post on Zulip Justin Lee (Apr 14 2023 at 20:33):

reading through various wast examples seem to support that.

view this post on Zulip Lann Martin (Apr 14 2023 at 20:34):

A closer analog for JVM would be a package, probably. There aren't any (native) "objects" in wasm

view this post on Zulip Justin Lee (Apr 14 2023 at 20:34):

maybe via name mangling and paramater passing i can fake out the instance method scenario.

view this post on Zulip Justin Lee (Apr 14 2023 at 20:35):

yeah. i've been trying to figure out how to emulate that.

view this post on Zulip Lann Martin (Apr 14 2023 at 20:37):

There will be "resource types" Pretty Soon which are intended to model things like that. In the meantime I think the most common approach has been to represent object references with integer handles that are manually tracked in a table

view this post on Zulip Chris Fallin (Apr 14 2023 at 20:37):

a key distinction between Wasm and the JVM (or other OOP runtimes like .NET) is its memory storage model -- Wasm gives each module a linear store ("C-style addressed memory") and the main approach in core Wasm so far has been to put the runtime on top of that

view this post on Zulip Chris Fallin (Apr 14 2023 at 20:38):

e.g. with SpiderMonkey-on-Wasm, JS objects are managed by the usual SpiderMonkey GC, and this lives inside of the module and allocates storage out of the linear address space

view this post on Zulip Justin Lee (Apr 14 2023 at 20:38):

interesting. like off-heap storage in the jvm.

view this post on Zulip Chris Fallin (Apr 14 2023 at 20:38):

a challenge with a module-is-an-object mapping instead will be that there are no first-class instances; i.e. there's no direct mapping for "new T"

view this post on Zulip Lann Martin (Apr 14 2023 at 20:38):

See for example: https://github.com/WebAssembly/wasi-http/blob/main/wit/types.wit#L76-L93

Contribute to WebAssembly/wasi-http development by creating an account on GitHub.

view this post on Zulip Chris Fallin (Apr 14 2023 at 20:39):

rather the shape of the instance graph is static and fixed as defined in the component

view this post on Zulip Justin Lee (Apr 14 2023 at 20:41):

some funky stuff there. i love it.


Last updated: Dec 23 2024 at 12:05 UTC