Remove the jit_function_registry global state (#915)
* Remove the `jit_function_registry` global state This commit removes on the final pieces of global state in wasmtime today, the `jit_function_registry` module. The purpose of this module is to help translate a native backtrace with native program counters into a wasm backtrace with module names, function names, and wasm module indices. To that end this module retained a global map of function ranges to this metadata information for each compiled function. It turns out that we already had a `NAMES` global in the `wasmtime` crate for symbolicating backtrace addresses, so this commit moves that global into its own file and restructures the internals to account for program counter ranges as well. The general set of changes here are: * Remove `jit_function_registry` * Remove `NAMES` * Create a new `frame_info` module which has a singleton global registering compiled module's frame information. * Update traps to use the `frame_info` module to symbolicate pcs, directly extracting a `FrameInfo` from the module. * Register and unregister information on a module level instead of on a per-function level (at least in terms of locking granluarity). This commit leaves the new `FRAME_INFO` global variable as the only remaining "critical" global variable in `wasmtime`, which only exists due to the API of `Trap` where it doesn't take in any extra context when capturing a stack trace through which we could hang off frame information. I'm thinking though that this is ok, and we can always tweak the API of `Trap` in the future if necessary if we truly need to accomodate this. * Remove a lazy_static dep * Add some comments and restructure
This commit is contained in:
@@ -21,8 +21,7 @@ use wasmtime_environ::{
|
||||
Traps, Tunables, VMOffsets,
|
||||
};
|
||||
use wasmtime_runtime::{
|
||||
jit_function_registry, InstantiationError, SignatureRegistry, TrapRegistration, TrapRegistry,
|
||||
VMFunctionBody,
|
||||
InstantiationError, SignatureRegistry, TrapRegistration, TrapRegistry, VMFunctionBody,
|
||||
};
|
||||
|
||||
/// Select which kind of compilation to use.
|
||||
@@ -51,7 +50,6 @@ pub struct Compiler {
|
||||
isa: Box<dyn TargetIsa>,
|
||||
|
||||
code_memory: CodeMemory,
|
||||
jit_function_ranges: Vec<(usize, usize)>,
|
||||
trap_registry: TrapRegistry,
|
||||
trampoline_park: HashMap<*const VMFunctionBody, *const VMFunctionBody>,
|
||||
signatures: SignatureRegistry,
|
||||
@@ -72,7 +70,6 @@ impl Compiler {
|
||||
Self {
|
||||
isa,
|
||||
code_memory: CodeMemory::new(),
|
||||
jit_function_ranges: Vec::new(),
|
||||
trampoline_park: HashMap::new(),
|
||||
signatures: SignatureRegistry::new(),
|
||||
fn_builder_ctx: FunctionBuilderContext::new(),
|
||||
@@ -83,14 +80,6 @@ impl Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Compiler {
|
||||
fn drop(&mut self) {
|
||||
for (start, end) in self.jit_function_ranges.iter() {
|
||||
jit_function_registry::unregister(*start, *end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
/// Return the target's frontend configuration settings.
|
||||
pub fn frontend_config(&self) -> TargetFrontendConfig {
|
||||
@@ -157,19 +146,6 @@ impl Compiler {
|
||||
|
||||
let trap_registration = register_traps(&allocated_functions, &traps, &self.trap_registry);
|
||||
|
||||
for (i, allocated) in allocated_functions.iter() {
|
||||
let ptr = (*allocated) as *const VMFunctionBody;
|
||||
let body_len = compilation.get(i).body.len();
|
||||
self.jit_function_ranges
|
||||
.push((ptr as usize, ptr as usize + body_len));
|
||||
let func_index = module.func_index(i);
|
||||
let tag = jit_function_registry::JITFunctionTag {
|
||||
module_id: module.id,
|
||||
func_index,
|
||||
};
|
||||
jit_function_registry::register(ptr as usize, ptr as usize + body_len, tag);
|
||||
}
|
||||
|
||||
// Translate debug info (DWARF) only if at least one function is present.
|
||||
let dbg = if debug_data.is_some() && !allocated_functions.is_empty() {
|
||||
let target_config = self.isa.frontend_config();
|
||||
|
||||
Reference in New Issue
Block a user