* Improve handling of strings for backtraces Largely avoid storing strings at all in the `wasmtime-*` internal crates, and instead only store strings in a separate global cache specific to the `wasmtime` crate itself. This global cache is inserted and removed from dynamically as modules are created and deallocated, and the global cache is consulted whenever a `Trap` is created to symbolicate any wasm frames. This also avoids the need to thread `module_name` through the jit crates and back, and additionally removes the need for `ModuleSyncString`. * Run rustfmt
74 lines
1.7 KiB
Rust
74 lines
1.7 KiB
Rust
#![allow(missing_docs)]
|
|
|
|
use lazy_static::lazy_static;
|
|
use std::collections::BTreeMap;
|
|
use std::sync::{Arc, RwLock};
|
|
use wasmtime_environ::wasm::FuncIndex;
|
|
|
|
lazy_static! {
|
|
static ref REGISTRY: RwLock<JITFunctionRegistry> = RwLock::new(JITFunctionRegistry::default());
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct JITFunctionTag {
|
|
pub module_id: usize,
|
|
pub func_index: FuncIndex,
|
|
}
|
|
|
|
struct JITFunctionRegistry {
|
|
ranges: BTreeMap<usize, (usize, Arc<JITFunctionTag>)>,
|
|
}
|
|
|
|
impl Default for JITFunctionRegistry {
|
|
fn default() -> Self {
|
|
Self {
|
|
ranges: Default::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl JITFunctionRegistry {
|
|
fn register(&mut self, fn_start: usize, fn_end: usize, tag: JITFunctionTag) {
|
|
self.ranges.insert(fn_end, (fn_start, Arc::new(tag)));
|
|
}
|
|
|
|
fn unregister(&mut self, fn_end: usize) {
|
|
self.ranges.remove(&fn_end);
|
|
}
|
|
|
|
fn find(&self, pc: usize) -> Option<&Arc<JITFunctionTag>> {
|
|
self.ranges
|
|
.range(pc..)
|
|
.next()
|
|
.and_then(|(end, (start, s))| {
|
|
if *start <= pc && pc < *end {
|
|
Some(s)
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
pub fn register(fn_start: usize, fn_end: usize, tag: JITFunctionTag) {
|
|
REGISTRY
|
|
.write()
|
|
.expect("jit function registry lock got poisoned")
|
|
.register(fn_start, fn_end, tag);
|
|
}
|
|
|
|
pub fn unregister(_fn_start: usize, fn_end: usize) {
|
|
REGISTRY
|
|
.write()
|
|
.expect("jit function registry lock got poisoned")
|
|
.unregister(fn_end);
|
|
}
|
|
|
|
pub fn find(pc: usize) -> Option<Arc<JITFunctionTag>> {
|
|
REGISTRY
|
|
.read()
|
|
.expect("jit function registry lock got poisoned")
|
|
.find(pc)
|
|
.cloned()
|
|
}
|