MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / new

Method new

crates/wasmtime/src/runtime/vm/component.rs:319–356  ·  view source on GitHub ↗

Allocates a new `ComponentInstance + VMComponentContext` pair on the heap with `malloc` and configures it for the `component` specified.

(
        id: ComponentInstanceId,
        component: &Component,
        resource_types: Arc<TryPrimaryMap<ResourceIndex, ResourceType>>,
        imports: &Arc<PrimaryMap<RuntimeImportIndex, RuntimeI

Source from the content-addressed store, hash-verified

317 /// Allocates a new `ComponentInstance + VMComponentContext` pair on the
318 /// heap with `malloc` and configures it for the `component` specified.
319 pub(crate) fn new(
320 id: ComponentInstanceId,
321 component: &Component,
322 resource_types: Arc<TryPrimaryMap<ResourceIndex, ResourceType>>,
323 imports: &Arc<PrimaryMap<RuntimeImportIndex, RuntimeImport>>,
324 store: NonNull<dyn VMStore>,
325 ) -> Result<OwnedComponentInstance, OutOfMemory> {
326 let offsets = VMComponentOffsets::new(HostPtr, component.env_component());
327 let num_instances = component.env_component().num_runtime_component_instances;
328 let mut instance_states = TryPrimaryMap::with_capacity(num_instances.try_into().unwrap())?;
329 for _ in 0..num_instances {
330 instance_states.push(InstanceState::default())?;
331 }
332
333 let instances = TryPrimaryMap::with_capacity(
334 component
335 .env_component()
336 .num_runtime_instances
337 .try_into()
338 .unwrap(),
339 )?;
340
341 let mut ret = OwnedInstance::new(ComponentInstance {
342 id,
343 offsets,
344 instance_states,
345 instances,
346 component: component.clone(),
347 resource_types,
348 imports: imports.clone(),
349 store: VMStoreRawPtr(store),
350 vmctx: OwnedVMContext::new(),
351 })?;
352 unsafe {
353 ret.get_mut().initialize_vmctx();
354 }
355 Ok(ret)
356 }
357
358 #[inline]
359 pub fn vmctx(&self) -> NonNull<VMComponentContext> {

Callers

nothing calls this directly

Calls 10

VMStoreRawPtrClass · 0.85
OkFunction · 0.85
env_componentMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
try_intoMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
initialize_vmctxMethod · 0.45
get_mutMethod · 0.45

Tested by

no test coverage detected