Improve handling of strings for backtraces (#843)
* 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
This commit is contained in:
@@ -23,6 +23,7 @@ use std::collections::HashSet;
|
||||
use std::convert::TryFrom;
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::{mem, ptr, slice};
|
||||
use thiserror::Error;
|
||||
use wasmtime_environ::entity::{BoxedSlice, EntityRef, PrimaryMap};
|
||||
@@ -288,7 +289,7 @@ pub(crate) struct Instance {
|
||||
mmap: Mmap,
|
||||
|
||||
/// The `Module` this `Instance` was instantiated from.
|
||||
module: Rc<Module>,
|
||||
module: Arc<Module>,
|
||||
|
||||
/// Offsets in the `vmctx` region.
|
||||
offsets: VMOffsets,
|
||||
@@ -748,7 +749,7 @@ impl InstanceHandle {
|
||||
|
||||
/// Create a new `InstanceHandle` pointing at a new `Instance`.
|
||||
pub fn new(
|
||||
module: Rc<Module>,
|
||||
module: Arc<Module>,
|
||||
finished_functions: BoxedSlice<DefinedFuncIndex, *const VMFunctionBody>,
|
||||
imports: Imports,
|
||||
data_initializers: &[DataInitializer<'_>],
|
||||
@@ -895,8 +896,8 @@ impl InstanceHandle {
|
||||
}
|
||||
|
||||
/// Return a reference-counting pointer to a module.
|
||||
pub fn module(&self) -> Rc<Module> {
|
||||
self.instance().module.clone()
|
||||
pub fn module(&self) -> &Arc<Module> {
|
||||
&self.instance().module
|
||||
}
|
||||
|
||||
/// Return a reference to a module.
|
||||
@@ -1110,7 +1111,7 @@ fn lookup_by_declaration(
|
||||
}
|
||||
|
||||
fn check_table_init_bounds(instance: &mut Instance) -> Result<(), InstantiationError> {
|
||||
let module = Rc::clone(&instance.module);
|
||||
let module = Arc::clone(&instance.module);
|
||||
for init in &module.table_elements {
|
||||
let start = get_table_init_start(init, instance);
|
||||
let slice = get_table_slice(
|
||||
@@ -1234,7 +1235,7 @@ fn get_table_slice<'instance>(
|
||||
/// Initialize the table memory from the provided initializers.
|
||||
fn initialize_tables(instance: &mut Instance) -> Result<(), InstantiationError> {
|
||||
let vmctx: *mut VMContext = instance.vmctx_mut();
|
||||
let module = Rc::clone(&instance.module);
|
||||
let module = Arc::clone(&instance.module);
|
||||
for init in &module.table_elements {
|
||||
let start = get_table_init_start(init, instance);
|
||||
let slice = get_table_slice(
|
||||
@@ -1311,7 +1312,7 @@ fn create_globals(module: &Module) -> BoxedSlice<DefinedGlobalIndex, VMGlobalDef
|
||||
}
|
||||
|
||||
fn initialize_globals(instance: &mut Instance) {
|
||||
let module = Rc::clone(&instance.module);
|
||||
let module = Arc::clone(&instance.module);
|
||||
let num_imports = module.imported_globals.len();
|
||||
for (index, global) in module.globals.iter().skip(num_imports) {
|
||||
let def_index = module.defined_global_index(index).unwrap();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use wasmtime_environ::ModuleSyncString;
|
||||
use wasmtime_environ::wasm::FuncIndex;
|
||||
|
||||
lazy_static! {
|
||||
static ref REGISTRY: RwLock<JITFunctionRegistry> = RwLock::new(JITFunctionRegistry::default());
|
||||
@@ -11,20 +11,8 @@ lazy_static! {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct JITFunctionTag {
|
||||
pub module_id: ModuleSyncString,
|
||||
pub func_index: usize,
|
||||
pub func_name: ModuleSyncString,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for JITFunctionTag {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(ref module_id) = self.module_id.get() {
|
||||
write!(f, "{}", module_id)?;
|
||||
} else {
|
||||
write!(f, "(module)")?;
|
||||
}
|
||||
write!(f, ":{}", self.func_index)
|
||||
}
|
||||
pub module_id: usize,
|
||||
pub func_index: FuncIndex,
|
||||
}
|
||||
|
||||
struct JITFunctionRegistry {
|
||||
|
||||
Reference in New Issue
Block a user