Skip to main content

emit_alloc_fast_path

Function emit_alloc_fast_path 

Source
pub fn emit_alloc_fast_path(
    builder: &mut FunctionBuilder<'_>,
    vmctx_val: Value,
    size: u64,
    gc_trigger_sig: SigRef,
    oom_func: FuncRef,
) -> Value
Expand description

Emit the alloc fast-path as inline Cranelift IR.

This is a bump-pointer allocation:

  1. Load alloc_ptr from VMContext
  2. new_ptr = alloc_ptr + size (8-byte aligned)
  3. If new_ptr > alloc_limit: call gc_trigger (cold path), then retry
  4. Store new_ptr as alloc_ptr
  5. Return old alloc_ptr (start of allocated region)

vmctx_val is the SSA value holding the VMContext pointer. size is the number of bytes to allocate (will be rounded up to 8-byte alignment). gc_trigger_sig is the signature reference for the gc_trigger call.

Returns the SSA value pointing to the start of the allocated memory.