Store memories and tables on Instance as PrimaryMap.
This commit changes how memories and tables are stored in `Instance`. Previously, the memories and tables were stored as a `BoxedSlice`. Storing it this way requires an allocation to change the length of the memories and tables, which is desirable for a pooling instance allocator that is reusing an `Instance` structure for a new instantiation. By storing it instead as `PrimaryMap`, the memories and tables can be resized without any allocations (the capacity of these maps will always be the configured limits of the pooling allocator).
This commit is contained in:
@@ -24,7 +24,7 @@ use std::ptr::NonNull;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{mem, ptr, slice};
|
use std::{mem, ptr, slice};
|
||||||
use wasmtime_environ::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, EntitySet};
|
use wasmtime_environ::entity::{packed_option::ReservedValue, EntityRef, EntitySet, PrimaryMap};
|
||||||
use wasmtime_environ::wasm::{
|
use wasmtime_environ::wasm::{
|
||||||
DataIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, EntityIndex,
|
DataIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, ElemIndex, EntityIndex,
|
||||||
FuncIndex, GlobalIndex, MemoryIndex, TableElementType, TableIndex,
|
FuncIndex, GlobalIndex, MemoryIndex, TableElementType, TableIndex,
|
||||||
@@ -51,10 +51,10 @@ pub(crate) struct Instance {
|
|||||||
offsets: VMOffsets,
|
offsets: VMOffsets,
|
||||||
|
|
||||||
/// WebAssembly linear memory data.
|
/// WebAssembly linear memory data.
|
||||||
memories: BoxedSlice<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>,
|
memories: PrimaryMap<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>,
|
||||||
|
|
||||||
/// WebAssembly table data.
|
/// WebAssembly table data.
|
||||||
tables: BoxedSlice<DefinedTableIndex, Table>,
|
tables: PrimaryMap<DefinedTableIndex, Table>,
|
||||||
|
|
||||||
/// Stores the dropped passive element segments in this instantiation by index.
|
/// Stores the dropped passive element segments in this instantiation by index.
|
||||||
/// If the index is present in the set, the segment has been dropped.
|
/// If the index is present in the set, the segment has been dropped.
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ use std::ptr::{self, NonNull};
|
|||||||
use std::slice;
|
use std::slice;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wasmtime_environ::entity::{
|
use wasmtime_environ::entity::{packed_option::ReservedValue, EntityRef, EntitySet, PrimaryMap};
|
||||||
packed_option::ReservedValue, BoxedSlice, EntityRef, EntitySet, PrimaryMap,
|
|
||||||
};
|
|
||||||
use wasmtime_environ::wasm::{
|
use wasmtime_environ::wasm::{
|
||||||
DefinedFuncIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, GlobalInit, SignatureIndex,
|
DefinedFuncIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, GlobalInit, SignatureIndex,
|
||||||
TableElementType, WasmType,
|
TableElementType, WasmType,
|
||||||
@@ -285,20 +283,20 @@ impl OnDemandInstanceAllocator {
|
|||||||
Self { mem_creator }
|
Self { mem_creator }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_tables(module: &Module) -> BoxedSlice<DefinedTableIndex, Table> {
|
fn create_tables(module: &Module) -> PrimaryMap<DefinedTableIndex, Table> {
|
||||||
let num_imports = module.num_imported_tables;
|
let num_imports = module.num_imported_tables;
|
||||||
let mut tables: PrimaryMap<DefinedTableIndex, _> =
|
let mut tables: PrimaryMap<DefinedTableIndex, _> =
|
||||||
PrimaryMap::with_capacity(module.table_plans.len() - num_imports);
|
PrimaryMap::with_capacity(module.table_plans.len() - num_imports);
|
||||||
for table in &module.table_plans.values().as_slice()[num_imports..] {
|
for table in &module.table_plans.values().as_slice()[num_imports..] {
|
||||||
tables.push(Table::new_dynamic(table));
|
tables.push(Table::new_dynamic(table));
|
||||||
}
|
}
|
||||||
tables.into_boxed_slice()
|
tables
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_memories(
|
fn create_memories(
|
||||||
&self,
|
&self,
|
||||||
module: &Module,
|
module: &Module,
|
||||||
) -> Result<BoxedSlice<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>, InstantiationError>
|
) -> Result<PrimaryMap<DefinedMemoryIndex, Box<dyn RuntimeLinearMemory>>, InstantiationError>
|
||||||
{
|
{
|
||||||
let creator = self
|
let creator = self
|
||||||
.mem_creator
|
.mem_creator
|
||||||
@@ -314,7 +312,7 @@ impl OnDemandInstanceAllocator {
|
|||||||
.map_err(InstantiationError::Resource)?,
|
.map_err(InstantiationError::Resource)?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(memories.into_boxed_slice())
|
Ok(memories)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_table_init_bounds(instance: &Instance) -> Result<(), InstantiationError> {
|
fn check_table_init_bounds(instance: &Instance) -> Result<(), InstantiationError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user