Merge pull request #2301 from alexcrichton/no-name-alloc

Avoid allocations in trampoline shims
This commit is contained in:
Nick Fitzgerald
2020-10-18 13:34:08 -07:00
committed by GitHub
5 changed files with 11 additions and 11 deletions

View File

@@ -230,7 +230,7 @@ pub fn create_handle_with_function(
let func_id = module.functions.push(sig_id); let func_id = module.functions.push(sig_id);
module module
.exports .exports
.insert("trampoline".to_string(), EntityIndex::Function(func_id)); .insert(String::new(), EntityIndex::Function(func_id));
let trampoline = make_trampoline(isa.as_ref(), &mut code_memory, &mut fn_builder_ctx, &sig); let trampoline = make_trampoline(isa.as_ref(), &mut code_memory, &mut fn_builder_ctx, &sig);
finished_functions.push(trampoline); finished_functions.push(trampoline);
@@ -289,7 +289,7 @@ pub unsafe fn create_handle_with_raw_function(
let func_id = module.functions.push(sig_id); let func_id = module.functions.push(sig_id);
module module
.exports .exports
.insert("trampoline".to_string(), EntityIndex::Function(func_id)); .insert(String::new(), EntityIndex::Function(func_id));
finished_functions.push(func); finished_functions.push(func);
let sig_id = store.register_signature(ft.to_wasm_func_type(), sig); let sig_id = store.register_signature(ft.to_wasm_func_type(), sig);
trampolines.insert(sig_id, trampoline); trampolines.insert(sig_id, trampoline);

View File

@@ -61,7 +61,7 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
let global_id = module.globals.push(global); let global_id = module.globals.push(global);
module module
.exports .exports
.insert("global".to_string(), EntityIndex::Global(global_id)); .insert(String::new(), EntityIndex::Global(global_id));
let handle = create_handle( let handle = create_handle(
module, module,
store, store,
@@ -72,7 +72,7 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
)?; )?;
if let Some(x) = externref_init { if let Some(x) = externref_init {
match handle.lookup("global").unwrap() { match handle.lookup("").unwrap() {
wasmtime_runtime::Export::Global(g) => unsafe { wasmtime_runtime::Export::Global(g) => unsafe {
*(*g.definition).as_externref_mut() = Some(x.inner); *(*g.definition).as_externref_mut() = Some(x.inner);
}, },

View File

@@ -27,7 +27,7 @@ pub fn create_handle_with_memory(
let memory_id = module.memory_plans.push(memory_plan); let memory_id = module.memory_plans.push(memory_plan);
module module
.exports .exports
.insert("memory".to_string(), EntityIndex::Memory(memory_id)); .insert(String::new(), EntityIndex::Memory(memory_id));
create_handle( create_handle(
module, module,

View File

@@ -55,7 +55,7 @@ pub fn generate_func_export(
VMTrampoline, VMTrampoline,
)> { )> {
let (instance, trampoline) = create_handle_with_function(ft, func, store)?; let (instance, trampoline) = create_handle_with_function(ft, func, store)?;
match instance.lookup("trampoline").expect("trampoline export") { match instance.lookup("").expect("trampoline export") {
wasmtime_runtime::Export::Function(f) => Ok((instance, f, trampoline)), wasmtime_runtime::Export::Function(f) => Ok((instance, f, trampoline)),
_ => unreachable!(), _ => unreachable!(),
} }
@@ -72,7 +72,7 @@ pub unsafe fn generate_raw_func_export(
state: Box<dyn Any>, state: Box<dyn Any>,
) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportFunction)> { ) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportFunction)> {
let instance = func::create_handle_with_raw_function(ft, func, trampoline, store, state)?; let instance = func::create_handle_with_raw_function(ft, func, trampoline, store, state)?;
match instance.lookup("trampoline").expect("trampoline export") { match instance.lookup("").expect("trampoline export") {
wasmtime_runtime::Export::Function(f) => Ok((instance, f)), wasmtime_runtime::Export::Function(f) => Ok((instance, f)),
_ => unreachable!(), _ => unreachable!(),
} }
@@ -84,7 +84,7 @@ pub fn generate_global_export(
val: Val, val: Val,
) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportGlobal)> { ) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportGlobal)> {
let instance = create_global(store, gt, val)?; let instance = create_global(store, gt, val)?;
match instance.lookup("global").expect("global export") { match instance.lookup("").expect("global export") {
wasmtime_runtime::Export::Global(g) => Ok((instance, g)), wasmtime_runtime::Export::Global(g) => Ok((instance, g)),
_ => unreachable!(), _ => unreachable!(),
} }
@@ -95,7 +95,7 @@ pub fn generate_memory_export(
m: &MemoryType, m: &MemoryType,
) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportMemory)> { ) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportMemory)> {
let instance = create_handle_with_memory(store, m)?; let instance = create_handle_with_memory(store, m)?;
match instance.lookup("memory").expect("memory export") { match instance.lookup("").expect("memory export") {
wasmtime_runtime::Export::Memory(m) => Ok((instance, m)), wasmtime_runtime::Export::Memory(m) => Ok((instance, m)),
_ => unreachable!(), _ => unreachable!(),
} }
@@ -106,7 +106,7 @@ pub fn generate_table_export(
t: &TableType, t: &TableType,
) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportTable)> { ) -> Result<(StoreInstanceHandle, wasmtime_runtime::ExportTable)> {
let instance = create_handle_with_table(store, t)?; let instance = create_handle_with_table(store, t)?;
match instance.lookup("table").expect("table export") { match instance.lookup("").expect("table export") {
wasmtime_runtime::Export::Table(t) => Ok((instance, t)), wasmtime_runtime::Export::Table(t) => Ok((instance, t)),
_ => unreachable!(), _ => unreachable!(),
} }

View File

@@ -25,7 +25,7 @@ pub fn create_handle_with_table(store: &Store, table: &TableType) -> Result<Stor
let table_id = module.table_plans.push(table_plan); let table_id = module.table_plans.push(table_plan);
module module
.exports .exports
.insert("table".to_string(), EntityIndex::Table(table_id)); .insert(String::new(), EntityIndex::Table(table_id));
create_handle( create_handle(
module, module,