-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use EntryStoreContext to manage state when entering and exiting Wasm #10626
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
Use EntryStoreContext to manage state when entering and exiting Wasm #10626
Conversation
CC @fitzgen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, will merge once our collective nitpicks are addressed. Thanks a ton for this clean up!
Initial comparison to
Looks like an improvement for most things! Going to look into the regressions a little bit. |
Co-authored-by: Nick Fitzgerald <[email protected]>
Okay I've got a few
|
// same store and `self.vm_store_context == self.prev.vm_store_context`) and we must to | ||
// maintain the list of contiguous-Wasm-frames stack regions for | ||
// backtracing purposes. | ||
// FIXME(frank-emrich) Does this need to be an (Unsafe)Cell? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the reasoning about UnsafeCell
elsewhere, I guess the answer is "no" here then as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, because nothing is mutating this pointer in such a way that violates Rust's regular borrowing discipline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I remember now why I put this comment here: The previous old_*
fields were Cell
s. Maybe that was just some leftover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, should be fine to remove.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Currently, there are two places that perform some updates to the runtime when entering and exiting Wasm: In
runtime::vm::catch_traps
(together withCallThreadState
'sdrop
) and infunc.rs
(using theenter_wasm
/exit_wasm
functions there). I believe @alexcrichton mentioned that this split is mostly for legacy reasons due to how to things were separated into different crates until recently.As a result, both of these places need to store different parts of the runtime state, and then restore it at the right moment.
This PR consolidates all of this into one place using a new type,
EntryStoreContext
, whoseenter_wasm
andexit_wasm
functions mimic the original functions, but also subsume what previously happened inCallThreadState
. The code is just moved around with minimal changes. The name of the type reflects that we are storing a subset of theStoreContext
upon entry into Wasm.The motivation for this refactoring is the following (discussed here): For the implementation of the stack switching proposal, we need to save and restore even more context. Using either of the places mentioned above lead to awkward code. Thus, this PR contains the necessary preparation work, without any stack-switching specific code.