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

wasmtime: Overhaul trampolines #6262

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ Unreleased.

### Changed

* Overhauled the way that Wasmtime calls into Wasm and Wasm calls back out to
the host. Instead of chaining together trampolines to convert between calling
conventions, we now represent `funcref`s with multiple function pointers, one
per calling convention. This paves the way for supporting Wasm tail calls and
also results in ~10% speed ups to a variety of function call benchmarks,
however there are some slight compiled Wasm module code size regressions
(which can be alleviated by disabling optional `.eh_frame`
generation). Additionally, in the C API the `wasmtime_func_call_unchecked`
function gained one more parameter, which is the capacity of the
args-and-results
buffer. [#6262](https://github.com/bytecodealliance/wasmtime/pull/6262)

--------------------------------------------------------------------------------

## 8.0.0
Expand Down
2 changes: 1 addition & 1 deletion benches/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn bench_host_to_wasm<Params, Results>(
space[i] = param.to_raw(&mut *store);
}
untyped
.call_unchecked(&mut *store, space.as_mut_ptr())
.call_unchecked(&mut *store, space.as_mut_ptr(), space.len())
.unwrap();
for (i, expected) in results.iter().enumerate() {
assert_vals_eq(
Expand Down
8 changes: 8 additions & 0 deletions benches/instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ fn bench_sequential(c: &mut Criterion, path: &Path) {
panic!("failed to load benchmark `{}`: {:?}", path.display(), e)
});
let mut linker = Linker::new(&engine);
// Add these imports so we can benchmark instantiation of Sightglass
// benchmark programs.
linker.func_wrap("bench", "start", || {}).unwrap();
linker.func_wrap("bench", "end", || {}).unwrap();
fitzgen marked this conversation as resolved.
Show resolved Hide resolved
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
let pre = linker
.instantiate_pre(&module)
Expand Down Expand Up @@ -74,6 +78,10 @@ fn bench_parallel(c: &mut Criterion, path: &Path) {
let module =
Module::from_file(&engine, path).expect("failed to load WASI example module");
let mut linker = Linker::new(&engine);
// Add these imports so we can benchmark instantiation of Sightglass
// benchmark programs.
linker.func_wrap("bench", "start", || {}).unwrap();
linker.func_wrap("bench", "end", || {}).unwrap();
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
let pre = Arc::new(
linker
Expand Down
Empty file modified cranelift/codegen/meta/src/shared/instructions.rs
100755 → 100644
Empty file.
3 changes: 3 additions & 0 deletions crates/c-api/include/wasmtime/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_func_call(
*
* * The `args_and_results` pointer has enough space to hold all the parameters
* and all the results (but not at the same time).
* * The `args_and_results_len` contains the length of the `args_and_results`
* buffer.
* * Parameters must all be configured as if they were the correct type.
* * Values such as `externref` and `funcref` are valid within the store being
* called.
Expand All @@ -245,6 +247,7 @@ WASM_API_EXTERN wasmtime_error_t *wasmtime_func_call_unchecked(
wasmtime_context_t *store,
const wasmtime_func_t *func,
wasmtime_val_raw_t *args_and_results,
size_t args_and_results_len,
fitzgen marked this conversation as resolved.
Show resolved Hide resolved
wasm_trap_t **trap
);

Expand Down
3 changes: 2 additions & 1 deletion crates/c-api/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,10 @@ pub unsafe extern "C" fn wasmtime_func_call_unchecked(
store: CStoreContextMut<'_>,
func: &Func,
args_and_results: *mut ValRaw,
args_and_results_len: usize,
trap_ret: &mut *mut wasm_trap_t,
) -> Option<Box<wasmtime_error_t>> {
match func.call_unchecked(store, args_and_results) {
match func.call_unchecked(store, args_and_results, args_and_results_len) {
Ok(()) => None,
Err(trap) => store_err(trap, trap_ret),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cranelift-shared/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'a> ModuleTextBuilder<'a> {
// loop could also be updated to forward the relocation to
// the final object file as well.
panic!(
"unresolved relocation could not be procesed against \
"unresolved relocation could not be processed against \
{index:?}: {r:?}"
);
}
Expand Down
Loading