Generate trampolines based on signatures (#947)

* Generate trampolines based on signatures

Instead of generating a trampoline-per-function generate a
trampoline-per-signature. This should hopefully greatly increase the
cache hit rate on trampolines within a module and avoid generating a
function-per-function.

* Update crates/runtime/src/traphandlers.rs

Co-Authored-By: Sergei Pepyakin <s.pepyakin@gmail.com>

Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
This commit is contained in:
Alex Crichton
2020-02-18 12:32:52 -06:00
committed by GitHub
parent c94cdc7730
commit 16affacafb
5 changed files with 58 additions and 53 deletions

View File

@@ -347,10 +347,14 @@ impl Instance {
&*self.host_state
}
fn invoke_function(&self, index: FuncIndex) -> Result<(), InstantiationError> {
// TODO: Check that the callee's calling convention matches what we expect.
/// Invoke the WebAssembly start function of the instance, if one is present.
fn invoke_start_function(&self) -> Result<(), InstantiationError> {
let start_index = match self.module.start_func {
Some(idx) => idx,
None => return Ok(()),
};
let (callee_address, callee_vmctx) = match self.module.defined_func_index(index) {
let (callee_address, callee_vmctx) = match self.module.defined_func_index(start_index) {
Some(defined_index) => {
let body = *self
.finished_functions
@@ -359,8 +363,8 @@ impl Instance {
(body as *const _, self.vmctx_ptr())
}
None => {
assert_lt!(index.index(), self.module.imported_funcs.len());
let import = self.imported_function(index);
assert_lt!(start_index.index(), self.module.imported_funcs.len());
let import = self.imported_function(start_index);
(import.body, import.vmctx)
}
};
@@ -370,15 +374,6 @@ impl Instance {
.map_err(InstantiationError::StartTrap)
}
/// Invoke the WebAssembly start function of the instance, if one is present.
fn invoke_start_function(&self) -> Result<(), InstantiationError> {
if let Some(start_index) = self.module.start_func {
self.invoke_function(start_index)
} else {
Ok(())
}
}
/// Return the offset from the vmctx pointer to its containing Instance.
pub(crate) fn vmctx_offset() -> isize {
offset_of!(Self, vmctx) as isize