Use Arc instead of Rc

This commit is contained in:
Syrus
2019-12-20 20:33:50 -08:00
parent 097353d0d4
commit c4d70a6b75
12 changed files with 16 additions and 35 deletions

View File

@ -5,7 +5,6 @@ use cranelift_codegen::ir;
use cranelift_entity::EntityRef;
use cranelift_wasm;
use std::sync::Arc;
use std::{cell::RefCell, rc::Rc};
use wasmer_runtime_core::cache::{Artifact, Error as CacheError};
@ -43,7 +42,7 @@ impl Module {
let runnable_module = Caller::new(handler_data, trampolines, func_resolver);
Ok(ModuleInner {
runnable_module: Rc::new(RefCell::new(Box::new(runnable_module))),
runnable_module: Arc::new(Box::new(runnable_module)),
cache_gen,
info,
})

View File

@ -8983,9 +8983,8 @@ impl<'ctx> ModuleCodeGenerator<LLVMFunctionCodeGenerator<'ctx>, LLVMBackend, Cod
LLVMBackend::from_buffer(memory).map_err(CacheError::DeserializeError)?;
Ok(ModuleInner {
runnable_module: Rc::new(RefCell::new(Box::new(backend))),
runnable_module: Arc::new(Box::new(backend)),
cache_gen: Box::new(cache_gen),
info,
})
}

View File

@ -111,7 +111,6 @@ impl LocalBacking {
.map(|index| {
module
.runnable_module
.borrow()
.get_func(&module.info, LocalFuncIndex::new(index))
.unwrap()
.as_ptr() as *const _
@ -381,7 +380,6 @@ impl LocalBacking {
LocalOrImport::Local(local_func_index) => (
module
.runnable_module
.borrow()
.get_func(&module.info, local_func_index)
.unwrap()
.as_ptr()
@ -415,7 +413,6 @@ impl LocalBacking {
LocalOrImport::Local(local_func_index) => (
module
.runnable_module
.borrow()
.get_func(&module.info, local_func_index)
.unwrap()
.as_ptr()

View File

@ -18,7 +18,6 @@ use std::fmt;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::{Arc, RwLock};
use std::{cell::RefCell, rc::Rc};
use wasmparser::{self, WasmDecoder};
use wasmparser::{Operator, Type as WpType};
@ -250,7 +249,7 @@ impl<
})?;
Ok(ModuleInner {
cache_gen,
runnable_module: Rc::new(RefCell::new(Box::new(exec_context))),
runnable_module: Arc::new(Box::new(exec_context)),
info: Arc::try_unwrap(info).unwrap().into_inner().unwrap(),
})
}

View File

@ -289,7 +289,7 @@ extern "C" fn signal_trap_handler(
CURRENT_CODE_VERSIONS.with(|versions| {
let versions = versions.borrow();
for v in versions.iter() {
let runnable_module = v.runnable_module.borrow();
let runnable_module = &v.runnable_module;
let magic_size =
if let Some(x) = runnable_module.get_inline_breakpoint_size(ARCH) {
x

View File

@ -103,7 +103,6 @@ impl Instance {
LocalOrImport::Local(local_func_index) => instance
.module
.runnable_module
.borrow()
.get_func(&instance.module.info, local_func_index)
.unwrap(),
LocalOrImport::Import(import_func_index) => NonNull::new(
@ -133,7 +132,6 @@ impl Instance {
let wasm_trampoline = instance
.module
.runnable_module
.borrow()
.get_trampoline(&instance.module.info, sig_index)
.expect("wasm trampoline");
@ -149,7 +147,7 @@ impl Instance {
/// Load an `Instance` using the given loader.
pub fn load<T: Loader>(&self, loader: T) -> ::std::result::Result<T::Instance, T::Error> {
loader.load(
&**self.module.runnable_module.borrow(),
&**self.module.runnable_module,
&self.module.info,
unsafe { &*self.inner.vmctx },
)
@ -219,7 +217,6 @@ impl Instance {
let func_wasm_inner = self
.module
.runnable_module
.borrow()
.get_trampoline(&self.module.info, sig_index)
.unwrap();
@ -227,7 +224,6 @@ impl Instance {
LocalOrImport::Local(local_func_index) => (
self.module
.runnable_module
.borrow()
.get_func(&self.module.info, local_func_index)
.unwrap(),
None,
@ -368,7 +364,7 @@ impl Instance {
call_func_with_index(
&self.module.info,
&**self.module.runnable_module.borrow(),
&**self.module.runnable_module,
&self.inner.import_backing,
self.inner.vmctx,
func_index,
@ -467,7 +463,6 @@ impl InstanceInner {
LocalOrImport::Local(local_func_index) => (
module
.runnable_module
.borrow()
.get_func(&module.info, local_func_index)
.expect("broken invariant, func resolver not synced with module.exports")
.cast()
@ -797,7 +792,7 @@ impl<'a> DynFunc<'a> {
call_func_with_index(
&self.module.info,
&**self.module.runnable_module.borrow(),
&**self.module.runnable_module,
&self.instance_inner.import_backing,
self.instance_inner.vmctx,
self.func_index,
@ -819,7 +814,6 @@ impl<'a> DynFunc<'a> {
LocalOrImport::Local(local_func_index) => self
.module
.runnable_module
.borrow()
.get_func(&self.module.info, local_func_index)
.unwrap()
.as_ptr(),

View File

@ -19,14 +19,12 @@ use crate::backend::CacheGen;
use indexmap::IndexMap;
use std::collections::HashMap;
use std::sync::Arc;
use std::{cell::RefCell, rc::Rc};
/// This is used to instantiate a new WebAssembly module.
#[doc(hidden)]
pub struct ModuleInner {
pub runnable_module: Rc<RefCell<Box<dyn RunnableModule>>>,
pub runnable_module: Arc<Box<dyn RunnableModule>>,
pub cache_gen: Box<dyn CacheGen>,
pub info: ModuleInfo,
}

View File

@ -5,7 +5,7 @@
use crate::backend::{Backend, RunnableModule};
use std::collections::BTreeMap;
use std::ops::Bound::{Included, Unbounded};
use std::{cell::RefCell, rc::Rc};
use std::sync::Arc;
/// An index to a register
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
@ -189,7 +189,7 @@ pub struct CodeVersion {
pub backend: Backend,
/// `RunnableModule` for this code version.
pub runnable_module: Rc<RefCell<Box<dyn RunnableModule>>>,
pub runnable_module: Arc<Box<dyn RunnableModule>>,
}
impl ModuleStateMap {

View File

@ -14,7 +14,6 @@ use crate::vm::Ctx;
use std::cell::Cell;
use std::sync::{Arc, Mutex};
use std::{cell::RefCell, rc::Rc};
struct Defer<F: FnOnce()>(Option<F>);
impl<F: FnOnce()> Drop for Defer<F> {
@ -212,7 +211,7 @@ pub unsafe fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
baseline.context_mut().local_functions = optimized.context_mut().local_functions;
}
// Assuming we do not want to do breakpoint-based debugging on optimized backends.
let breakpoints = baseline.module.runnable_module.borrow().get_breakpoints();
let breakpoints = baseline.module.runnable_module.get_breakpoints();
let ctx = baseline.context_mut() as *mut _;
let ret = with_ctx(ctx, || {
if let Some(image) = resume_image.take() {

View File

@ -515,7 +515,7 @@ macro_rules! impl_traits {
// At this point, there is an error that needs to
// be trapped.
unsafe {
(&*vmctx.module).runnable_module.borrow().do_early_trap(err)
(&*vmctx.module).runnable_module.do_early_trap(err)
}
}
@ -627,7 +627,7 @@ macro_rules! impl_traits {
// At this point, there is an error that needs to
// be trapped.
unsafe {
(&*vmctx.module).runnable_module.borrow().do_early_trap(err)
(&*vmctx.module).runnable_module.do_early_trap(err)
}
}

View File

@ -457,7 +457,6 @@ impl Ctx {
let sig_index = SigRegistry.lookup_sig_index(signature.clone());
runnable
.borrow()
.get_trampoline(&module.info, sig_index)
.expect("wasm trampoline")
};
@ -976,7 +975,6 @@ mod vm_ctx_tests {
use crate::module::{ModuleInfo, ModuleInner, StringTable};
use crate::structures::Map;
use std::ffi::c_void;
use std::{cell::RefCell, rc::Rc};
struct TestData {
x: u32,
@ -1097,7 +1095,7 @@ mod vm_ctx_tests {
}
ModuleInner {
runnable_module: Rc::new(RefCell::new(Box::new(Placeholder))),
runnable_module: Arc::new(Box::new(Placeholder)),
cache_gen: Box::new(Placeholder),
info: ModuleInfo {
memories: Map::new(),

View File

@ -20,7 +20,6 @@ use std::{
sync::{Arc, RwLock},
usize,
};
use std::{cell::RefCell, rc::Rc};
use wasmer_runtime_core::{
backend::{
sys::{Memory, Protect},
@ -368,7 +367,7 @@ impl RunnableModule for X64ExecutionContext {
user_error: *mut Option<Box<dyn Any + Send>>,
num_params_plus_one: Option<NonNull<c_void>>,
) -> bool {
let rm: &Box<dyn RunnableModule> = &(&*(*ctx).module).runnable_module.borrow();
let rm: &Box<dyn RunnableModule> = &(&*(*ctx).module).runnable_module;
let args =
slice::from_raw_parts(args, num_params_plus_one.unwrap().as_ptr() as usize - 1);
@ -918,11 +917,10 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
msm: cache_image.msm,
};
Ok(ModuleInner {
runnable_module: Rc::new(RefCell::new(Box::new(ec))),
runnable_module: Arc::new(Box::new(ec)),
cache_gen: Box::new(SinglepassCache {
buffer: Arc::from(memory.as_slice().to_vec().into_boxed_slice()),
}),
info,
})
}