Class NativeEngineBindings
java.lang.Object
ai.tegmentum.wasmtime4j.panama.NativeEngineBindings
Native function bindings for Engine and Module operations.
Provides type-safe wrappers for all Wasmtime engine lifecycle and module compilation and
introspection native functions. Hot-path methods use eagerly initialized volatile MethodHandle fields for invokeExact optimization.
Store-related bindings are in NativeStoreBindings.
This class follows the singleton pattern with initialization-on-demand holder.
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFunctionBinding(String functionName, FunctionDescriptor descriptor) Registers a native function binding with a given descriptor.<T> TcallNativeFunction(String functionName, Class<T> returnType, Object... args) Calls a native function with type safety.codeBuilderCompileComponent(MemorySegment builderPtr) Compiles a component from the code builder.byte[]codeBuilderCompileComponentSerialized(MemorySegment builderPtr) Compiles a component to serialized bytes from the code builder.codeBuilderCompileModule(MemorySegment builderPtr) Compiles a module from the code builder.byte[]codeBuilderCompileModuleSerialized(MemorySegment builderPtr) Compiles a module to serialized bytes from the code builder.voidcodeBuilderCompileTimeBuiltinsBinary(MemorySegment builderPtr, String name, byte[] wasmBytes) Adds compile-time builtins from binary bytes to the code builder.voidcodeBuilderCompileTimeBuiltinsBinaryOrText(MemorySegment builderPtr, String name, byte[] wasmBytes) Adds compile-time builtins from binary or text bytes to the code builder.codeBuilderCreate(MemorySegment enginePtr) Creates a new CodeBuilder for the given engine.voidcodeBuilderDestroy(MemorySegment builderPtr) Destroys a code builder.voidcodeBuilderDwarfPackage(MemorySegment builderPtr, byte[] dwarfBytes) Sets DWARF package bytes on the code builder.voidcodeBuilderExposeUnsafeIntrinsics(MemorySegment builderPtr, String importName) Exposes unsafe intrinsics at the given import name on the code builder.voidcodeBuilderHint(MemorySegment builderPtr, int hintOrdinal) Sets hint on the code builder.voidcodeBuilderWasmBinary(MemorySegment builderPtr, byte[] wasmBytes) Sets wasm binary bytes on the code builder.voidcodeBuilderWasmBinaryOrText(MemorySegment builderPtr, byte[] wasmBytes) Sets wasm binary or text bytes on the code builder.booleanengineCoredumpOnTrapEnabled(MemorySegment enginePtr) Checks if coredump generation on trap is enabled.engineCreateSharedMemory(MemorySegment enginePtr, int initialPages, int maxPages) Creates a standalone shared memory from an engine.engineCreateWeak(MemorySegment enginePtr) Creates a weak reference to an engine.engineCreateWithConfig(ai.tegmentum.wasmtime4j.config.EngineConfig config) Creates a new Wasmtime engine with extended configuration.engineCreateWithExtensions(ai.tegmentum.wasmtime4j.config.EngineConfig config) Creates a new engine with JSON configuration and all optional extension traits.voidengineDestroy(MemorySegment enginePtr) Destroys a Wasmtime engine.intengineDetectHostFeature(String featureName) Detects whether a host CPU feature is available.intengineDetectPrecompiled(MemorySegment enginePtr, MemorySegment bytesPtr, long bytesLen) Detects whether bytes are a precompiled artifact.booleanengineEpochInterruptionEnabled(MemorySegment enginePtr) Checks if epoch interruption is enabled.booleanengineFuelEnabled(MemorySegment enginePtr) Checks if fuel is enabled.voidengineIncrementEpoch(MemorySegment enginePtr) Increments the epoch counter.booleanengineIsAsync(MemorySegment enginePtr) Checks if async support is enabled for the engine.booleanengineIsPulley(MemorySegment enginePtr) Checks if the Pulley interpreter is being used.booleanengineIsRecording(MemorySegment enginePtr) Checks if the engine is configured for execution recording.booleanengineIsReplaying(MemorySegment enginePtr) Checks if the engine is configured for execution replaying.long[]enginePoolingAllocatorMetrics(MemorySegment enginePtr) Gets pooling allocator metrics from the engine.byte[]enginePrecompileCompatibilityHash(MemorySegment enginePtr) Gets the precompilation compatibility hash for this engine.byte[]enginePrecompileComponent(MemorySegment enginePtr, byte[] wasmBytes) Precompiles a WebAssembly component for AOT usage.byte[]enginePrecompileModule(MemorySegment enginePtr, byte[] wasmBytes) Precompiles WebAssembly bytecode into a serialized form for ahead-of-time (AOT) usage.booleanengineSame(MemorySegment enginePtr1, MemorySegment enginePtr2) Checks if two engines are the same (share the same underlying Wasmtime engine).longengineStackSizeLimit(MemorySegment enginePtr) Gets the stack size limit.booleanengineSupportsFeature(MemorySegment enginePtr, String featureName) Checks if engine supports a feature by name.intengineUnloadProcessHandlers(MemorySegment enginePtr) Unloads process-level signal handlers installed by Wasmtime.protected Object[]extractValueForNative(ai.tegmentum.wasmtime4j.WasmValue value) Extracts value components from WasmValue for passing to native code.voidfreeAddressMap(MemorySegment codeOffsetsPtr, MemorySegment wasmOffsetsPtr, long count) Frees address map arrays allocated by native code.voidfreeByteArray(MemorySegment dataPtr, long len) Frees a byte array allocated by native code.protected ai.tegmentum.wasmtime4j.panama.NativeBindingsBase.FunctionBindinggetFunctionBinding(String functionName) Gets a registered function binding by name.static NativeEngineBindingsGets the singleton instance.intguestProfilerCallHook(MemorySegment profilerPtr, MemorySegment storePtr, int hookKind) Records a call hook transition.voidguestProfilerDestroy(MemorySegment profilerPtr) Destroys a guest profiler.intguestProfilerFinish(MemorySegment profilerPtr, MemorySegment dataOut, MemorySegment lenOut) Finishes profiling and returns the profile data.voidguestProfilerFreeData(MemorySegment dataPtr, long len) Frees profile data returned by finish.guestProfilerNew(MemorySegment enginePtr, MemorySegment moduleNamePtr, long intervalNanos, MemorySegment modulePtrs, MemorySegment moduleNamePtrs, int moduleCount) Creates a new guest profiler.guestProfilerNewComponent(MemorySegment enginePtr, MemorySegment componentNamePtr, long intervalNanos, MemorySegment componentPtr, MemorySegment extraModulePtrs, MemorySegment extraModuleNamePtrs, int extraModuleCount) Creates a new guest profiler for a component.intguestProfilerSample(MemorySegment profilerPtr, MemorySegment storePtr, long deltaNanos) Collects a stack sample.booleanChecks if the bindings are initialized and available.protected voidMarks this binding set as initialized.intmoduleAddressMap(MemorySegment modulePtr, MemorySegment codeOffsetsOut, MemorySegment wasmOffsetsOut, MemorySegment countOut) Gets address map from a module.intmoduleCompileFromFile(MemorySegment enginePtr, MemorySegment pathPtr, MemorySegment modulePtrPtr) Compiles a WebAssembly module from a file path.intmoduleCompileWat(MemorySegment enginePtr, MemorySegment watText, MemorySegment modulePtr) Compiles a WebAssembly module from WAT (WebAssembly Text format).intmoduleCompileWithDwarf(MemorySegment enginePtr, MemorySegment wasmBytes, long wasmSize, MemorySegment dwarfBytes, long dwarfSize, MemorySegment modulePtr) Compiles a WebAssembly module with DWARF debug package.moduleCreate(MemorySegment enginePtr, MemorySegment wasmBytes, long wasmSize) Creates a WebAssembly module from bytecode (Panama FFI).intmoduleDeserialize(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment modulePtrPtr) Deserializes a WebAssembly module from serialized bytes.intmoduleDeserializeOpenFile(MemorySegment enginePtr, int fd, MemorySegment modulePtrPtr) Deserializes a module from an open file descriptor (Unix only).intmoduleDeserializeRaw(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment modulePtrPtr) Deserializes a module from raw bytes (no file format wrapper).voidmoduleDestroy(MemorySegment modulePtr) Destroys a WebAssembly module.longmoduleExportCount(MemorySegment modulePtr) Gets the number of exports in a module.longmoduleExportsLen(MemorySegment modulePtr) Gets the number of exports in a module.voidmoduleFreeString(MemorySegment strPtr) Frees a C string returned by module functions.intmoduleFromTrustedFile(MemorySegment enginePtr, MemorySegment pathPtr, MemorySegment modulePtrPtr) Loads a module from a trusted file, skipping code integrity validation.moduleGetAllFunctions(MemorySegment modulePtr) Gets all module functions (imports, exports, and internal) as JSON string.intmoduleGetExportIndex(MemorySegment modulePtr, MemorySegment namePtr) Gets the index of an export by name.intmoduleGetExportKind(MemorySegment modulePtr, MemorySegment name) Gets the kind of a specific export by name.longmoduleGetExportNames(MemorySegment modulePtr, MemorySegment namesOut, long maxCount) Gets export names from a module.moduleGetExportsJson(MemorySegment modulePtr) Gets module exports as JSON string.moduleGetImportsJson(MemorySegment modulePtr) Gets module imports as JSON string.moduleGetName(MemorySegment modulePtr) Gets the name of a module.intmoduleImageRange(MemorySegment modulePtr, MemorySegment startPtr, MemorySegment endPtr) Gets the image range of a compiled module.longmoduleImportsLen(MemorySegment modulePtr) Gets the number of imports in a module.intmoduleInitializeCowImage(MemorySegment modulePtr) Pre-initializes a module's copy-on-write image for faster instantiation.intmoduleResourcesRequired(MemorySegment modulePtr, MemorySegment minMemoryBytesOut, MemorySegment maxMemoryBytesOut, MemorySegment minTableElementsOut, MemorySegment maxTableElementsOut, MemorySegment numMemoriesOut, MemorySegment numTablesOut, MemorySegment numGlobalsOut, MemorySegment numFunctionsOut) Gets the resources required to instantiate a module.booleanmoduleSame(MemorySegment modulePtr1, MemorySegment modulePtr2) Checks if two modules share the same underlying compiled code.intmoduleSerialize(MemorySegment modulePtr, MemorySegment dataPtrPtr, MemorySegment lenPtr) Serializes a WebAssembly module.intmoduleText(MemorySegment modulePtr, MemorySegment dataPtrPtr, MemorySegment lenPtr) Gets compiled machine code text from a module.intmoduleValidate(MemorySegment wasmBytes, long wasmSize) Validates WebAssembly bytecode using full Wasmtime structural and semantic validation.voidserializerFreeBuffer(MemorySegment buffer, long size) Frees a buffer allocated by serialization functions.voidEagerly initializes Wasmtime's thread-local state for the current thread.protected voidvalidatePointer(MemorySegment pointer, String name) Validates that a pointer is not null.protected voidvalidateSize(long size, String name) Validates that a size is positive.voidweakEngineDestroy(MemorySegment weakPtr) Destroys a weak engine reference.weakEngineUpgrade(MemorySegment weakPtr) Upgrades a weak engine reference to a strong engine.
-
Method Details
-
getInstance
Gets the singleton instance.- Returns:
- the singleton instance
- Throws:
RuntimeException- if initialization fails
-
engineCreateWithConfig
Creates a new Wasmtime engine with extended configuration.- Parameters:
config- the engine configuration- Returns:
- memory segment pointer to the engine, or null on failure
-
engineCreateWithExtensions
Creates a new engine with JSON configuration and all optional extension traits.- Parameters:
config- the engine configuration (may have cache store, memory creator, stack creator, and/or custom code memory set)- Returns:
- memory segment pointer to the engine, or null on failure
-
engineDestroy
Destroys a Wasmtime engine.- Parameters:
enginePtr- pointer to the engine to destroy
-
engineSupportsFeature
Checks if engine supports a feature by name.- Parameters:
enginePtr- pointer to the enginefeatureName- feature name string- Returns:
- true if supported, false otherwise
-
engineStackSizeLimit
Gets the stack size limit.- Parameters:
enginePtr- pointer to the engine- Returns:
- stack size limit in bytes, or -1 if not set
-
engineFuelEnabled
Checks if fuel is enabled.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if fuel is enabled, false otherwise
-
engineEpochInterruptionEnabled
Checks if epoch interruption is enabled.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if epoch interruption is enabled, false otherwise
-
engineCoredumpOnTrapEnabled
Checks if coredump generation on trap is enabled.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if coredump generation is enabled, false otherwise
-
engineSame
Checks if two engines are the same (share the same underlying Wasmtime engine).- Parameters:
enginePtr1- pointer to the first engineenginePtr2- pointer to the second engine- Returns:
- true if both engines share the same underlying engine
-
engineIsAsync
Checks if async support is enabled for the engine.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if async support is enabled, false otherwise
-
engineIsRecording
Checks if the engine is configured for execution recording.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if recording is enabled, false otherwise
-
engineIsReplaying
Checks if the engine is configured for execution replaying.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if replaying is enabled, false otherwise
-
engineIncrementEpoch
Increments the epoch counter.This method is signal-safe and performs only an atomic increment. The epoch counter is used for epoch-based interruption of WebAssembly execution.
- Parameters:
enginePtr- pointer to the engine
-
engineDetectHostFeature
Detects whether a host CPU feature is available.- Parameters:
featureName- the feature name (e.g., "sse4.2", "avx2")- Returns:
- 1 if available, 0 if not
-
tlsEagerInitialize
public void tlsEagerInitialize()Eagerly initializes Wasmtime's thread-local state for the current thread. -
engineUnloadProcessHandlers
Unloads process-level signal handlers installed by Wasmtime.- Parameters:
enginePtr- pointer to the engine (consumed by this call)- Returns:
- 0 on success, -1 on failure
-
engineIsPulley
Checks if the Pulley interpreter is being used.- Parameters:
enginePtr- pointer to the engine- Returns:
- true if Pulley interpreter is being used, false if using Cranelift JIT
-
enginePrecompileCompatibilityHash
Gets the precompilation compatibility hash for this engine.- Parameters:
enginePtr- pointer to the engine- Returns:
- the compatibility hash as a byte array, or null if not available
-
enginePrecompileModule
public byte[] enginePrecompileModule(MemorySegment enginePtr, byte[] wasmBytes) throws ai.tegmentum.wasmtime4j.exception.WasmException Precompiles WebAssembly bytecode into a serialized form for ahead-of-time (AOT) usage.This method compiles the WebAssembly binary into a serialized form that can be later loaded via Module.deserialize() without needing to recompile.
- Parameters:
enginePtr- pointer to the enginewasmBytes- the WebAssembly bytecode to precompile- Returns:
- the precompiled serialized module bytes
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if precompilation fails
-
serializerFreeBuffer
Frees a buffer allocated by serialization functions.- Parameters:
buffer- pointer to the buffer to freesize- size of the buffer
-
engineDetectPrecompiled
Detects whether bytes are a precompiled artifact.- Parameters:
enginePtr- the engine pointerbytesPtr- pointer to the bytes to inspectbytesLen- length of the bytes- Returns:
- -1 if not precompiled, 0 for MODULE, 1 for COMPONENT
-
enginePrecompileComponent
public byte[] enginePrecompileComponent(MemorySegment enginePtr, byte[] wasmBytes) throws ai.tegmentum.wasmtime4j.exception.WasmException Precompiles a WebAssembly component for AOT usage.- Parameters:
enginePtr- pointer to the enginewasmBytes- the WebAssembly component bytecode to precompile- Returns:
- the precompiled serialized component bytes
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if precompilation fails
-
enginePoolingAllocatorMetrics
Gets pooling allocator metrics from the engine.- Parameters:
enginePtr- pointer to the engine- Returns:
- a 12-element long array with metrics, or null if pooling is not enabled
-
engineCreateWeak
Creates a weak reference to an engine.- Parameters:
enginePtr- pointer to the engine- Returns:
- pointer to the weak engine, or NULL if creation failed
-
weakEngineUpgrade
Upgrades a weak engine reference to a strong engine.- Parameters:
weakPtr- pointer to the weak engine- Returns:
- pointer to the engine, or NULL if the engine has been dropped
-
weakEngineDestroy
Destroys a weak engine reference.- Parameters:
weakPtr- pointer to the weak engine to destroy
-
moduleCompileWithDwarf
public int moduleCompileWithDwarf(MemorySegment enginePtr, MemorySegment wasmBytes, long wasmSize, MemorySegment dwarfBytes, long dwarfSize, MemorySegment modulePtr) Compiles a WebAssembly module with DWARF debug package.- Parameters:
enginePtr- pointer to the enginewasmBytes- pointer to the WASM byteswasmSize- size of the WASM bytesdwarfBytes- pointer to the DWARF package bytesdwarfSize- size of the DWARF package bytesmodulePtr- pointer to store the compiled module- Returns:
- 0 on success, negative error code on failure
-
moduleCompileWat
public int moduleCompileWat(MemorySegment enginePtr, MemorySegment watText, MemorySegment modulePtr) Compiles a WebAssembly module from WAT (WebAssembly Text format).- Parameters:
enginePtr- pointer to the enginewatText- pointer to the WAT text stringmodulePtr- pointer to store the compiled module- Returns:
- 0 on success, negative error code on failure
-
moduleSerialize
Serializes a WebAssembly module.- Parameters:
modulePtr- pointer to the module to serializedataPtrPtr- pointer to receive the serialized data pointerlenPtr- pointer to receive the data length- Returns:
- 0 on success, non-zero on error
-
moduleDeserialize
public int moduleDeserialize(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment modulePtrPtr) Deserializes a WebAssembly module from serialized bytes.- Parameters:
enginePtr- pointer to the enginedataPtr- pointer to the serialized module datalen- length of the serialized datamodulePtrPtr- pointer to store the deserialized module pointer- Returns:
- 0 on success, negative error code on failure
-
moduleDestroy
Destroys a WebAssembly module.- Parameters:
modulePtr- pointer to the module to destroy
-
moduleCompileFromFile
public int moduleCompileFromFile(MemorySegment enginePtr, MemorySegment pathPtr, MemorySegment modulePtrPtr) Compiles a WebAssembly module from a file path.- Parameters:
enginePtr- pointer to the enginepathPtr- pointer to the file path (null-terminated string)modulePtrPtr- pointer to store the compiled module pointer- Returns:
- 0 on success, negative error code on failure
-
moduleSame
Checks if two modules share the same underlying compiled code.- Parameters:
modulePtr1- pointer to the first modulemodulePtr2- pointer to the second module- Returns:
- 1 if the modules are the same, 0 if not
-
moduleGetExportIndex
Gets the index of an export by name.- Parameters:
modulePtr- pointer to the modulenamePtr- pointer to the export name (null-terminated string)- Returns:
- the zero-based index, or -1 if not found
-
moduleInitializeCowImage
Pre-initializes a module's copy-on-write image for faster instantiation.- Parameters:
modulePtr- pointer to the module- Returns:
- 0 on success, negative error code on failure
-
moduleImageRange
Gets the image range of a compiled module.- Parameters:
modulePtr- pointer to the modulestartPtr- output pointer for the start address (u64)endPtr- output pointer for the end address (u64)- Returns:
- 0 on success, negative error code on failure
-
moduleResourcesRequired
public int moduleResourcesRequired(MemorySegment modulePtr, MemorySegment minMemoryBytesOut, MemorySegment maxMemoryBytesOut, MemorySegment minTableElementsOut, MemorySegment maxTableElementsOut, MemorySegment numMemoriesOut, MemorySegment numTablesOut, MemorySegment numGlobalsOut, MemorySegment numFunctionsOut) Gets the resources required to instantiate a module.- Parameters:
modulePtr- pointer to the moduleminMemoryBytesOut- output pointer for minimum memory bytes (i64)maxMemoryBytesOut- output pointer for maximum memory bytes (i64, -1 if unbounded)minTableElementsOut- output pointer for minimum table elements (i64)maxTableElementsOut- output pointer for maximum table elements (i64, -1 if unbounded)numMemoriesOut- output pointer for number of memories (i32)numTablesOut- output pointer for number of tables (i32)numGlobalsOut- output pointer for number of globals (i32)numFunctionsOut- output pointer for number of functions (i32)- Returns:
- 0 on success, negative error code on failure
-
moduleCreate
Creates a WebAssembly module from bytecode (Panama FFI).- Parameters:
enginePtr- pointer to the enginewasmBytes- pointer to the WASM bytecodewasmSize- size of the WASM bytecode- Returns:
- memory segment pointer to the module, or null on failure
-
moduleValidate
Validates WebAssembly bytecode using full Wasmtime structural and semantic validation.- Parameters:
wasmBytes- pointer to the WASM bytecodewasmSize- size of the WASM bytecode in bytes- Returns:
- 0 on success (valid), non-zero on failure (invalid)
-
moduleImportsLen
Gets the number of imports in a module.- Parameters:
modulePtr- pointer to the module- Returns:
- the number of imports
-
moduleExportsLen
Gets the number of exports in a module.- Parameters:
modulePtr- pointer to the module- Returns:
- the number of exports
-
moduleGetExportsJson
Gets module exports as JSON string.- Parameters:
modulePtr- pointer to the module- Returns:
- MemorySegment pointing to JSON string, or NULL on error
-
moduleGetImportsJson
Gets module imports as JSON string.- Parameters:
modulePtr- pointer to the module- Returns:
- MemorySegment pointing to JSON string, or NULL on error
-
moduleGetAllFunctions
Gets all module functions (imports, exports, and internal) as JSON string.- Parameters:
modulePtr- pointer to the module- Returns:
- MemorySegment pointing to JSON string, or NULL on error
-
moduleFreeString
Frees a C string returned by module functions.- Parameters:
strPtr- pointer to the string to free
-
moduleText
Gets compiled machine code text from a module.- Parameters:
modulePtr- pointer to the moduledataPtrPtr- output pointer for the data pointerlenPtr- output pointer for the data length- Returns:
- 0 on success, negative error code on failure
-
moduleAddressMap
public int moduleAddressMap(MemorySegment modulePtr, MemorySegment codeOffsetsOut, MemorySegment wasmOffsetsOut, MemorySegment countOut) Gets address map from a module.- Parameters:
modulePtr- pointer to the modulecodeOffsetsOut- output pointer for code offsets arraywasmOffsetsOut- output pointer for wasm offsets arraycountOut- output pointer for the number of entries- Returns:
- 0 on success, 1 if address map not available, -1 on error
-
moduleFromTrustedFile
public int moduleFromTrustedFile(MemorySegment enginePtr, MemorySegment pathPtr, MemorySegment modulePtrPtr) Loads a module from a trusted file, skipping code integrity validation.- Parameters:
enginePtr- pointer to the enginepathPtr- pointer to the file path (null-terminated string)modulePtrPtr- pointer to store the loaded module pointer- Returns:
- 0 on success, negative error code on failure
-
moduleDeserializeRaw
public int moduleDeserializeRaw(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment modulePtrPtr) Deserializes a module from raw bytes (no file format wrapper).- Parameters:
enginePtr- pointer to the enginedataPtr- pointer to the raw module byteslen- length of the raw datamodulePtrPtr- pointer to store the deserialized module pointer- Returns:
- 0 on success, negative error code on failure
-
moduleDeserializeOpenFile
Deserializes a module from an open file descriptor (Unix only).- Parameters:
enginePtr- pointer to the enginefd- the file descriptormodulePtrPtr- pointer to store the deserialized module pointer- Returns:
- 0 on success, negative error code on failure
-
freeByteArray
Frees a byte array allocated by native code.- Parameters:
dataPtr- pointer to the datalen- length of the data
-
freeAddressMap
Frees address map arrays allocated by native code.- Parameters:
codeOffsetsPtr- pointer to the code offsets arraywasmOffsetsPtr- pointer to the wasm offsets arraycount- number of entries
-
moduleGetName
Gets the name of a module.- Parameters:
modulePtr- pointer to the module- Returns:
- pointer to the module name string, or null if unnamed
-
moduleExportCount
Gets the number of exports in a module.- Parameters:
modulePtr- pointer to the module- Returns:
- the number of exports
-
moduleGetExportNames
Gets export names from a module.- Parameters:
modulePtr- pointer to the modulenamesOut- pointer to array that will hold char* pointersmaxCount- maximum number of names to retrieve- Returns:
- actual number of exports retrieved
-
moduleGetExportKind
Gets the kind of a specific export by name.- Parameters:
modulePtr- pointer to the modulename- pointer to null-terminated C string name- Returns:
- 0=not found, 1=function, 2=global, 3=memory, 4=table
-
guestProfilerNew
public MemorySegment guestProfilerNew(MemorySegment enginePtr, MemorySegment moduleNamePtr, long intervalNanos, MemorySegment modulePtrs, MemorySegment moduleNamePtrs, int moduleCount) Creates a new guest profiler.- Parameters:
enginePtr- pointer to the enginemoduleNamePtr- pointer to module name C stringintervalNanos- sampling interval in nanosecondsmodulePtrs- pointer to array of module pointersmoduleNamePtrs- pointer to array of module name C stringsmoduleCount- number of modules- Returns:
- pointer to the profiler, or NULL on failure
-
guestProfilerNewComponent
public MemorySegment guestProfilerNewComponent(MemorySegment enginePtr, MemorySegment componentNamePtr, long intervalNanos, MemorySegment componentPtr, MemorySegment extraModulePtrs, MemorySegment extraModuleNamePtrs, int extraModuleCount) Creates a new guest profiler for a component.- Parameters:
enginePtr- pointer to the enginecomponentNamePtr- pointer to component name C stringintervalNanos- sampling interval in nanosecondscomponentPtr- pointer to the componentextraModulePtrs- pointer to array of extra module pointersextraModuleNamePtrs- pointer to array of extra module name C stringsextraModuleCount- number of extra modules- Returns:
- pointer to the profiler, or NULL on failure
-
guestProfilerSample
Collects a stack sample.- Parameters:
profilerPtr- pointer to the profilerstorePtr- pointer to the storedeltaNanos- CPU time since previous sample in nanoseconds- Returns:
- 0 on success, -1 on error, -2 if already finished
-
guestProfilerCallHook
Records a call hook transition.- Parameters:
profilerPtr- pointer to the profilerstorePtr- pointer to the storehookKind- 0=CallingWasm, 1=ReturningFromWasm, 2=CallingHost, 3=ReturningFromHost- Returns:
- 0 on success, -1 on error, -2 if already finished
-
guestProfilerFinish
public int guestProfilerFinish(MemorySegment profilerPtr, MemorySegment dataOut, MemorySegment lenOut) Finishes profiling and returns the profile data.- Parameters:
profilerPtr- pointer to the profilerdataOut- pointer to receive the data pointerlenOut- pointer to receive the data length- Returns:
- 0 on success, -1 on error, -2 if already finished
-
guestProfilerFreeData
Frees profile data returned by finish.- Parameters:
dataPtr- pointer to the datalen- length of the data
-
guestProfilerDestroy
Destroys a guest profiler.- Parameters:
profilerPtr- pointer to the profiler to destroy
-
codeBuilderCreate
public MemorySegment codeBuilderCreate(MemorySegment enginePtr) throws ai.tegmentum.wasmtime4j.exception.WasmException Creates a new CodeBuilder for the given engine.- Parameters:
enginePtr- pointer to the engine- Returns:
- pointer to the new CodeBuilder
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if creation fails
-
codeBuilderWasmBinary
public void codeBuilderWasmBinary(MemorySegment builderPtr, byte[] wasmBytes) throws ai.tegmentum.wasmtime4j.exception.WasmException Sets wasm binary bytes on the code builder.- Parameters:
builderPtr- pointer to the code builderwasmBytes- the wasm bytes- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if setting bytes fails
-
codeBuilderWasmBinaryOrText
public void codeBuilderWasmBinaryOrText(MemorySegment builderPtr, byte[] wasmBytes) throws ai.tegmentum.wasmtime4j.exception.WasmException Sets wasm binary or text bytes on the code builder.- Parameters:
builderPtr- pointer to the code builderwasmBytes- the wasm or WAT bytes- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if setting bytes fails
-
codeBuilderDwarfPackage
public void codeBuilderDwarfPackage(MemorySegment builderPtr, byte[] dwarfBytes) throws ai.tegmentum.wasmtime4j.exception.WasmException Sets DWARF package bytes on the code builder.- Parameters:
builderPtr- pointer to the code builderdwarfBytes- the DWARF package bytes- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if setting bytes fails
-
codeBuilderHint
Sets hint on the code builder.- Parameters:
builderPtr- pointer to the code builderhintOrdinal- the hint ordinal (0=MODULE, 1=COMPONENT)
-
codeBuilderCompileModule
public MemorySegment codeBuilderCompileModule(MemorySegment builderPtr) throws ai.tegmentum.wasmtime4j.exception.WasmException Compiles a module from the code builder.- Parameters:
builderPtr- pointer to the code builder- Returns:
- pointer to the compiled module
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if compilation fails
-
codeBuilderCompileModuleSerialized
public byte[] codeBuilderCompileModuleSerialized(MemorySegment builderPtr) throws ai.tegmentum.wasmtime4j.exception.WasmException Compiles a module to serialized bytes from the code builder.- Parameters:
builderPtr- pointer to the code builder- Returns:
- the serialized module bytes
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if compilation fails
-
codeBuilderCompileComponent
public MemorySegment codeBuilderCompileComponent(MemorySegment builderPtr) throws ai.tegmentum.wasmtime4j.exception.WasmException Compiles a component from the code builder.- Parameters:
builderPtr- pointer to the code builder- Returns:
- pointer to the compiled component
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if compilation fails
-
codeBuilderCompileComponentSerialized
public byte[] codeBuilderCompileComponentSerialized(MemorySegment builderPtr) throws ai.tegmentum.wasmtime4j.exception.WasmException Compiles a component to serialized bytes from the code builder.- Parameters:
builderPtr- pointer to the code builder- Returns:
- the serialized component bytes
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if compilation fails
-
codeBuilderCompileTimeBuiltinsBinary
public void codeBuilderCompileTimeBuiltinsBinary(MemorySegment builderPtr, String name, byte[] wasmBytes) Adds compile-time builtins from binary bytes to the code builder.- Parameters:
builderPtr- pointer to the code buildername- the name of the builtin componentwasmBytes- the wasm binary bytes
-
codeBuilderCompileTimeBuiltinsBinaryOrText
public void codeBuilderCompileTimeBuiltinsBinaryOrText(MemorySegment builderPtr, String name, byte[] wasmBytes) Adds compile-time builtins from binary or text bytes to the code builder.- Parameters:
builderPtr- pointer to the code buildername- the name of the builtin componentwasmBytes- the wasm binary or WAT text bytes
-
codeBuilderExposeUnsafeIntrinsics
Exposes unsafe intrinsics at the given import name on the code builder.- Parameters:
builderPtr- pointer to the code builderimportName- the import name for unsafe intrinsics
-
codeBuilderDestroy
Destroys a code builder.- Parameters:
builderPtr- pointer to the code builder to destroy
-
markInitialized
protected void markInitialized()Marks this binding set as initialized. Subclasses should call this after registering all function bindings and initializing hot-path MethodHandles. -
isInitialized
public boolean isInitialized()Checks if the bindings are initialized and available.- Returns:
- true if initialized, false otherwise
-
addFunctionBinding
Registers a native function binding with a given descriptor.- Parameters:
functionName- the native function symbol namedescriptor- the Panama FunctionDescriptor for the native function
-
getFunctionBinding
protected ai.tegmentum.wasmtime4j.panama.NativeBindingsBase.FunctionBinding getFunctionBinding(String functionName) Gets a registered function binding by name.- Parameters:
functionName- the native function symbol name- Returns:
- the function binding, or null if not registered
-
callNativeFunction
Calls a native function with type safety.- Parameters:
functionName- the name of the functionreturnType- the expected return typeargs- the function arguments- Returns:
- the function result
- Throws:
IllegalStateException- if the function call fails
-
validatePointer
Validates that a pointer is not null.- Parameters:
pointer- the pointer to validatename- the name of the parameter for error messages- Throws:
IllegalArgumentException- if the pointer is null
-
validateSize
Validates that a size is positive.- Parameters:
size- the size to validatename- the name of the parameter for error messages- Throws:
IllegalArgumentException- if the size is not positive
-
extractValueForNative
Extracts value components from WasmValue for passing to native code.- Parameters:
value- the WasmValue to extract components from- Returns:
- array containing [i32Value, i64Value, f32Value, f64Value, refValue]
-