JWebAssembly icon indicating copy to clipboard operation
JWebAssembly copied to clipboard

wasm memory not exported ?

Open zonghaishang opened this issue 3 years ago • 3 comments

Currently, data transfer is dependent on wasm's linear memory, but jwebassembly is not exported. Is it currently not supported?

  • memory[0] -> "memory"

I found out that both tinygo and teavm include memory export.

zonghaishang avatar Apr 14 '21 03:04 zonghaishang

JWebAssembly does not used linear memory for data access. It is written for a GC. The linear memory contains only the class descriptions, string constants, etc. The program code that are not machine instructions.

Horcrux7 avatar Apr 14 '21 16:04 Horcrux7

JWebAssembly does not used linear memory for data access. It is written for a GC. The linear memory contains only the class descriptions, string constants, etc. The program code that are not machine instructions.

Maybe I don’t understand it correctly, I found that the webassembly specification should include the memory section: https://webassembly.github.io/spec/core/binary/modules.html#binary-memsec

At present, the exchange of complex types of data and the host can only be passed through the linear memory of wasm. https://github.com/mosn/mosn/blob/ebd131fbfb2c6eae7d0926ee305ecdeba194e348/pkg/wasm/runtime/wasmer/instance.go#L363

zonghaishang avatar Apr 15 '21 03:04 zonghaishang

Maybe I don’t understand it correctly, I found that the webassembly specification should include the memory section: https://webassembly.github.io/spec/core/binary/modules.html#binary-memsec

It can contain a memory section. It is optional. JWebAssembly use also a memory section but only for it internal data.

At present, the exchange of complex types of data and the host can only be passed through the linear memory of wasm. https://github.com/mosn/mosn/blob/ebd131fbfb2c6eae7d0926ee305ecdeba194e348/pkg/wasm/runtime/wasmer/instance.go#L363

Via memory section you can only share pointers in a byte array. If your complex types are bytes in linear memory like in languages like C++ then this is valid. Java das not work with linear memory. The underlying memory manager of the VM can work with it. But this is a layer that JWebAssembly will not implement.

The target of JWebAssembly is the usage of a GC and there complex object will be share by reference.

Horcrux7 avatar Apr 15 '21 14:04 Horcrux7