-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor module instantiation in the runtime. #2454
Commits on Feb 4, 2021
-
Implement support for
async
functions in WasmtimeThis is an implementation of [RFC 2] in Wasmtime which is to support `async`-defined host functions. At a high level support is added by executing WebAssembly code that might invoke an asynchronous host function on a separate native stack. When the host function's future is not ready we switch back to the main native stack to continue execution. There's a whole bunch of details in this commit, and it's a bit much to go over them all here in this commit message. The most important changes here are: * A new `wasmtime-fiber` crate has been written to manage the low-level details of stack-switching. Unixes use `mmap` to allocate a stack and Windows uses the native fibers implementation. We'll surely want to refactor this to move stack allocation elsewhere in the future. Fibers are intended to be relatively general with a lot of type paremters to fling values back and forth across suspension points. The whole crate is a giant wad of `unsafe` unfortunately and involves handwritten assembly with custom dwarf CFI directives to boot. Definitely deserves a close eye in review! * The `Store` type has two new methods -- `block_on` and `on_fiber` which bridge between the async and non-async worlds. Lots of unsafe fiddly bits here as we're trying to communicate context pointers between disparate portions of the code. Extra eyes and care in review is greatly appreciated. * The APIs for binding `async` functions are unfortunately pretty ugly in `Func`. This is mostly due to language limitations and compiler bugs (I believe) in Rust. Instead of `Func::wrap` we have a `Func::wrapN_async` family of methods, and we've also got a whole bunch of `Func::getN_async` methods now too. It may be worth rethinking the API of `Func` to try to make the documentation page actually grok'able. This isn't super heavily tested but the various test should suffice for engaging hopefully nearly all the infrastructure in one form or another. This is just the start though! [RFC 2]: bytecodealliance/rfcs#2
Configuration menu - View commit details
-
Copy full SHA for c484c1f - Browse repository at this point
Copy the full SHA c484c1fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3d8f26a - Browse repository at this point
Copy the full SHA 3d8f26aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8e78482 - Browse repository at this point
Copy the full SHA 8e78482View commit details -
Configuration menu - View commit details
-
Copy full SHA for 069d02b - Browse repository at this point
Copy the full SHA 069d02bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9260750 - Browse repository at this point
Copy the full SHA 9260750View commit details -
Implement periodically yielding with fuel consumption
This commit implements APIs on `Store` to periodically yield execution of futures through the consumption of fuel. When fuel runs out a future's execution is yielded back to the caller, and then upon resumption fuel is re-injected. The goal of this is to allow cooperative multi-tasking with futures.
Configuration menu - View commit details
-
Copy full SHA for 5797a3f - Browse repository at this point
Copy the full SHA 5797a3fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 24faf2f - Browse repository at this point
Copy the full SHA 24faf2fView commit details -
Save/restore the frame pointer in fiber switching
Turns out this is another caller-saved register!
Configuration menu - View commit details
-
Copy full SHA for ead9567 - Browse repository at this point
Copy the full SHA ead9567View commit details -
Take a leaf out of aarch64's playbook and don't have extra memory to load/store these arguments, instead leverage how `wasmtime_fiber_switch` already loads a bunch of data into registers which we can then immediately start using on a fiber's start without any extra memory accesses.
Configuration menu - View commit details
-
Copy full SHA for 0108943 - Browse repository at this point
Copy the full SHA 0108943View commit details -
Configuration menu - View commit details
-
Copy full SHA for f21b479 - Browse repository at this point
Copy the full SHA f21b479View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4468167 - Browse repository at this point
Copy the full SHA 4468167View commit details -
Configuration menu - View commit details
-
Copy full SHA for bd3c2f1 - Browse repository at this point
Copy the full SHA bd3c2f1View commit details -
Configuration menu - View commit details
-
Copy full SHA for a96b0a9 - Browse repository at this point
Copy the full SHA a96b0a9View commit details -
Configuration menu - View commit details
-
Copy full SHA for f421321 - Browse repository at this point
Copy the full SHA f421321View commit details -
Configuration menu - View commit details
-
Copy full SHA for f68f9a2 - Browse repository at this point
Copy the full SHA f68f9a2View commit details -
Tweak async fuel to eventually run out.
With fuel it's probably best to not provide any way to inject infinite fuel.
Configuration menu - View commit details
-
Copy full SHA for fd5a7da - Browse repository at this point
Copy the full SHA fd5a7daView commit details -
Refactor module instantiation in the runtime.
This commit refactors module instantiation in the runtime to allow for different instance allocation strategy implementations. It adds an `InstanceAllocator` trait with the current implementation put behind the `OnDemandInstanceAllocator` struct. The Wasmtime API has been updated to allow a `Config` to have an instance allocation strategy set which will determine how instances get allocated. This change is in preparation for an alternative *pooling* instance allocator that can reserve all needed host process address space in advance. This commit also makes changes to the `wasmtime_environ` crate to represent compiled modules in a way that reduces copying at instantiation time.
Configuration menu - View commit details
-
Copy full SHA for 32a3ff7 - Browse repository at this point
Copy the full SHA 32a3ff7View commit details -
Allow instance allocators control over module compilation.
This commit introduces two new methods on `InstanceAllocator`: * `validate_module` - this method is used to validate a module after translation but before compilation. It will be used for the upcoming pooling allocator to ensure a module being compiled adheres to the limits of the allocator. * `adjust_tunables` - this method is used to adjust the `Tunables` given the JIT compiler. The pooling allocator will use this to force all memories to be static during compilation.
Configuration menu - View commit details
-
Copy full SHA for 9bbd982 - Browse repository at this point
Copy the full SHA 9bbd982View commit details -
Refactor runtime
Table
to support static storage.This commit refactors `Table` in the runtime such that it can be created from a pointer to existing table data. The current `Vec` backing of the `Table` is considered to be "dynamic" storage. This will be used for the upcoming pooling allocator where table memory is managed externally to the instance. The `table.copy` implementation was improved to use slice primitives for doing the copying. Fixes bytecodealliance#983.
Configuration menu - View commit details
-
Copy full SHA for 2980ed6 - Browse repository at this point
Copy the full SHA 2980ed6View commit details -
Store memories and tables on Instance as PrimaryMap.
This commit changes how memories and tables are stored in `Instance`. Previously, the memories and tables were stored as a `BoxedSlice`. Storing it this way requires an allocation to change the length of the memories and tables, which is desirable for a pooling instance allocator that is reusing an `Instance` structure for a new instantiation. By storing it instead as `PrimaryMap`, the memories and tables can be resized without any allocations (the capacity of these maps will always be the configured limits of the pooling allocator).
Configuration menu - View commit details
-
Copy full SHA for a0704a2 - Browse repository at this point
Copy the full SHA a0704a2View commit details -
Change how Instance stores instantiated memories in the runtime.
This commit changes `Instance` such that memories can be stored statically, with just a base pointer, size, maximum, and a callback to make memory accessible. Previously the memories were being stored as boxed trait objects, which would require the pooling allocator to do some unpleasant things to avoid allocations. With this change, the pooling allocator can simply define a memory for the instance without using a trait object.
Configuration menu - View commit details
-
Copy full SHA for 3c63a49 - Browse repository at this point
Copy the full SHA 3c63a49View commit details -
Ensure default allocator is used for instance deallocation.
Handles created with `create_handle` need to be deallocated with the default (on-demand) instance allocator. This commit changes Store such that handles can be added with a flag that is used to force deallocation via the default instance allocator when the Store is dropped.
Configuration menu - View commit details
-
Copy full SHA for 04f814b - Browse repository at this point
Copy the full SHA 04f814bView commit details -
Only treat a memory as static when the minimum is also within bounds.
With the change to artificially limit unbounded memories based on Tunables, it's possible to hit the assert where the minimum might exceed the static memory bound. This commit removes the assert in favor of a check to see if the minimum also fits within the static memory bound. It also corrects the maximum bounding to ensure the minimum between the memory's maximum and the configured maximum is used. If it does not fit, the memory will be treated as dynamic. In the case of the pooling instance allocator, the bounds will be checked again during translation and an appropriate error will be returned as dynamic memories are not supported for that allocator.
Configuration menu - View commit details
-
Copy full SHA for 84e3bcd - Browse repository at this point
Copy the full SHA 84e3bcdView commit details
Commits on Feb 5, 2021
-
Implement allocating fiber stacks for an instance allocator.
This commit implements allocating fiber stacks in an instance allocator. The on-demand instance allocator doesn't support custom stacks, so the implementation will use the allocation from `wasmtime-fiber` for the fiber stacks. In the future, the pooling instance allocator will return custom stacks to use on Linux and macOS. On Windows, the native fiber implementation will always be used.
Configuration menu - View commit details
-
Copy full SHA for 3107349 - Browse repository at this point
Copy the full SHA 3107349View commit details