Sign in

    wasmoon_jit

    Wasmoon-specific JIT integration and native runtime glue

    wasm
    jit
    runtime
    native
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    199

    #wasmoon_jit

    JIT integration and native runtime support for Wasmoon.

    wasmoon_jit connects the compiler pipeline to Wasmoon's runtime. It provides VMContext layouts, native runtime helpers, cwasm artifacts, trampolines, WASI bridge glue, and integration planning for loading generated code.

    #Packages

    • Milky2018/wasmoon_jit: runtime layout, JIT integration planning, trampolines, native glue, runtime symbols, and helper APIs.
    • Milky2018/wasmoon_jit/cwasm: serialized precompiled-code artifacts.

    The current CWASM format records machine-code compilation features, including whether cooperative cancellation safepoints were emitted. Readers accept only the current format version; this prevents callers from assuming cancellation support for older or otherwise incompatible artifacts.
    • Milky2018/wasmoon_jit/perf: optional JIT performance metrics.
    • Milky2018/wasmoon_jit/jit_ffi: native stubs used by the JIT runtime.

    #When to use it

    Use wasmoon_jit when integrating generated code with the Wasmoon runtime, including VMContext layout, runtime helper symbols, trampolines, cwasm artifacts, and native glue.

    #Example: plan MilkIR through the Wasmoon JIT pipeline

    This API runs a MilkIR function through target lowering, register allocation, and emission, then returns the generated bytes and runtime integration data.

    ///|
    test "plan a small MilkIR function for x64 JIT integration" {
    let signature = @milkir.Signature::Signature([I64, I64], [I64])
    let milk = @milkir.Function::with_signature("add64", signature)
    let lhs = milk.param(0).unwrap()
    let rhs = milk.param(1).unwrap()
    let sum = milk.new_value(I64)
    let entry = milk.new_block([])
    entry.append_inst(milk.new_inst(Scalar(IntBinary(Add)), [lhs, rhs], [sum]))
    entry.set_terminator(Return([sum]))
    let plan = plan_milkir_integration_for_target(milk, X64)
    inspect(plan.entry_symbol, content="add64")
    debug_inspect(plan.target, content="X64")
    inspect(plan.object.get_bytes().length() > 0, content="true")
    inspect(
    native_glue_covers_jit_ffi_stubs(glue=plan.native_glue),
    content="true",
    )
    }

    #Example: serialize a cwasm artifact

    The cwasm package stores compiled functions, imports, memories, data segments, and target metadata in a portable artifact format.

    ///|
    test "serialize and restore a precompiled module" {
    let mod_ = @cwasm.PrecompiledModule::PrecompiledModule(AArch64)
    mod_.add_type([TYPE_I32], [TYPE_I32])
    mod_.add_import("env", "host_inc", 1, 1)
    let entry = @cwasm.CompiledEntry::CompiledEntry(0, "inc", [0xc3], 0, 0, 1, 1)
    mod_.add_function(entry)
    let encoded = mod_.serialize()
    let decoded = @cwasm.deserialize(encoded)
    debug_inspect(decoded.target, content="AArch64")
    inspect(decoded.import_count(), content="1")
    inspect(decoded.function_count(), content="1")
    }

    #Compiler pipeline

    JIT planning composes milkir, milkir_machv, the selected target package, machv_regalloc, and machv_emit. The resulting plan adds the VMContext, runtime symbols, trampolines, and native glue needed to install and invoke the code in Wasmoon.

    CHeapError

    pub(all) suberror CHeapError {
    OutOfBoundsArrayAccess
    NullReference
    OutOfMemory
    }

    CHeap error types for runtime errors

    DirectCallStubInstallError

    pub suberror DirectCallStubInstallError {
    UnsupportedDirectCallStubTarget(pseudo_idx~ : Int, code_size~ : Int)
    DirectCallStubAllocationFailed(pseudo_idx~ : Int, code_size~ : Int)
    } derive(Eq,
    Debug
    )

    GCSetupError

    pub suberror GCSetupError {
    MissingJITContext
    InvalidFuncCount(num_funcs~ : Int)
    FuncTypeIndicesLengthMismatch(func_type_indices_len~ : Int, num_funcs~ : Int)
    MissingFunctionTableContext(num_funcs~ : Int)
    } derive(
    Debug
    )

    Error for invalid JIT GC setup context

    HostcallImportTrampolineError

    pub suberror HostcallImportTrampolineError {
    UnsupportedHostcallImportTrampoline(message~ : String)
    } derive(Eq,
    Debug
    )

    JitPipelineError

    pub suberror JitPipelineError {
    PipelineFailure(message~ : String)
    } derive(Eq,
    Debug
    )

    LinkError

    pub suberror LinkError {
    UnknownRuntimeSymbol(String)
    } derive(Eq,
    Debug
    )

    impl Show for LinkError

    BacktraceFrame

    pub struct BacktraceFrame {
    pc : Int64
    name : String
    offset : Int64
    func_idx : Int
    }

    Backtrace frame

    CHeap

    pub struct CHeap {
    ptr : Int64
    } derive(
    Debug
    )

    C-managed GC Heap The heap is automatically freed when this object is garbage collected.

    CHeap::CHeap

    fn CHeap::CHeap(capacity? : Int) -> CHeap

    Create a new C heap with the given initial capacity

    CHeap::alloc_array

    fn CHeap::alloc_array(self : CHeap, type_idx : Int, len : Int, init_value :
    Value
    ) -> Int raise CHeapError

    Allocate a new array with initial value Returns gc_ref (0-based index for external use)

    CHeap::alloc_array_from_values

    fn CHeap::alloc_array_from_values(self : CHeap, type_idx : Int, elements : Array[
    Value
    ]) -> Int raise CHeapError

    Allocate a new array from existing values Returns gc_ref (0-based index for external use)

    CHeap::alloc_struct

    fn CHeap::alloc_struct(self : CHeap, type_idx : Int, fields : Array[
    Value
    ]) -> Int raise CHeapError

    Allocate a new struct Returns gc_ref (0-based index for external use)

    CHeap::array_copy

    fn CHeap::array_copy(self : CHeap, dst_idx : Int, dst_offset : Int, src_idx : Int, src_offset : Int, count : Int) -> Unit raise CHeapError

    Copy array elements

    CHeap::array_fill

    fn CHeap::array_fill(self : CHeap, array_idx : Int, offset : Int, value :
    Value
    , count : Int) -> Unit raise CHeapError

    Fill array elements with a value

    CHeap::array_get

    fn CHeap::array_get(self : CHeap, array_idx : Int, elem_idx : Int, elem_type :
    ValueType
    ) ->
    Value
    raise CHeapError

    Get an array element

    CHeap::array_len

    fn CHeap::array_len(self : CHeap, array_idx : Int) -> Int

    Get array length

    CHeap::array_set

    fn CHeap::array_set(self : CHeap, array_idx : Int, elem_idx : Int, value :
    Value
    ) -> Unit raise CHeapError

    Set an array element

    CHeap::collect

    fn CHeap::collect(self : CHeap, roots : Array[
    Value
    ]) -> Int

    Perform garbage collection with given roots Returns the number of objects collected

    CHeap::free

    fn CHeap::free(self : CHeap) -> Unit

    Free the C heap (called explicitly if needed before GC)

    CHeap::get_barrier_writes

    fn CHeap::get_barrier_writes(self : CHeap) -> Int

    Get total number of write-barrier calls recorded

    CHeap::get_base

    fn CHeap::get_base(self : CHeap) -> Int64

    Get heap base pointer (for JIT inline access)

    CHeap::get_capacity

    fn CHeap::get_capacity(self : CHeap) -> Int64

    Get heap capacity (total allocated bytes)

    CHeap::get_kind

    fn CHeap::get_kind(self : CHeap, idx : Int) -> Int

    Get the kind of an object (1=struct, 2=array)

    CHeap::get_object_count

    fn CHeap::get_object_count(self : CHeap) -> Int

    Get number of objects in heap

    CHeap::get_offset

    fn CHeap::get_offset(self : CHeap, idx : Int) -> Int

    Get object offset in heap (for JIT inline access)

    CHeap::get_ptr

    fn CHeap::get_ptr(self : CHeap) -> Int64

    Get the raw C pointer (for JIT)

    CHeap::get_size

    fn CHeap::get_size(self : CHeap) -> Int64

    Get current heap size (bytes used)

    CHeap::get_total_allocations

    fn CHeap::get_total_allocations(self : CHeap) -> Int

    Get total number of allocations since heap creation

    CHeap::get_total_collections

    fn CHeap::get_total_collections(self : CHeap) -> Int

    Get total number of GC cycles performed

    CHeap::get_type_idx

    fn CHeap::get_type_idx(self : CHeap, idx : Int) -> Int

    Get the type index of an object

    CHeap::get_usage_ratio

    fn CHeap::get_usage_ratio(self : CHeap) -> Double

    Get heap usage ratio (0.0 to 1.0)

    CHeap::is_array

    fn CHeap::is_array(self : CHeap, idx : Int) -> Bool

    Check if this is an array

    CHeap::is_struct

    fn CHeap::is_struct(self : CHeap, idx : Int) -> Bool

    Check if this is a struct

    CHeap::is_valid

    fn CHeap::is_valid(self : CHeap, idx : Int) -> Bool

    Check if an object reference is valid

    CHeap::should_collect

    fn CHeap::should_collect(self : CHeap, threshold? : Double) -> Bool

    Check if GC should be triggered based on heap usage Default threshold is 75% of capacity

    CHeap::struct_get

    fn CHeap::struct_get(self : CHeap, struct_idx : Int, field_idx : Int, field_type :
    ValueType
    ) ->
    Value

    Get a struct field value

    CHeap::struct_set

    fn CHeap::struct_set(self : CHeap, struct_idx : Int, field_idx : Int, value :
    Value
    ) -> Unit

    Set a struct field value

    CHeap::verify

    fn CHeap::verify(self : CHeap, verbose? : Bool) -> Bool

    Verify heap invariants (for debugging)

    CallCounter

    pub(all) struct CallCounter {
    counts : Map[Int, Int]
    total_calls : Int
    }

    Stores call counts for each function

    CallCounter::CallCounter

    fn CallCounter::CallCounter() -> CallCounter

    CallCounter::clear

    fn CallCounter::clear(self : CallCounter) -> Unit

    Clear all counters

    CallCounter::get_count

    fn CallCounter::get_count(self : CallCounter, func_idx : Int) -> Int

    Get the call count for a function

    CallCounter::increment

    fn CallCounter::increment(self : CallCounter, func_idx : Int) -> Int

    Increment the call count for a function

    CallCounter::reset

    fn CallCounter::reset(self : CallCounter, func_idx : Int) -> Unit

    Reset counter for a specific function

    CallCounter::total

    fn CallCounter::total(self : CallCounter) -> Int

    Get total number of calls tracked

    CallCounter::unique_functions

    fn CallCounter::unique_functions(self : CallCounter) -> Int

    Get the number of unique functions called

    CodeCache

    type CodeCache

    impl Show for CodeCache

    CodeCache::CodeCache

    fn CodeCache::CodeCache(max_size : Int) -> CodeCache

    CodeCache::clear

    fn CodeCache::clear(self : CodeCache) -> Unit

    Clear all cached functions

    CodeCache::contains

    fn CodeCache::contains(self : CodeCache, func_idx : Int) -> Bool

    Check if a function is cached and valid

    CodeCache::get

    fn CodeCache::get(self : CodeCache, func_idx : Int) -> CompiledFunction?

    Look up a compiled function by index

    CodeCache::insert

    fn CodeCache::insert(self : CodeCache, func_idx : Int, func : CompiledFunction) -> Unit

    Insert a compiled function into the cache

    CodeCache::invalidate

    fn CodeCache::invalidate(self : CodeCache, func_idx : Int) -> Unit

    Invalidate a cached function

    CodeCache::remove

    fn CodeCache::remove(self : CodeCache, func_idx : Int) -> Unit

    Remove a function from the cache

    CodeCache::stats

    fn CodeCache::stats(self : CodeCache) -> (Int, Int, Int, Int)

    Get cache statistics

    CompilationDecision

    pub(all) enum CompilationDecision {
    Interpret
    CompileAndExecute(CompilationMode)
    ExecuteCompiled
    }

    Decision about what to do with a function call

    CompilationMode

    pub(all) enum CompilationMode {
    Interpret
    Baseline
    Optimized
    }

    The compilation mode for a function

    CompilationQueue

    pub(all) struct CompilationQueue {
    requests : Array[CompilationRequest]
    max_size : Int
    }

    Queue of pending compilation requests

    CompilationQueue::CompilationQueue

    fn CompilationQueue::CompilationQueue(max_size : Int) -> CompilationQueue

    CompilationQueue::clear

    fn CompilationQueue::clear(self : CompilationQueue) -> Unit

    Clear the queue

    CompilationQueue::contains

    fn CompilationQueue::contains(self : CompilationQueue, func_idx : Int) -> Bool

    Check if a function is in the queue

    CompilationQueue::dequeue

    Get the next request to process

    CompilationQueue::enqueue

    fn CompilationQueue::enqueue(self : CompilationQueue, request : CompilationRequest) -> Bool

    Add a compilation request to the queue

    CompilationQueue::is_empty

    fn CompilationQueue::is_empty(self : CompilationQueue) -> Bool

    Check if queue is empty

    CompilationQueue::length

    fn CompilationQueue::length(self : CompilationQueue) -> Int

    Get queue length

    CompilationRequest

    pub(all) struct CompilationRequest {
    func_idx : Int
    mode : CompilationMode
    priority : Int
    }

    A request to compile a function

    CompilationRequest::CompilationRequest

    fn CompilationRequest::CompilationRequest(func_idx : Int, mode : CompilationMode) -> CompilationRequest

    CompilationRequest::with_priority

    fn CompilationRequest::with_priority(func_idx : Int, mode : CompilationMode, priority : Int) -> CompilationRequest

    CompilationStrategy

    pub(all) struct CompilationStrategy {
    profiler : Profiler
    queue : CompilationQueue
    config : TieredConfig
    decisions_interpret : Int
    decisions_compile : Int
    decisions_compiled : Int
    }

    The main compilation strategy manager

    CompilationStrategy::CompilationStrategy

    fn CompilationStrategy::CompilationStrategy(config : TieredConfig) -> CompilationStrategy

    CompilationStrategy::decide

    fn CompilationStrategy::decide(self : CompilationStrategy, func_idx : Int) -> CompilationDecision

    Make a compilation decision for a function call

    CompilationStrategy::is_compiled

    fn CompilationStrategy::is_compiled(self : CompilationStrategy, func_idx : Int) -> Bool

    Check if a function is compiled

    CompilationStrategy::mark_compiled

    fn CompilationStrategy::mark_compiled(self : CompilationStrategy, func_idx : Int) -> Unit

    Mark a function as compiled

    CompilationStrategy::next_to_compile

    Get the next function to compile (for background compilation)

    CompilationStrategy::schedule_compilation

    fn CompilationStrategy::schedule_compilation(self : CompilationStrategy, func_idx : Int, mode : CompilationMode) -> Bool

    Schedule a function for background compilation

    CompilationStrategy::stats

    fn CompilationStrategy::stats(self : CompilationStrategy) -> (Int, Int, Int, Int, Int, Int)

    Get strategy statistics

    CompiledFunction

    pub struct CompiledFunction {
    name : String
    code :
    MachineCode

    entry_offset : Int
    code_size : Int
    frame_size : Int
    gc_safepoints : Array[GcSafepoint]
    gc_stackmap_blob : Bytes
    valid : Bool
    }

    A compiled function ready for Wasmoon JIT execution.

    CompiledFunction::CompiledFunction

    fn CompiledFunction::CompiledFunction(name : String, code :
    MachineCode
    , frame_size : Int, gc_safepoints? : Array[GcSafepoint], gc_stackmap_blob? : Bytes) -> CompiledFunction

    CompiledFunction::get_call_fixups

    Get direct function call fixups.

    CompiledFunction::get_code

    fn CompiledFunction::get_code(self : CompiledFunction) -> Array[Int]

    Get the machine code bytes.

    CompiledFunction::get_func_addr_fixups

    Get direct function address fixups.

    CompiledFunction::get_gc_safepoints

    fn CompiledFunction::get_gc_safepoints(self : CompiledFunction) -> Array[GcSafepoint]

    Get GC safepoint metadata for this function.

    CompiledFunction::get_gc_stackmap_blob

    fn CompiledFunction::get_gc_stackmap_blob(self : CompiledFunction) -> Bytes

    Get GC stack-map payload bytes for this function.

    CompiledFunction::invalidate

    fn CompiledFunction::invalidate(self : CompiledFunction) -> Unit

    Invalidate this compiled function and mark it for recompilation.

    CompiledFunction::is_valid

    fn CompiledFunction::is_valid(self : CompiledFunction) -> Bool

    Check if the function is still valid.

    CwasmArtifact

    pub(all) struct CwasmArtifact {
    version : Int
    target :
    TargetArch

    entry_symbol : String
    code : Array[Int]
    functions : Array[CwasmFunctionRecord]
    call_veneers : Array[CwasmCallVeneer]
    runtime_relocations : Array[ResolvedRuntimeRelocation]
    func_addr_fixups : Array[
    FuncAddrFixup
    ]
    call_fixups : Array[
    CallFixup
    ]
    gc_safepoints : Array[GcSafepoint]
    gc_stackmap_blob : Bytes
    } derive(
    Debug
    )

    CwasmArtifact::from_jit_plan

    fn CwasmArtifact::from_jit_plan(plan : JitIntegrationPlan, resolver : RuntimeSymbolResolver, function_index : Int) -> CwasmArtifact raise LinkError

    CwasmArtifact::from_jit_plan_with_signature

    fn CwasmArtifact::from_jit_plan_with_signature(plan : JitIntegrationPlan, resolver : RuntimeSymbolResolver, function_index : Int, num_params : Int, num_results : Int) -> CwasmArtifact raise LinkError

    CwasmArtifact::from_linked_code_for_target

    fn CwasmArtifact::from_linked_code_for_target(linked : LinkedCode, function_index : Int, target :
    TargetArch
    , entry_symbol : String) -> CwasmArtifact

    CwasmArtifact::from_linked_code_for_target_with_signature

    fn CwasmArtifact::from_linked_code_for_target_with_signature(linked : LinkedCode, function_index : Int, target :
    TargetArch
    , entry_symbol : String, num_params : Int, num_results : Int) -> CwasmArtifact

    CwasmArtifact::manifest

    fn CwasmArtifact::manifest(self : CwasmArtifact) -> Array[String]

    CwasmArtifact::serialize

    fn CwasmArtifact::serialize(self : CwasmArtifact) -> Array[Int]

    CwasmArtifact::to_precompiled_module

    CwasmCallVeneer

    pub(all) struct CwasmCallVeneer {
    function_index : Int
    func_idx : Int
    offset : Int
    } derive(Eq,
    Debug
    )

    CwasmFunctionRecord

    pub(all) struct CwasmFunctionRecord {
    function_index : Int
    code_offset : Int
    code_size : Int
    frame_size : Int
    num_params : Int
    num_results : Int
    } derive(Eq,
    Debug
    )

    DWARFBuilder

    pub struct DWARFBuilder {
    // private fields
    }

    DWARF debug info builder Accumulates function metadata and generates DWARF sections

    DWARFBuilder::DWARFBuilder

    fn DWARFBuilder::DWARFBuilder() -> DWARFBuilder

    Create a new DWARF builder

    DWARFBuilder::add_function

    fn DWARFBuilder::add_function(self : DWARFBuilder, name : String, addr : Int64, size : Int, func_idx : Int) -> Unit

    Add a function to the DWARF debug info Parameters: name: Function name (e.g., "func_42" or "my_function") addr: Function start address in memory size: Function size in bytes func_idx: WebAssembly function index

    DWARFBuilder::capture_backtrace

    fn DWARFBuilder::capture_backtrace(self : DWARFBuilder) -> Array[BacktraceFrame]

    Capture and format a backtrace from the current trap state Returns an array of backtrace frames

    DWARFBuilder::destroy

    fn DWARFBuilder::destroy(self : DWARFBuilder) -> Unit

    Destroy the DWARF builder and free all resources This also unregisters the debug info if it was registered

    DWARFBuilder::format_backtrace

    fn DWARFBuilder::format_backtrace(_self : DWARFBuilder, frames : Array[BacktraceFrame]) -> String

    Format a backtrace as a string

    DWARFBuilder::lookup_address

    fn DWARFBuilder::lookup_address(self : DWARFBuilder, addr : Int64) -> FunctionInfo?

    Lookup an address to find which function it belongs to Returns None if the address is not in any known function

    DWARFBuilder::register

    fn DWARFBuilder::register(self : DWARFBuilder, verbose? : Bool) -> Unit

    Register the DWARF debug info with the debugger This generates an in-memory Mach-O/ELF object file with DWARF sections and registers it with LLDB/GDB via the standard JIT interface. After calling this, function names will appear in stack traces. Also sets this builder as the active one for backtrace lookups. verbose: if true, print debug info to stderr

    DWARFBuilder::unregister

    fn DWARFBuilder::unregister(self : DWARFBuilder) -> Unit

    Unregister DWARF debug info from the debugger Call this before destroying if you want to explicitly unregister

    DirectCallStubSet

    pub struct DirectCallStubSet {
    exec_codes : Array[ExecCode]
    targets : Map[Int, Int64]
    }

    ExecCode

    type ExecCode

    GC-managed executable code block wrapper.

    ExecCode::ptr

    fn ExecCode::ptr(self : ExecCode) -> Int64

    Get the function pointer from this executable code.

    ExecCode::try_alloc

    fn ExecCode::try_alloc(code : Array[Int]) -> ExecCode?

    Allocate and copy code to executable memory (GC-managed).

    ExecutableRegion

    type ExecutableRegion

    Represents a region of memory that can hold executable code (Abstraction - actual executable memory requires platform-specific implementation)

    ExecutableRegion::ExecutableRegion

    fn ExecutableRegion::ExecutableRegion(id : Int, size : Int) -> ExecutableRegion

    ExecutableRegion::address_at

    fn ExecutableRegion::address_at(self : ExecutableRegion, offset : Int) -> Int

    Get the effective address for a given offset

    ExecutableRegion::finalize

    fn ExecutableRegion::finalize(self : ExecutableRegion) -> Unit

    Finalize the region (make it executable, no more writes)

    ExecutableRegion::read_at

    fn ExecutableRegion::read_at(self : ExecutableRegion, offset : Int, length : Int) -> Array[Int]

    Read code at a given offset

    ExecutableRegion::remaining

    fn ExecutableRegion::remaining(self : ExecutableRegion) -> Int

    Get remaining space in the region

    ExecutableRegion::write

    fn ExecutableRegion::write(self : ExecutableRegion, bytes : Array[Int]) -> Result[Int, String]

    Write code bytes to the region

    FunctionInfo

    pub struct FunctionInfo {
    name : String
    func_idx : Int
    offset : Int64
    }

    Function lookup result

    FunctionTemperature

    pub(all) enum FunctionTemperature {
    Cold
    Warm
    Hot
    }

    Temperature of a function based on call frequency

    GcSafepoint

    pub struct GcSafepoint {
    code_offset : Int
    live_refs : Array[Int]
    metadata : Int64
    } derive(
    Debug
    )

    Information about a GC safepoint in generated code.

    GcSafepoint::GcSafepoint

    fn GcSafepoint::GcSafepoint(code_offset : Int, live_refs : Array[Int], metadata : Int64) -> GcSafepoint

    HostcallImportTrampolineCode

    pub(all) struct HostcallImportTrampolineCode {
    code : Array[Int]
    func_addr_fixups : Array[
    FuncAddrFixup
    ]
    }

    Machine-code bytes for Wasm-ABI import trampolines that call the wasmoon_jit_hostcall C bridge.

    HostcallImportTrampolineLayout

    pub(all) struct HostcallImportTrampolineLayout {
    arg_slots : Int
    result_slots : Int
    values_vec_bytes : Int
    int_overflow_count : Int
    float_overflow_types : Array[
    ValueType
    ]
    }

    HotThreshold

    pub(all) struct HotThreshold {
    warm_threshold : Int
    hot_threshold : Int
    }

    Configuration for hot function detection

    HotThreshold::aggressive

    fn HotThreshold::aggressive() -> HotThreshold

    HotThreshold::conservative

    fn HotThreshold::conservative() -> HotThreshold

    HotThreshold::default

    fn HotThreshold::default() -> HotThreshold

    ImportFunctionResolution

    pub(all) enum ImportFunctionResolution {
    DirectImportFunction(Int64)
    HostImportFunctionAddr(Int)
    UnsupportedImportFunction
    } derive(Eq,
    Debug
    )

    JITDebugDB

    pub struct JITDebugDB {
    entries : Map[Int, JITFunctionDebug]
    }

    Optional in-memory database of per-function debug dumps.

    JITDebugDB::JITDebugDB

    fn JITDebugDB::JITDebugDB() -> JITDebugDB

    JITDebugDB::get

    fn JITDebugDB::get(self : JITDebugDB, func_idx : Int) -> JITFunctionDebug?

    JITDebugDB::set

    fn JITDebugDB::set(self : JITDebugDB, func_idx : Int, debug : JITFunctionDebug) -> Unit

    JITFunctionDebug

    pub struct JITFunctionDebug {
    ir : String
    machv_before_regalloc : String
    machv_after_regalloc : String
    machine_code : String
    }

    Per-function compilation dumps captured for dump-on-trap.

    JITFunctionDebug::JITFunctionDebug

    fn JITFunctionDebug::JITFunctionDebug(ir : String, machv_before_regalloc : String, machv_after_regalloc : String, machine_code : String) -> JITFunctionDebug

    JITRuntime

    type JITRuntime

    Complete JIT runtime combining code cache and memory management
    impl Show for JITRuntime

    JITRuntime::JITRuntime

    fn JITRuntime::JITRuntime(cache_size : Int, region_size : Int) -> JITRuntime

    JITRuntime::clear

    fn JITRuntime::clear(self : JITRuntime) -> Unit

    Clear all compiled code

    JITRuntime::invalidate

    fn JITRuntime::invalidate(self : JITRuntime, func_idx : Int) -> Unit

    Invalidate a function (will be recompiled on next call)

    JITRuntime::lookup

    fn JITRuntime::lookup(self : JITRuntime, func_idx : Int) -> CompiledFunction?

    Look up a compiled function

    JITRuntime::register

    fn JITRuntime::register(self : JITRuntime, func_idx : Int, func : CompiledFunction) -> Result[Int, String]

    Register a compiled function

    JITRuntime::stats

    fn JITRuntime::stats(self : JITRuntime) -> (Int, Int, Int, Int, Int, Int, Int)

    Get runtime statistics

    JITTable

    Shared indirect table that can be used by multiple JIT modules.

    JITTable::get_entry_type

    fn JITTable::get_entry_type(self : JITTable, table_idx : Int) -> Int

    Read raw entry type index from the shared table.

    JITTable::get_entry_value

    fn JITTable::get_entry_value(self : JITTable, table_idx : Int) -> Int64

    Read raw entry value bits from the shared table.

    JITTable::get_max

    fn JITTable::get_max(self : JITTable) -> Int?

    Get the table max size.

    JITTable::get_size

    fn JITTable::get_size(self : JITTable) -> Int

    Get the table size.

    JITTable::raw_ptr

    fn JITTable::raw_ptr(self : JITTable) -> Int64

    Get the raw shared table pointer.

    JITTable::refresh_layout

    fn JITTable::refresh_layout(self : JITTable, table_ptr : Int64, size : Int) -> Unit

    Refresh table pointer and size from the active JIT context view.

    JITTable::set

    fn JITTable::set(self : JITTable, table_idx : Int, func_ptr : Int64, type_hash : Int) -> Unit

    Set an entry in the shared table.

    JITTable::try_alloc

    fn JITTable::try_alloc(size : Int, max : Int?) -> JITTable?

    Create a new shared JIT table. Note: size 0 is valid (empty table that can grow later).

    JitIntegrationPlan

    pub(all) struct JitIntegrationPlan {
    entry_symbol : String
    target :
    EmitTarget

    native_glue : Array[NativeGlueBinding]
    object :
    MachineCode

    }

    LinkedCode

    pub(all) struct LinkedCode {
    code : Array[Int]
    frame_size : Int
    runtime_relocations : Array[ResolvedRuntimeRelocation]
    func_addr_fixups : Array[
    FuncAddrFixup
    ]
    call_fixups : Array[
    CallFixup
    ]
    gc_safepoints : Array[GcSafepoint]
    gc_stackmap_blob : Bytes
    } derive(
    Debug
    )

    MemoryDescriptorLayout

    pub(all) struct MemoryDescriptorLayout {
    base_offset : Int
    current_length_offset : Int
    }

    Fixed prefix layout of wasmoon_memory_t accessed by generated JIT code.

    Keep these offsets in sync with jit_ffi/jit_ffi.h::wasmoon_memory_t.

    MemoryInfo

    pub struct MemoryInfo {
    ptr : Int64
    size : Int64
    max_pages : Int?
    }

    Memory information for JIT execution.

    MemoryInfo::MemoryInfo

    fn MemoryInfo::MemoryInfo(ptr : Int64, size : Int64, max_pages : Int?) -> MemoryInfo

    Create a new MemoryInfo.

    MemoryManager

    type MemoryManager

    Manages executable memory regions

    MemoryManager::MemoryManager

    fn MemoryManager::MemoryManager(default_region_size : Int) -> MemoryManager

    MemoryManager::alloc_region

    fn MemoryManager::alloc_region(self : MemoryManager, size : Int) -> ExecutableRegion

    Allocate a new executable region

    MemoryManager::finalize_all

    fn MemoryManager::finalize_all(self : MemoryManager) -> Unit

    Finalize all regions

    MemoryManager::get_current_region

    fn MemoryManager::get_current_region(self : MemoryManager) -> ExecutableRegion

    Get the current region, allocating if needed

    MemoryManager::total_allocated

    fn MemoryManager::total_allocated(self : MemoryManager) -> Int

    Get total allocated memory

    MemoryManager::total_used

    fn MemoryManager::total_used(self : MemoryManager) -> Int

    Get total used memory

    MemoryManager::write_code

    fn MemoryManager::write_code(self : MemoryManager, code :
    MachineCode
    ) -> Result[(ExecutableRegion, Int), String]

    Write code to the current region

    NativeGlueBinding

    pub(all) struct NativeGlueBinding {
    kind : NativeGlueKind
    symbol : String
    sources : Array[String]
    } derive(Eq,
    Debug
    )

    NativeGlueKind

    pub(all) enum NativeGlueKind {
    ExecutableMemory
    TrapHandler
    StackSwitch
    HostCallBridge
    WasmMemoryOp
    GcRuntime
    ExceptionHandling
    WasiPreview1
    DebugInfo
    } derive(Eq,
    Debug
    )

    NativeJITContext

    type NativeJITContext

    NativeJITContext::alloc_guarded_memory

    fn NativeJITContext::alloc_guarded_memory(self : NativeJITContext, initial_pages : Int, max_pages : Int?) -> Int64

    NativeJITContext::alloc_indirect_table

    fn NativeJITContext::alloc_indirect_table(self : NativeJITContext, count : Int) -> Bool

    NativeJITContext::alloc_wasm_stack

    fn NativeJITContext::alloc_wasm_stack(self : NativeJITContext, stack_size : Int64) -> Bool

    NativeJITContext::call_trampoline

    fn NativeJITContext::call_trampoline(self : NativeJITContext, trampoline_ptr : Int64, func_ptr : Int64, values_vec : FixedArray[Int64], values_len : Int, use_stack_switch : Bool) -> Int

    NativeJITContext::clear_cancellation_callback

    fn NativeJITContext::clear_cancellation_callback(self : NativeJITContext) -> Unit

    NativeJITContext::clear_hostcall_callback

    fn NativeJITContext::clear_hostcall_callback(self : NativeJITContext) -> Unit

    NativeJITContext::func_table_ptr

    fn NativeJITContext::func_table_ptr(self : NativeJITContext) -> Int64

    NativeJITContext::has_wasm_stack

    fn NativeJITContext::has_wasm_stack(self : NativeJITContext) -> Bool

    NativeJITContext::memory_ptr

    fn NativeJITContext::memory_ptr(self : NativeJITContext, memidx : Int) -> Int64

    NativeJITContext::memory_size

    fn NativeJITContext::memory_size(self : NativeJITContext, memidx : Int) -> Int64

    NativeJITContext::ptr

    fn NativeJITContext::ptr(self : NativeJITContext) -> Int64

    NativeJITContext::set_cancellation_callback

    fn NativeJITContext::set_cancellation_callback(self : NativeJITContext, callback : () -> Bool) -> Unit

    NativeJITContext::set_func

    fn NativeJITContext::set_func(self : NativeJITContext, idx : Int, func_ptr : Int64) -> Unit

    NativeJITContext::set_globals

    fn NativeJITContext::set_globals(self : NativeJITContext, globals_ptr : Int64) -> Unit

    NativeJITContext::set_hostcall_callback

    fn NativeJITContext::set_hostcall_callback(self : NativeJITContext, callback : () -> Int) -> Unit

    NativeJITContext::set_indirect

    fn NativeJITContext::set_indirect(self : NativeJITContext, table_idx : Int, func_idx : Int, type_idx : Int) -> Unit

    NativeJITContext::set_memory

    fn NativeJITContext::set_memory(self : NativeJITContext, mem0_ptr : Int64) -> Unit

    NativeJITContext::set_memory_pointers

    fn NativeJITContext::set_memory_pointers(self : NativeJITContext, memories : Array[MemoryInfo]) -> Unit

    NativeJITContext::set_table_pointers

    fn NativeJITContext::set_table_pointers(self : NativeJITContext, jit_tables : Array[JITTable?]) -> Unit

    NativeJITContext::try_alloc

    fn NativeJITContext::try_alloc(total_funcs : Int) -> NativeJITContext?

    Profiler

    pub(all) struct Profiler {
    counter : CallCounter
    threshold : HotThreshold
    hot_functions :
    HashSet
    [Int]
    pending_compilation :
    HashSet
    [Int]
    compiled_functions :
    HashSet
    [Int]
    }

    Complete profiler combining call counting and hot detection
    impl Show for Profiler

    Profiler::Profiler

    fn Profiler::Profiler(threshold : HotThreshold) -> Profiler

    Profiler::get_function_temperature

    fn Profiler::get_function_temperature(self : Profiler, func_idx : Int) -> FunctionTemperature

    Get temperature for a specific function

    Profiler::get_pending

    fn Profiler::get_pending(self : Profiler) -> Array[Int]

    Get list of functions pending compilation

    Profiler::is_compiled

    fn Profiler::is_compiled(self : Profiler, func_idx : Int) -> Bool

    Check if a function is compiled

    Profiler::mark_compiled

    fn Profiler::mark_compiled(self : Profiler, func_idx : Int) -> Unit

    Mark a function as compiled

    Profiler::record_call

    fn Profiler::record_call(self : Profiler, func_idx : Int) -> (Int, Bool)

    Record a function call and return whether it should be compiled Returns: (new_count, should_compile)

    Profiler::should_use_jit

    fn Profiler::should_use_jit(self : Profiler, func_idx : Int) -> Bool

    Check if a function should use JIT code

    Profiler::stats

    fn Profiler::stats(self : Profiler) -> (Int, Int, Int, Int)

    Get profiling statistics

    ResolvedRuntimeRelocation

    pub(all) struct ResolvedRuntimeRelocation {
    offset : Int
    symbol : String
    address : Int64
    fixup_idx : Int?
    } derive(Eq,
    Debug
    )

    RuntimeSymbol

    pub(all) struct RuntimeSymbol {
    name : String
    address : Int64
    fixup_idx : Int?
    } derive(Eq,
    Debug
    )

    RuntimeSymbolResolver

    pub(all) struct RuntimeSymbolResolver {
    symbols : Array[RuntimeSymbol]
    } derive(
    Debug
    )

    RuntimeSymbolResolver::RuntimeSymbolResolver

    fn RuntimeSymbolResolver::RuntimeSymbolResolver() -> RuntimeSymbolResolver

    RuntimeSymbolResolver::add_symbol

    fn RuntimeSymbolResolver::add_symbol(self : RuntimeSymbolResolver, name : String, address : Int64) -> Unit

    RuntimeSymbolResolver::add_symbol_fixup

    fn RuntimeSymbolResolver::add_symbol_fixup(self : RuntimeSymbolResolver, name : String, address : Int64, fixup_idx : Int) -> Unit

    RuntimeSymbolResolver::resolve

    fn RuntimeSymbolResolver::resolve(self : RuntimeSymbolResolver, name : String) -> Int64?

    RuntimeSymbolResolver::resolve_symbol

    fn RuntimeSymbolResolver::resolve_symbol(self : RuntimeSymbolResolver, name : String) -> RuntimeSymbol?

    RuntimeSymbolResolver::with_wasmoon_runtime_symbols

    fn RuntimeSymbolResolver::with_wasmoon_runtime_symbols() -> RuntimeSymbolResolver

    TieredConfig

    pub(all) struct TieredConfig {
    baseline_threshold : Int
    optimize_threshold : Int
    synchronous : Bool
    max_concurrent : Int
    }

    Configuration for tiered compilation

    TieredConfig::default

    fn TieredConfig::default() -> TieredConfig

    TieredConfig::deferred

    fn TieredConfig::deferred() -> TieredConfig

    TieredConfig::eager

    fn TieredConfig::eager() -> TieredConfig

    TrapDetails

    pub struct TrapDetails {
    signal : Int
    pc : Int64
    lr : Int64
    fp : Int64
    frame_lr : Int64
    fault_addr : Int64
    brk_imm : Int
    func_idx : Int
    x0 : Int64
    x1 : Int64
    x2 : Int64
    x3 : Int64
    x6 : Int64
    x7 : Int64
    x8 : Int64
    x9 : Int64
    x10 : Int64
    x11 : Int64
    x15 : Int64
    }

    Low-level trap detail captured by the JIT signal handlers (best-effort).

    TrapDetails::TrapDetails

    fn TrapDetails::TrapDetails() -> TrapDetails

    TrapReport

    pub(all) struct TrapReport {
    trap_kind : String
    message : String
    signal : Int
    signal_name : String
    pc : Int64
    lr : Int64
    fp : Int64
    frame_lr : Int64
    fault_addr : Int64
    brk_imm : Int
    wasm_func_idx : Int?
    wasm_func_name : String?
    wasm_offset : Int64?
    wasm_frames : Array[WasmTrapFrame]
    host_frames : Array[String]
    dump_path : String?
    }

    Structured trap report for native integrations.

    VMContextLayout

    pub(all) struct VMContextLayout {
    memory0_offset : Int
    memory0_base_offset : Int
    memory0_size_offset : Int
    func_table_offset : Int
    table0_base_offset : Int
    table0_elements_offset : Int
    globals_offset : Int
    tables_offset : Int
    table_count_offset : Int
    func_count_offset : Int
    table_sizes_offset : Int
    table_max_sizes_offset : Int
    memories_offset : Int
    memory_count_offset : Int
    debug_current_func_idx_offset : Int
    gc_heap_ptr_offset : Int
    gc_heap_limit_offset : Int
    gc_heap_offset : Int
    pointer_stride : Int
    global_value_stride : Int
    table_entry_value_offset : Int
    table_entry_stride : Int
    func_table_entry_stride : Int
    }

    Fixed VMContext prefix layout accessed by generated JIT code.

    Keep these offsets in sync with jit_ffi/jit_ffi.h::jit_context_t. Embedders and frontends should query this value instead of copying raw offsets into lowering code.

    VMContextLayout::to_embedding_context_layout

    Translate Wasmoon's concrete VMContext prefix into the generic machine-level embedding context layout consumed by reusable code.

    WasmTrapFrame

    pub(all) struct WasmTrapFrame {
    pc : Int64
    func_idx : Int
    func_name : String
    wasm_offset : Int64
    }

    A resolved wasm frame in a native trap report.

    TYPE_F32

    let TYPE_F32 : Int

    TYPE_F64

    let TYPE_F64 : Int

    TYPE_I32

    let TYPE_I32 : Int

    Type codes for parameter/result types

    TYPE_I64

    let TYPE_I64 : Int

    TYPE_V128

    let TYPE_V128 : Int

    alloc_guarded_memory_desc

    fn alloc_guarded_memory_desc(initial_pages : Int, max_pages : Int?) -> Int64

    Allocate a guarded (reserved) memory descriptor for memory32 memory0. This is required for bounds-check elimination; out-of-bounds accesses trap via guard pages.

    alloc_memory

    fn alloc_memory(size : Int64) -> Int64

    Allocate linear memory for WASM (returns 0 on failure).

    alloc_memory_desc

    fn alloc_memory_desc(size_bytes : Int64, max_pages : Int?, is_memory64? : Bool, page_size_log2? : Int, is_shared? : Bool) -> Int64

    Allocate a wasmoon_memory_t descriptor with owned backing memory.

    build_aarch64_direct_call_stub

    fn build_aarch64_direct_call_stub(target_ptr : Int64) -> Array[Int]

    build_aarch64_load_imm64_fixed_bytes

    fn build_aarch64_load_imm64_fixed_bytes(reg : Int, imm : Int64) -> Array[Int]

    build_cwasm_entry_from_code

    fn build_cwasm_entry_from_code(func_idx : Int, name : String, code : Array[Int], frame_size : Int, entry_offset : Int, num_params : Int, num_results : Int, func_addr_fixups? : Array[
    FuncAddrFixup
    ], call_fixups? : Array[
    CallFixup
    ], gc_safepoint_offsets? : Array[Int], gc_safepoint_root_counts? : Array[Int], gc_safepoint_root_indices? : Array[Array[Int]], gc_safepoints? : Array[
    GcSafepoint
    ], gc_stackmap_blob? : Bytes) ->
    CompiledEntry

    build_entry_trampoline_for_target

    build_gc_stackmap_blob

    fn build_gc_stackmap_blob(root_counts : Array[Int]) -> Bytes

    build_gc_stackmap_blob_for_safepoints

    fn build_gc_stackmap_blob_for_safepoints(safepoints : Array[
    GcSafepoint
    ], root_counts : Array[Int], explicit_blob? : Bytes) -> Bytes

    build_gc_stackmap_blob_v2

    fn build_gc_stackmap_blob_v2(safepoints : Array[
    GcSafepoint
    ], default_root_counts : Array[Int]) -> Bytes

    build_hostcall_import_trampoline_for_target

    build_x64_direct_call_stub

    fn build_x64_direct_call_stub(target_ptr : Int64) -> Array[Int]

    c_jit_read_i64

    fn c_jit_read_i64(addr : Int64) -> Int64

    Read an int64 value from a memory address

    c_jit_write_i64

    fn c_jit_write_i64(addr : Int64, value : Int64) -> Unit

    Write an int64 value to a memory address

    c_jit_write_u32

    fn c_jit_write_u32(addr : Int64, value : Int) -> Unit

    Write a u32 value to a memory address

    can_use_reusable_entry_trampoline

    fn can_use_reusable_entry_trampoline(param_types : Array[
    ValueType
    ], result_types : Array[
    ValueType
    ]) -> Bool

    classify_import_function_ptr

    fn classify_import_function_ptr(ptr : Int64) -> ImportFunctionResolution

    clear_segments

    fn clear_segments(ctx_ptr : Int64) -> Unit

    clear_wasi_stdin_buffer

    fn clear_wasi_stdin_buffer(ctx_ptr : Int64) -> Unit

    clear_wasi_stdin_callback

    fn clear_wasi_stdin_callback(ctx_ptr : Int64) -> Unit

    collect_gc_root_args

    fn collect_gc_root_args(args : Array[Int64], param_types : Array[
    ValueType
    ]) -> Array[Int64]

    context_func_count

    fn context_func_count(ctx_ptr : Int64) -> Int

    context_func_table_ptr

    fn context_func_table_ptr(ctx_ptr : Int64) -> Int64

    context_table_ptr

    fn context_table_ptr(ctx_ptr : Int64, table_idx : Int) -> Int64

    context_table_size

    fn context_table_size(ctx_ptr : Int64, table_idx : Int) -> Int

    count_entry_trampoline_slots

    fn count_entry_trampoline_slots(types : Array[
    ValueType
    ]) -> Int

    decode_externref

    fn decode_externref(raw : Int64) -> Int?

    decode_funcref_idx

    fn decode_funcref_idx(raw : Int64) -> Int?

    decode_gc_heap_ref

    fn decode_gc_heap_ref(raw : Int64) -> Int?

    decode_heap_ref

    fn decode_heap_ref(encoded : Int64) -> Int

    Decode a heap reference from JIT representation Returns 0-based heap_idx for MoonBit Store/CHeap

    decode_i31

    fn decode_i31(encoded : Int64) -> Int

    Decode an i31 value from JIT representation

    default_native_glue

    fn default_native_glue() -> Array[NativeGlueBinding]

    derive_gc_safepoints

    fn derive_gc_safepoints(offsets : Array[Int], root_counts : Array[Int], root_indices : Array[Array[Int]]) -> Array[
    GcSafepoint
    ]

    direct_call_idx_memory_copy_mem0

    fn direct_call_idx_memory_copy_mem0() -> Int

    direct_call_idx_memory_fill_mem0

    fn direct_call_idx_memory_fill_mem0() -> Int

    embedding_context_layout

    emit_entry_trampoline

    fn emit_entry_trampoline(param_types : Array[Int], result_types : Array[Int], call_conv_layout :
    CallConventionLayout
    , isa? :
    ISA
    ) ->
    MachineCode

    Generate an entry trampoline for a specific function signature

    Trampoline signature (C calling convention): int trampoline(vmctx: X0, values_vec: X1, func_ptr: X2) -> trap_code

    The values_vec layout: [arg0, arg1, ..., argN, result0, result1, ..., resultM] Each slot is 8 bytes (int64_t), except V128 which uses 16 bytes (2 slots)

    Parameters: param_types: Array of parameter types (0=I32, 1=I64, 2=F32, 3=F64, 4=V128) result_types: Array of result types

    Approach: generate IR, then compile through the normal pipeline. The register allocator will automatically choose callee-saved registers when needed, eliminating the need for hardcoded X23/X24.

    emit_hostcall_import_trampoline

    Generate a Wasm-ABI trampoline for calling a host function via a hostcall bridge.

    host_func_addr is the runtime Store function address and is passed to the dispatcher.

    emit_target_to_isa

    encode_aarch64_bl_imm26

    fn encode_aarch64_bl_imm26(pc : Int64, target_ptr : Int64) -> Int?

    encode_externref

    fn encode_externref(host_idx : Int) -> Int64

    encode_funcref_idx

    fn encode_funcref_idx(func_idx : Int) -> Int64

    encode_gc_heap_ref

    fn encode_gc_heap_ref(heap_idx0 : Int) -> Int64

    encode_heap_ref

    fn encode_heap_ref(heap_idx : Int) -> Int64

    Encode a heap reference (struct or array) for JIT heap_idx is 0-based (from MoonBit Store/CHeap) JIT uses 1-based gc_ref internally to avoid collision with null (0)

    encode_i31

    fn encode_i31(value : Int) -> Int64

    Encode an i31 value for JIT (tagged pointer with lowest bit = 1)

    encode_null_ref

    fn encode_null_ref() -> Int64

    encode_x64_call_rel32_disp

    fn encode_x64_call_rel32_disp(pc : Int64, target_ptr : Int64) -> Int?

    entry_trampoline_signature_hash

    fn entry_trampoline_signature_hash(param_types : Array[
    ValueType
    ], result_types : Array[
    ValueType
    ]) -> Int64

    entry_trampoline_type_codes

    fn entry_trampoline_type_codes(types : Array[
    ValueType
    ]) -> Array[Int]

    entry_trampoline_value_type_code

    fn entry_trampoline_value_type_code(ty :
    ValueType
    ) -> Int

    exception_runtime_fixup_idx

    fn exception_runtime_fixup_idx(ordinal : Int) -> Int

    Reserve negative function-index values for cwasm runtime-helper fixups.

    format_signal_name

    fn format_signal_name(sig : Int) -> String

    format_trap_report_message

    fn format_trap_report_message(report : TrapReport) -> String

    format_u64_hex

    fn format_u64_hex(v : Int64) -> String

    free_memory

    fn free_memory(mem_ptr : Int64) -> Unit

    free_memory_desc

    fn free_memory_desc(mem_desc_ptr : Int64) -> Unit

    gc_begin_frame

    fn gc_begin_frame(ctx_ptr : Int64, frame_id : Int64) -> Unit

    Begin a GC frame scope for current JIT context.

    gc_clear_heap

    fn gc_clear_heap(ctx_ptr : Int64) -> Unit

    Clear the GC heap pointer after JIT execution

    gc_collect_for_alloc

    fn gc_collect_for_alloc(ctx_ptr : Int64, roots : Array[Int64]) -> Int

    Trigger a GC cycle for allocation retry.

    gc_debug_set_fail_alloc

    fn gc_debug_set_fail_alloc(fail_at : Int, fail_every? : Int) -> Unit

    Configure allocation fault injection for debugging

    gc_end_frame

    fn gc_end_frame(ctx_ptr : Int64) -> Unit

    End a GC frame scope for current JIT context.

    gc_runtime_fixup_idx

    fn gc_runtime_fixup_idx(ordinal : Int) -> Int

    Reserve negative function-index values for cwasm runtime-helper fixups.

    gc_safepoint_metadata_to_root_count

    fn gc_safepoint_metadata_to_root_count(metadata : Int64) -> Int

    gc_set_context_heap_ptr

    fn gc_set_context_heap_ptr(ctx_ptr : Int64, heap_ptr : Int64) -> Unit

    gc_set_func_safepoints

    fn gc_set_func_safepoints(ctx_ptr : Int64, func_idx : Int, safepoints : Array[
    GcSafepoint
    ], stackmap_blob : Bytes) -> Bool

    gc_set_heap

    fn gc_set_heap(ctx_ptr : Int64, heap : CHeap) -> Unit

    Set up the GC heap for JIT execution heap: The CHeap pointer from Store

    gc_set_root_scratch

    fn gc_set_root_scratch(ctx_ptr : Int64, roots : Array[Int64]) -> Bool

    Merge roots into context-local scratch storage for allocation retries.

    gc_set_safepoint_table

    fn gc_set_safepoint_table(ctx_ptr : Int64, table_ptr : Int64) -> Unit

    Set safepoint metadata table pointer for current context.

    gc_setup

    fn gc_setup(heap : CHeap, types : Array[
    SubType
    ], canonical_indices : Array[Int], ctx_ptr~ : Int64, func_type_indices~ : Array[Int], func_table_ptr~ : Int64, num_funcs~ : Int) -> Unit raise GCSetupError

    Full GC setup for JIT: set heap and type cache func_type_indices, func_table_ptr, and num_funcs are required to keep typed funcref/ref.func operations safe and deterministic.

    gc_teardown

    fn gc_teardown(ctx_ptr : Int64) -> Unit

    Clean up GC context after JIT execution

    gc_use_func_safepoints

    fn gc_use_func_safepoints(ctx_ptr : Int64, func_idx : Int) -> Unit

    get_args_get_ptr

    fn get_args_get_ptr() -> Int64

    get_args_sizes_get_ptr

    fn get_args_sizes_get_ptr() -> Int64

    get_clock_res_get_ptr

    fn get_clock_res_get_ptr() -> Int64

    get_clock_time_get_ptr

    fn get_clock_time_get_ptr() -> Int64

    get_environ_get_ptr

    fn get_environ_get_ptr() -> Int64

    get_environ_sizes_get_ptr

    fn get_environ_sizes_get_ptr() -> Int64

    get_fd_advise_ptr

    fn get_fd_advise_ptr() -> Int64

    get_fd_allocate_ptr

    fn get_fd_allocate_ptr() -> Int64

    get_fd_close_ptr

    fn get_fd_close_ptr() -> Int64

    get_fd_datasync_ptr

    fn get_fd_datasync_ptr() -> Int64

    get_fd_fdstat_get_ptr

    fn get_fd_fdstat_get_ptr() -> Int64

    get_fd_fdstat_set_flags_ptr

    fn get_fd_fdstat_set_flags_ptr() -> Int64

    get_fd_fdstat_set_rights_ptr

    fn get_fd_fdstat_set_rights_ptr() -> Int64

    get_fd_filestat_get_ptr

    fn get_fd_filestat_get_ptr() -> Int64

    get_fd_filestat_set_size_ptr

    fn get_fd_filestat_set_size_ptr() -> Int64

    get_fd_filestat_set_times_ptr

    fn get_fd_filestat_set_times_ptr() -> Int64

    get_fd_pread_ptr

    fn get_fd_pread_ptr() -> Int64

    get_fd_prestat_dir_name_ptr

    fn get_fd_prestat_dir_name_ptr() -> Int64

    get_fd_prestat_get_ptr

    fn get_fd_prestat_get_ptr() -> Int64

    get_fd_pwrite_ptr

    fn get_fd_pwrite_ptr() -> Int64

    get_fd_read_ptr

    fn get_fd_read_ptr() -> Int64

    get_fd_readdir_ptr

    fn get_fd_readdir_ptr() -> Int64

    get_fd_renumber_ptr

    fn get_fd_renumber_ptr() -> Int64

    get_fd_seek_ptr

    fn get_fd_seek_ptr() -> Int64

    get_fd_sync_ptr

    fn get_fd_sync_ptr() -> Int64

    get_fd_tell_ptr

    fn get_fd_tell_ptr() -> Int64

    get_fd_write_ptr

    fn get_fd_write_ptr() -> Int64

    get_gc_array_copy_ptr

    fn get_gc_array_copy_ptr() -> Int64

    Get array.copy libcall function pointer Signature: void gc_array_copy(int64_t dst_ref, int32_t dst_off, int64_t src_ref, int32_t src_off, int32_t count) Copies array elements from source to destination

    get_gc_array_fill_ptr

    fn get_gc_array_fill_ptr() -> Int64

    Get array.fill libcall function pointer Signature: void gc_array_fill(int64_t ref, int32_t offset, int64_t value, int32_t count) Fills array elements with a value

    get_gc_array_get_ptr

    fn get_gc_array_get_ptr() -> Int64

    Get array.get libcall function pointer Signature: int64_t gc_array_get(int64_t ref, int type_idx, int idx) Returns the element value

    get_gc_array_len_ptr

    fn get_gc_array_len_ptr() -> Int64

    Get array.len libcall function pointer Signature: int gc_array_len(int64_t ref) Returns the array length

    get_gc_array_new_ptr

    fn get_gc_array_new_ptr() -> Int64

    Get array.new libcall function pointer Signature: int64_t gc_array_new(int type_idx, int len, int64_t fill) Returns encoded ArrayRef

    get_gc_array_set_ptr

    fn get_gc_array_set_ptr() -> Int64

    Get array.set libcall function pointer Signature: void gc_array_set(int64_t ref, int type_idx, int idx, int64_t value)

    get_gc_ref_cast_ptr

    fn get_gc_ref_cast_ptr() -> Int64

    Get ref.cast libcall function pointer Signature: int64_t gc_ref_cast(int64_t ref, int type_idx, int nullable) Returns the ref if cast succeeds, traps on failure

    get_gc_ref_test_ptr

    fn get_gc_ref_test_ptr() -> Int64

    Get ref.test libcall function pointer Signature: int gc_ref_test(int64_t ref, int type_idx, int nullable) Returns 1 if test passes, 0 otherwise

    get_gc_struct_get_ptr

    fn get_gc_struct_get_ptr() -> Int64

    Get struct.get libcall function pointer Signature: int64_t gc_struct_get(int64_t ref, int type_idx, int field_idx) Returns the field value

    get_gc_struct_new_ptr

    fn get_gc_struct_new_ptr() -> Int64

    Get struct.new libcall function pointer Signature: int64_t gc_struct_new(int type_idx, int64_t* fields, int num_fields) Returns encoded StructRef

    get_gc_struct_set_ptr

    fn get_gc_struct_set_ptr() -> Int64

    Get struct.set libcall function pointer Signature: void gc_struct_set(int64_t ref, int type_idx, int field_idx, int64_t value)

    get_gc_type_check_subtype_ptr

    fn get_gc_type_check_subtype_ptr() -> Int64

    Get type check subtype libcall function pointer for call_indirect with subtyping Signature: void gc_type_check_subtype(int32_t actual_type, int32_t expected_type) Traps if actual_type is not a subtype of expected_type

    get_hostcall_func_addr

    fn get_hostcall_func_addr() -> Int

    Get the runtime store function address for the current JIT -> hostcall.

    This value is set by wasmoon_jit_hostcall right before invoking the MoonBit hostcall callback.

    get_hostcall_num_arg_slots

    fn get_hostcall_num_arg_slots() -> Int

    Get the number of argument slots in values_vec.

    Note: slots are 8 bytes each; V128 occupies 2 slots.

    get_hostcall_num_result_slots

    fn get_hostcall_num_result_slots() -> Int

    Get the number of result slots in values_vec.

    Note: slots are 8 bytes each; V128 occupies 2 slots.

    get_hostcall_values_ptr

    fn get_hostcall_values_ptr() -> Int64

    Get the pointer to the hostcall scratch values_vec buffer.

    get_import_trampoline

    fn get_import_trampoline(module_name : String, field_name : String) -> Int64?

    Get trampoline function pointer for an import. Returns None if the import is not supported by JIT.

    get_last_trap_details

    fn get_last_trap_details() -> TrapDetails

    Get the last captured trap details (best-effort). These fields are reset at the start of each JIT call.

    get_path_create_directory_ptr

    fn get_path_create_directory_ptr() -> Int64

    get_path_filestat_get_ptr

    fn get_path_filestat_get_ptr() -> Int64

    get_path_filestat_set_times_ptr

    fn get_path_filestat_set_times_ptr() -> Int64

    fn get_path_link_ptr() -> Int64

    get_path_open_ptr

    fn get_path_open_ptr() -> Int64

    fn get_path_readlink_ptr() -> Int64

    get_path_remove_directory_ptr

    fn get_path_remove_directory_ptr() -> Int64

    get_path_rename_ptr

    fn get_path_rename_ptr() -> Int64

    fn get_path_symlink_ptr() -> Int64

    fn get_path_unlink_file_ptr() -> Int64

    get_poll_oneoff_ptr

    fn get_poll_oneoff_ptr() -> Int64

    get_proc_exit_ptr

    fn get_proc_exit_ptr() -> Int64

    get_proc_raise_ptr

    fn get_proc_raise_ptr() -> Int64

    get_random_get_ptr

    fn get_random_get_ptr() -> Int64

    get_sched_yield_ptr

    fn get_sched_yield_ptr() -> Int64

    get_sock_accept_ptr

    fn get_sock_accept_ptr() -> Int64

    get_sock_recv_ptr

    fn get_sock_recv_ptr() -> Int64

    get_sock_send_ptr

    fn get_sock_send_ptr() -> Int64

    get_sock_shutdown_ptr

    fn get_sock_shutdown_ptr() -> Int64

    get_spectest_print_char_ptr

    fn get_spectest_print_char_ptr() -> Int64

    get_spectest_print_f32_ptr

    fn get_spectest_print_f32_ptr() -> Int64

    get_spectest_print_f64_f64_ptr

    fn get_spectest_print_f64_f64_ptr() -> Int64

    get_spectest_print_f64_ptr

    fn get_spectest_print_f64_ptr() -> Int64

    get_spectest_print_i32_f32_ptr

    fn get_spectest_print_i32_f32_ptr() -> Int64

    get_spectest_print_i32_ptr

    fn get_spectest_print_i32_ptr() -> Int64

    get_spectest_print_i64_ptr

    fn get_spectest_print_i64_ptr() -> Int64

    get_spectest_print_ptr

    fn get_spectest_print_ptr() -> Int64

    get_temperature

    fn get_temperature(count : Int, threshold : HotThreshold) -> FunctionTemperature

    Determines the temperature of a function based on its call count

    host_target_arch

    hostcall_value_byte_count

    fn hostcall_value_byte_count(ty :
    ValueType
    ) -> Int

    hostcall_value_slot_count

    fn hostcall_value_slot_count(ty :
    ValueType
    ) -> Int

    i64_to_value

    Decode an Int64 from C heap to a Value based on expected type

    init_wasi_context

    fn init_wasi_context(ctx_ptr : Int64, args : Array[String], env : Array[String], preopens : Array[(String, String)], quiet? : Bool) -> Unit

    install_direct_call_stubs_for_target

    is_cancelled_trap_code

    fn is_cancelled_trap_code(code : Int) -> Bool

    is_funcref_ptr

    fn is_funcref_ptr(raw : Int64) -> Bool

    is_i31

    fn is_i31(value : Int64) -> Bool

    Check if a JIT value is an i31 (has tag bit set)

    is_jit_supported_module

    fn is_jit_supported_module(module_name : String) -> Bool

    Check if a module is known to JIT (has trampoline support).

    is_null

    fn is_null(value : Int64) -> Bool

    Check if a JIT value is null

    is_null_ref

    fn is_null_ref(raw : Int64) -> Bool

    is_wasi_exit_trap_code

    fn is_wasi_exit_trap_code(code : Int) -> Bool

    jit_ffi_native_stub_sources

    fn jit_ffi_native_stub_sources() -> Array[String]

    jit_runtime_fixup_idx

    fn jit_runtime_fixup_idx(ordinal : Int) -> Int

    Reserve negative function-index values for cwasm runtime-helper fixups.

    jit_trap_message

    fn jit_trap_message(code : Int) -> String

    lower_wasm_body_milkir_for_target

    machv_reloc_target_to_cwasm_func_idx

    fn machv_reloc_target_to_cwasm_func_idx(target :
    RelocTarget
    ) -> Int?

    make_cstring

    fn make_cstring(s : String) -> FixedArray[Byte]

    memory_descriptor_layout

    fn memory_descriptor_layout() -> MemoryDescriptorLayout

    memory_init

    fn memory_init(mem_ptr : Int64, offset : Int64, data : Bytes) -> Bool

    Initialize memory with data at offset.

    memory_read

    fn memory_read(mem_ptr : Int64, offset : Int64, size : Int) -> Bytes

    Read size bytes from linear memory at offset.

    native_glue_covers_jit_ffi_stubs

    fn native_glue_covers_jit_ffi_stubs(glue? : Array[NativeGlueBinding]) -> Bool

    native_glue_covers_source

    fn native_glue_covers_source(glue : Array[NativeGlueBinding], source : String) -> Bool

    patch_aarch64_call_fixups

    fn patch_aarch64_call_fixups(exec_ptr : Int64, fixups : Array[
    CallFixup
    ], func_table_ptr : Int64, direct_call_targets : Map[Int, Int64]) -> Unit

    patch_aarch64_call_veneer_target

    fn patch_aarch64_call_veneer_target(exec_ptr : Int64, fixup :
    CallFixup
    , target_ptr : Int64) -> Unit

    patch_aarch64_direct_call

    fn patch_aarch64_direct_call(exec_ptr : Int64, fixup :
    CallFixup
    , target_ptr : Int64) -> Unit

    patch_aarch64_func_addr_fixup

    fn patch_aarch64_func_addr_fixup(exec_ptr : Int64, fixup :
    FuncAddrFixup
    , target_ptr : Int64) -> Unit

    patch_aarch64_func_addr_fixup_parts

    fn patch_aarch64_func_addr_fixup_parts(exec_ptr : Int64, offset : Int, reg : Int, target_ptr : Int64) -> Unit

    patch_aarch64_func_addr_fixup_raw

    fn patch_aarch64_func_addr_fixup_raw(exec_ptr : Int64, offset : Int, reg : Int, func_idx : Int, func_table_ptr : Int64) -> Unit

    patch_aarch64_func_addr_fixups

    fn patch_aarch64_func_addr_fixups(exec_ptr : Int64, fixups : Array[
    FuncAddrFixup
    ], func_table_ptr : Int64) -> Unit

    patch_aarch64_load_imm64_fixed

    fn patch_aarch64_load_imm64_fixed(exec_ptr : Int64, offset : Int, reg : Int, imm : Int64) -> Unit

    patch_call_fixups_for_target

    fn patch_call_fixups_for_target(target :
    TargetArch
    , exec_ptr : Int64, fixups : Array[
    CallFixup
    ], func_table_ptr : Int64, direct_call_targets : Map[Int, Int64]) -> Unit

    patch_func_addr_fixup_raw_for_target

    fn patch_func_addr_fixup_raw_for_target(target :
    TargetArch
    , exec_ptr : Int64, offset : Int, reg : Int, func_idx : Int, func_table_ptr : Int64) -> Unit

    patch_func_addr_fixups_for_target

    fn patch_func_addr_fixups_for_target(target :
    TargetArch
    , exec_ptr : Int64, fixups : Array[
    FuncAddrFixup
    ], func_table_ptr : Int64) -> Unit

    patch_x64_call_fixups

    fn patch_x64_call_fixups(exec_ptr : Int64, fixups : Array[
    CallFixup
    ], func_table_ptr : Int64, direct_call_targets : Map[Int, Int64]) -> Unit

    patch_x64_direct_call

    fn patch_x64_direct_call(exec_ptr : Int64, fixup :
    CallFixup
    , target_ptr : Int64) -> Unit

    patch_x64_func_addr_fixup_parts

    fn patch_x64_func_addr_fixup_parts(exec_ptr : Int64, offset : Int, _reg : Int, target_ptr : Int64) -> Unit

    patch_x64_func_addr_fixup_raw

    fn patch_x64_func_addr_fixup_raw(exec_ptr : Int64, offset : Int, reg : Int, func_idx : Int, func_table_ptr : Int64) -> Unit

    patch_x64_func_addr_fixups

    fn patch_x64_func_addr_fixups(exec_ptr : Int64, fixups : Array[
    FuncAddrFixup
    ], func_table_ptr : Int64) -> Unit

    plan_entry_trampoline_for_target

    plan_hostcall_import_trampoline_layout

    fn plan_hostcall_import_trampoline_layout(param_types : Array[
    ValueType
    ], result_types : Array[
    ValueType
    ], max_int_regs : Int, max_float_regs : Int) -> HostcallImportTrampolineLayout

    plan_integration_for_target

    plan_milkir_integration_for_target

    plan_wasm_body_milkir_integration_for_target

    fn plan_wasm_body_milkir_integration_for_target(func :
    Function
    , target :
    EmitTarget
    ) -> JitIntegrationPlan

    required_context_function_count

    fn required_context_function_count(precompiled :
    PrecompiledModule
    , func_signature_count : Int) -> Int

    resolve_call_fixup_target

    fn resolve_call_fixup_target(func_idx : Int, func_table_ptr : Int64, direct_call_targets : Map[Int, Int64]) -> Int64?

    resolve_func_addr_fixup_target

    fn resolve_func_addr_fixup_target(func_idx : Int, func_table_ptr : Int64) -> Int64?

    resolve_import_function

    fn resolve_import_function(external_imports : Map[String, Map[String, Int64]], module_name : String, field_name : String) -> ImportFunctionResolution

    resolve_import_function_ptr

    fn resolve_import_function_ptr(external_imports : Map[String, Map[String, Int64]], module_name : String, field_name : String) -> Int64?

    resolve_runtime_func_fixup_idx

    fn resolve_runtime_func_fixup_idx(idx : Int) -> Int64?

    Resolve the negative cwasm runtime-helper function index used by Wasmoon JIT call fixups. MachV emission uses named external-symbol relocations, and the cwasm artifact stores those runtime helper targets as negative function indices for the loader to patch.

    resolve_wasm_func_code_symbol

    fn resolve_wasm_func_code_symbol(symbol :
    CodeSymbol
    ) -> Int?

    resolve_wasm_func_symbol

    fn resolve_wasm_func_symbol(name : String) -> Int?

    runtime_hostcall_symbol

    fn runtime_hostcall_symbol() ->
    ExternalName

    sanitize_debug_filename

    fn sanitize_debug_filename(s : String) -> String

    set_wasi_stderr_capture

    fn set_wasi_stderr_capture(ctx_ptr : Int64, enabled : Bool) -> Unit

    set_wasi_stdin_buffer

    fn set_wasi_stdin_buffer(ctx_ptr : Int64, data : Bytes) -> Unit

    set_wasi_stdin_callback

    fn set_wasi_stdin_callback(ctx_ptr : Int64, callback : () -> Bytes) -> Unit

    set_wasi_stdout_capture

    fn set_wasi_stdout_capture(ctx_ptr : Int64, enabled : Bool) -> Unit

    setup_segments

    fn setup_segments(ctx_ptr : Int64, datas : Array[
    Data
    ], elem_segments : Array[Array[Int64]], data_dropped? : Array[Bool], elem_dropped? : Array[Bool]) -> Unit

    setup_type_cache_from_types

    fn setup_type_cache_from_types(ctx_ptr : Int64, types : Array[
    SubType
    ], canonical_indices : Array[Int]) -> Unit

    Set up the type cache for subtyping checks from raw type data types: Array of SubType from the module canonical_indices: Array of canonical type indices

    tag_funcref_ptr

    fn tag_funcref_ptr(func_ptr : Int64) -> Int64

    take_pending_trap_message

    fn take_pending_trap_message() -> String?

    take_wasi_exit_code

    fn take_wasi_exit_code(ctx_ptr : Int64) -> Int

    take_wasi_stderr

    fn take_wasi_stderr(ctx_ptr : Int64) -> Bytes

    take_wasi_stdout

    fn take_wasi_stdout(ctx_ptr : Int64) -> Bytes

    target_arch_to_isa

    throw_exception_tag

    fn throw_exception_tag(ctx_ptr : Int64, tag_addr : Int) -> Unit

    throw_exception_values

    fn throw_exception_values(ctx_ptr : Int64, tag_addr : Int, values : Array[Int64]) -> Unit

    untag_funcref_ptr

    fn untag_funcref_ptr(tagged_ptr : Int64) -> Int64

    value_to_i64

    fn value_to_i64(value :
    Value
    ) -> Int64

    Encode a Value to Int64 for C heap storage Encoding rules:
    • i32: sign-extended to i64
    • i64: as-is
    • f32: lower 32 bits (IEEE 754 bits)
    • f64: as-is (IEEE 754 bits)
    • structref/arrayref: (gc_ref) << 1, where gc_ref = idx + 1 (even, low bit = 0)
    • funcref: function index + 1 (0 = null)
    • externref: extern index + 1 (0 = null)
    • exnref: exception index + 1 (0 = null)
    • i31: (value << 1) | 1 (tagged, low bit = 1)
    • null: 0

    GC reference detection in gc_heap_mark uses: (value & 1) == 0 && value > 0

    value_type_may_hold_gc_ref

    fn value_type_may_hold_gc_ref(ty :
    ValueType
    ) -> Bool

    vmcontext_layout

    fn vmcontext_layout() -> VMContextLayout

    wasm_calling_convention

    wasm_calling_convention_for_isa

    Wasmoon internal Wasm-to-Wasm calling convention for a target ISA.

    wasm_context_slots

    wasm_embedding_abi

    wasm_embedding_abi_for_isa

    Complete Wasmoon embedding ABI contract for reusable MachV/MilkIR stages.

    wasm_embedding_reg_roles

    wasm_embedding_reg_roles_for_isa

    Wasmoon JIT embedding register roles for a target ISA.

    These numbers preserve the historical Wasmoon ABI. They are owned here so reusable MachV ISA policy does not decide VMContext or cached-pointer roles.

    wasm_runtime_symbols

    wasm_trap_payload

    fn wasm_trap_payload(reason : String) -> Int

    Map Wasm trap reasons to the payload consumed by Wasmoon's native trap handler. MachV only carries the integer payload; this module owns the Wasmoon-specific reason-to-payload policy.