Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for inter-instance stack switching #108

Merged
merged 5 commits into from
Feb 16, 2024

Conversation

frank-emrich
Copy link

There is a currently a conceptual error in the implementation, where the chain of active stacks (= continuations + the main stack) is stored per Instance/VMContext.

This means that when a function $f calls an imported function $g, where $f and $g are not part of the same instance, their stack chains are completely separate. For example, it is not possible to suspend to a tag $t in $g and handle this in a resume block in $f (assuming that the underlying modules import and export the tag $t so that it is shared between the two).

This PR rectifies this situation by sharing a single StackChain object between all instances of the same Store. The VMContext then contains merely a pointer to this shared chain, rather than a chain of its own. This fully mirrors how the VMRuntimeLimits are already shared between all instances of a Store.

Copy link
Member

@dhil dhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@dhil dhil merged commit 82d8569 into wasmfx:main Feb 16, 2024
19 checks passed
@dhil
Copy link
Member

dhil commented Feb 19, 2024

Did you test this on the baseline implementation? I am thinking it may just have worked because of the use of (global) thread-local state. Though, it should be easy to construct an example with host threads, which causes a segfault. But I suppose we don't care much about such things at this stage.

@frank-emrich
Copy link
Author

Regarding the baseline implementation, I assumed that it would just work due to its usage of thread-local state. But I did make sure that the new test is actually executed for both implementations. Crossing threads would require performing a host call and then re-entering wasm. I'm not sure if the current wasmtime API actually allows you to carry a mutable Store across thread boundaries.
I guess that we do not overly care about that, but it's something I've discussed in #109

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

Successfully merging this pull request may close these issues.

None yet

2 participants