From f94e2d6bcc461b832b398543f42a20fb81d3d724 Mon Sep 17 00:00:00 2001 From: Syrus Date: Sun, 3 May 2020 19:37:11 -0700 Subject: [PATCH] Improve Tunables memory/table creation --- lib/api/src/externals.rs | 9 +++++++-- lib/api/src/tunables.rs | 6 ++---- lib/jit/src/tunables.rs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/api/src/externals.rs b/lib/api/src/externals.rs index 18629f329..5e684247d 100644 --- a/lib/api/src/externals.rs +++ b/lib/api/src/externals.rs @@ -231,7 +231,9 @@ fn set_table_item( impl Table { pub fn new(store: &Store, ty: TableType, init: Val) -> Result { let item = init.into_checked_anyfunc(store)?; - let table = store.engine().tunables().create_table(ty); + let tunables = store.engine().tunables(); + let table_plan = tunables.table_plan(ty); + let table = tunables.create_table(table_plan); let definition = table.vmtable(); for i in 0..definition.current_elements { @@ -345,7 +347,10 @@ pub struct Memory { impl Memory { pub fn new(store: &Store, ty: MemoryType) -> Memory { - let memory = store.engine().tunables().create_memory(ty).unwrap(); + let tunables = store.engine().tunables(); + let memory_plan = tunables.memory_plan(ty); + let memory = tunables.create_memory(memory_plan).unwrap(); + let definition = memory.vmmemory(); Memory { diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index 1e73824ec..3f948dbed 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -92,14 +92,12 @@ impl wasmer_jit::Tunables for Tunables { } /// Create a memory given a memory type - fn create_memory(&self, memory_type: MemoryType) -> Result { - let plan = self.memory_plan(memory_type); + fn create_memory(&self, plan: MemoryPlan) -> Result { LinearMemory::new(&plan) } /// Create a memory given a memory type - fn create_table(&self, table_type: TableType) -> Table { - let plan = self.table_plan(table_type); + fn create_table(&self, plan: TablePlan) -> Table { Table::new(&plan) } } diff --git a/lib/jit/src/tunables.rs b/lib/jit/src/tunables.rs index 0f5408ef7..d31787e77 100644 --- a/lib/jit/src/tunables.rs +++ b/lib/jit/src/tunables.rs @@ -11,8 +11,8 @@ pub trait Tunables { fn table_plan(&self, table: TableType) -> TablePlan; /// Create a memory given a memory type - fn create_memory(&self, memory_type: MemoryType) -> Result; + fn create_memory(&self, memory_type: MemoryPlan) -> Result; /// Create a memory given a memory type - fn create_table(&self, table_type: TableType) -> Table; + fn create_table(&self, table_type: TablePlan) -> Table; }