Merge pull request #3738 from cfallin/pooling-affinity

Pooling allocator: add a reuse-affinity policy.
This commit is contained in:
Chris Fallin
2022-02-02 13:11:39 -08:00
committed by GitHub
11 changed files with 724 additions and 129 deletions

View File

@@ -7,7 +7,7 @@ use crate::vmcontext::{
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMGlobalDefinition, VMSharedSignatureIndex,
};
use crate::ModuleMemFds;
use crate::Store;
use crate::{CompiledModuleId, Store};
use anyhow::Result;
use std::alloc;
use std::any::Any;
@@ -35,6 +35,9 @@ pub struct InstanceAllocationRequest<'a> {
/// The module being instantiated.
pub module: Arc<Module>,
/// The unique ID of the module being allocated within this engine.
pub unique_id: Option<CompiledModuleId>,
/// The base address of where JIT functions are located.
pub image_base: usize,
@@ -726,8 +729,14 @@ unsafe impl InstanceAllocator for OnDemandInstanceAllocator {
let host_state = std::mem::replace(&mut req.host_state, Box::new(()));
let mut handle = {
let instance =
Instance::create_raw(&req.module, &*req.wasm_data, memories, tables, host_state);
let instance = Instance::create_raw(
&req.module,
req.unique_id,
&*req.wasm_data,
memories,
tables,
host_state,
);
let layout = instance.alloc_layout();
let instance_ptr = alloc::alloc(layout) as *mut Instance;
if instance_ptr.is_null() {