Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

WebAssembly (WASM) generation questions #1170

Closed
ylluminate opened this issue Dec 19, 2017 · 10 comments
Closed

WebAssembly (WASM) generation questions #1170

ylluminate opened this issue Dec 19, 2017 · 10 comments

Comments

@ylluminate
Copy link

Could you provide an overview of how Kotlin generates WASM output given that garbage collection is a requirement for Kotlin and the garbage collection specification has not even been implemented yet for WebAssembly?

I'm curious to get a "10 mile view" of what you're doing that has overcome this deficiency for the time being and also working with providing standard libraries for the language.

@alexander-gorshenev
Copy link
Contributor

Our webassembly runtime uses the same memory management code as all other native targets. It is written in C/C++ and is compiled to wasm together with the Kotlin code. So until you are all inside wasm32 you should notice no difference.

We are working on providing a richer Kotlin/WASM32 to JavaScript interoperability. That will bring some complications on the boundary between the languages.

@ylluminate
Copy link
Author

Hmm, perhaps I'm missing something here in your explanation. As per a discussion I had here, gc still needs to be considered and implemented on a per language need / basis where gc is required by that language. In the case noted there, you'll see that they are saying that we have to get bdwgc running prior to Crystal working. Do you not do something similar? Or is there a way "around" this garbage collection issue that we're missing in that discussion?

FYI, it might be easier for you to look into using Emscripten to get the JS interop.

@alexander-gorshenev
Copy link
Contributor

Yes, we have our garbage collection code (which is a reference counter with a cycle collector) ready and running on wasm32.

@ylluminate
Copy link
Author

Interesting, I see you've got a binaryen.diff, is this where you implement the gc? I would be interested in exploring how you implemented your gc functionality.

@catmando
Copy link

@Alefas so if you could explain a little more... Your compiler and WASM is treating memory as linear array of bytes? And then you build your structures on top of that just as if you were dealing in assembly? How do you search the stack frame and global variable space for pointers?

@sureshg
Copy link

sureshg commented Dec 20, 2017

@olonho
Copy link
Contributor

olonho commented Dec 20, 2017

Not sure what is the issue here. Closing for now.

@olonho olonho closed this as completed Dec 20, 2017
@ylluminate
Copy link
Author

ylluminate commented Dec 20, 2017

@olonho I think @catmando was hoping for some more verbose English based explanation of what is going with regards to memory management / gc from @alexander-gorshenev.

@RX14
Copy link

RX14 commented Dec 21, 2017

The question is an implementation question: how do you implement GC roots on the stack for the wasm target, which is a stack machine not a register machine.

Go's very WIP port recreates the stack in linear memory, at a speed cost, and the suggested solution from the emscripten guys was to write all pointers to the C stack. We were wondering about your approach to supporting gc on this platform.

@rdp
Copy link

rdp commented Sep 5, 2018

@alexander-gorshenev how does the "automatic reference counting with a cycle collector on top" work in wasm without being able to walk the stack to look for roots? or does it not need to? (ref: https://blog.jetbrains.com/kotlin/2017/04/kotlinnative-tech-preview-kotlin-without-a-vm/ )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants