Move trap information to a section of the compiled image (#3241)
This commit moves the `traps` field of `FunctionInfo` into a section of the compiled artifact produced by Cranelift. This section is quite large and when previously encoded/decoded with `bincode` this can take quite some time to process. Traps are expected to be relatively rare and it's not necessarily the right tradeoff to spend so much time serializing/deserializing this data, so this commit offloads the section into a custom-encoded binary format located elsewhere in the compiled image. This is similar to #3240 in its goal which is to move very large pieces of metadata to their own sections to avoid decoding anything when we load a precompiled modules. This also has a small benefit that it's slightly more efficient storage for the trap information too, but that's a negligible benefit. This is part of #3230 to make loading modules fast.
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
||||
collections::BTreeMap,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use wasmtime_environ::{EntityRef, FilePos, StackMap, TrapInformation};
|
||||
use wasmtime_environ::{EntityRef, FilePos, StackMap, TrapCode};
|
||||
use wasmtime_jit::CompiledModule;
|
||||
use wasmtime_runtime::{ModuleInfo, VMCallerCheckedAnyfunc, VMTrampoline};
|
||||
|
||||
@@ -262,9 +262,9 @@ impl GlobalModuleRegistry {
|
||||
}
|
||||
|
||||
/// Fetches trap information about a program counter in a backtrace.
|
||||
pub(crate) fn lookup_trap_info(&self, pc: usize) -> Option<&TrapInformation> {
|
||||
pub(crate) fn lookup_trap_code(&self, pc: usize) -> Option<TrapCode> {
|
||||
let (module, offset) = self.module(pc)?;
|
||||
module.lookup_trap_info(offset)
|
||||
wasmtime_environ::lookup_trap_code(module.module.trap_data(), offset)
|
||||
}
|
||||
|
||||
/// Registers a new region of code, described by `(start, end)` and with
|
||||
@@ -371,17 +371,6 @@ impl GlobalRegisteredModule {
|
||||
symbols,
|
||||
})
|
||||
}
|
||||
|
||||
/// Fetches trap information about a program counter in a backtrace.
|
||||
pub fn lookup_trap_info(&self, text_offset: usize) -> Option<&TrapInformation> {
|
||||
let (index, func_offset) = self.module.func_by_text_offset(text_offset)?;
|
||||
let info = self.module.func_info(index);
|
||||
let idx = info
|
||||
.traps
|
||||
.binary_search_by_key(&func_offset, |info| info.code_offset)
|
||||
.ok()?;
|
||||
Some(&info.traps[idx])
|
||||
}
|
||||
}
|
||||
|
||||
/// Description of a frame in a backtrace for a [`Trap`].
|
||||
|
||||
@@ -172,8 +172,7 @@ impl Trap {
|
||||
} => {
|
||||
let mut code = GlobalModuleRegistry::with(|modules| {
|
||||
modules
|
||||
.lookup_trap_info(pc)
|
||||
.map(|info| info.trap_code)
|
||||
.lookup_trap_code(pc)
|
||||
.unwrap_or(EnvTrapCode::StackOverflow)
|
||||
});
|
||||
if maybe_interrupted && code == EnvTrapCode::StackOverflow {
|
||||
|
||||
Reference in New Issue
Block a user