Class NativeComponentBindings
Provides type-safe wrappers for all component model native functions including component engine lifecycle, component loading and instantiation, component linker operations, enhanced component engine with instance IDs, component metrics, and WIT value marshalling.
This class covers the following functional areas:
- Component engine creation and destruction
- Component loading from bytes and validation
- Component instantiation and instance management
- Component export/import introspection
- Component linker with WASI Preview 2 and HTTP support
- Enhanced component engine with instance ID tracking
- Component metrics collection and querying
- WIT value serialization and deserialization
- Component orchestrator and resource management
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFunctionBinding(String functionName, FunctionDescriptor descriptor) Registers a native function binding with a given descriptor.intasyncValClose(long handle) Closes an async val handle (Future/Stream/ErrorContext) in the native AsyncValRegistry.<T> TcallNativeFunction(String functionName, Class<T> returnType, Object... args) Calls a native function with type safety.intcomponentCompileWat(MemorySegment engineHandle, MemorySegment watBytes, long watLen, MemorySegment componentOut) Compiles a component from WAT text.longcomponentExportCount(MemorySegment componentHandle) Gets the count of exports in a component.voidcomponentExportIndexDestroy(MemorySegment indexPtr) Destroys a component export index handle.intcomponentExportsInterface(MemorySegment componentHandle, MemorySegment interfaceName) Checks if a component exports an interface.voidcomponentFreeSerializedData(MemorySegment dataPtr, long len) Frees serialized component data previously returned bycomponentSerialize(java.lang.foreign.MemorySegment, java.lang.foreign.MemorySegment, java.lang.foreign.MemorySegment).voidcomponentFreeString(MemorySegment stringPtr) Frees a string returned by component functions.voidcomponentFreeStringArray(MemorySegment stringsPtr, int count) Frees an array of C strings returned by component functions.intcomponentGetExportIndex(MemorySegment componentPtr, MemorySegment instanceIndexPtr, MemorySegment name, MemorySegment indexOut) Looks up a component export index by name.intcomponentGetExportName(MemorySegment componentHandle, long index, MemorySegment nameOut) Gets an export interface name by index.intcomponentGetFullTypeJson(MemorySegment componentHandle, MemorySegment engineHandle, MemorySegment jsonOut) Gets the full component type as a JSON string with complete type information.intcomponentGetImportName(MemorySegment componentHandle, long index, MemorySegment nameOut) Gets an import interface name by index.longcomponentGetSize(MemorySegment componentHandle) Gets the size of a component.componentHostCallbackAllocResult(long len) Allocates a result buffer for host function callback results.intcomponentImageRange(MemorySegment componentPtr, MemorySegment startPtr, MemorySegment endPtr) Gets the image range of a compiled component.longcomponentImportCount(MemorySegment componentHandle) Gets the count of imports in a component.intcomponentImportsInterface(MemorySegment componentHandle, MemorySegment interfaceName) Checks if a component imports an interface.intcomponentInitializeCowImage(MemorySegment componentPtr) Pre-initializes a component's copy-on-write image for faster instantiation.longGets the average instantiation time in nanoseconds from a pre-instantiated component.voidDestroys a pre-instantiated component handle.longGets the instance count from a pre-instantiated component.intcomponentInstancePreInstantiate(MemorySegment prePtr, MemorySegment instanceOutPtr) Instantiates from a pre-instantiated component.intcomponentInstancePreInstantiateWithConfig(MemorySegment prePtr, long fuelLimit, long epochDeadline, long maxMemoryBytes, long maxTableElements, long maxInstances, long maxTables, long maxMemories, byte trapOnGrowFailure, MemorySegment instanceOutPtr) Instantiates from a pre-instantiated component with store configuration.intChecks if a pre-instantiated component handle is valid.longGets the preparation time in nanoseconds from a pre-instantiated component.intcomponentLinkerAddWasiEnv(MemorySegment linkerPtr, MemorySegment keyPtr, MemorySegment valuePtr) Adds a WASI Preview 2 environment variable to the component linker.intcomponentLinkerAddWasiPreopenDir(MemorySegment linkerPtr, MemorySegment hostPathPtr, MemorySegment guestPathPtr, int dirPermsBits, int filePermsBits) Adds a preopened directory for WASI Preview 2 with granular permissions.voidcomponentLinkerAllowShadowing(MemorySegment linkerPtr, int allow) Allow or disallow shadowing of previously defined names.componentLinkerCreateWithEngine(MemorySegment enginePtr) Creates a new component linker from a Wasmtime engine.intcomponentLinkerDefineHostFunction(MemorySegment linkerPtr, MemorySegment witPathPtr, long witPathLen, MemorySegment callbackFn, long callbackId) Defines a host function on the component linker using a WIT path.intcomponentLinkerDefineHostFunctionAsync(MemorySegment linkerPtr, MemorySegment witPathPtr, long witPathLen, MemorySegment callbackFn, long callbackId) Defines an async host function on the component linker using a WIT path.intcomponentLinkerDefineModule(MemorySegment linkerPtr, MemorySegment instancePathPtr, long instancePathLen, MemorySegment namePtr, long nameLen, MemorySegment modulePtr) Defines a core module on the component linker.intcomponentLinkerDefineResource(MemorySegment linkerPtr, MemorySegment interfacePathPtr, long interfacePathLen, MemorySegment resourceNamePtr, long resourceNameLen, int resourceId, MemorySegment destructorFn, long destructorCallbackId) Defines a host resource type on the component linker.intcomponentLinkerDefineUnknownImportsAsTraps(MemorySegment linkerPtr, MemorySegment componentPtr) Define all unknown imports as traps.voidcomponentLinkerDestroy(MemorySegment linkerPtr) Destroys a component linker.intcomponentLinkerEnableWasiConfig(MemorySegment linkerPtr) Enables WASI Config in the component linker.intcomponentLinkerEnableWasiHttp(MemorySegment linkerPtr) Enables WASI HTTP in the component linker.intcomponentLinkerEnableWasiHttpWithConfig(MemorySegment linkerPtr, long fieldSizeLimit) Enables WASI HTTP with configuration in the component linker.intcomponentLinkerEnableWasiP2(MemorySegment linkerPtr) Enables WASI Preview 2 in the component linker.intcomponentLinkerGetFunctions(MemorySegment linkerPtr, MemorySegment namespace, MemorySegment interfaceName, MemorySegment jsonOut) Gets all defined functions for a specific interface as a JSON array string.intcomponentLinkerGetInterfaces(MemorySegment linkerPtr, MemorySegment jsonOut) Gets all defined interfaces from the native linker as a JSON array string.longcomponentLinkerHostFunctionCount(MemorySegment linkerPtr) Gets the number of host functions defined in the linker.intcomponentLinkerInstantiate(MemorySegment linkerPtr, MemorySegment componentPtr, MemorySegment instanceOutPtr) Instantiates a component using the component linker.componentLinkerInstantiatePre(MemorySegment linkerPtr, MemorySegment componentPtr) Pre-instantiates a component using the linker.longcomponentLinkerInterfaceCount(MemorySegment linkerPtr) Gets the number of interfaces defined in the linker.intcomponentLinkerIsValid(MemorySegment linkerPtr) Checks if a component linker is valid.intcomponentLinkerSetAsyncSupport(MemorySegment linkerPtr, int enabled) Sets async support on the linker.intcomponentLinkerSetConfigVariables(MemorySegment linkerPtr, Map<String, String> variables) Sets configuration variables for WASI Config.intcomponentLinkerSetWasiAllowBlockingCurrentThread(MemorySegment linkerPtr, int allow) Sets whether blocking the current thread is allowed.intcomponentLinkerSetWasiAllowIpNameLookup(MemorySegment linkerPtr, int allow) Sets whether IP name lookup (DNS) is allowed.intcomponentLinkerSetWasiAllowNetwork(MemorySegment linkerPtr, int allow) Sets whether network access is allowed in WASI Preview 2.intcomponentLinkerSetWasiAllowTcp(MemorySegment linkerPtr, int allow) Sets whether TCP sockets are allowed.intcomponentLinkerSetWasiAllowUdp(MemorySegment linkerPtr, int allow) Sets whether UDP sockets are allowed.intcomponentLinkerSetWasiArgs(MemorySegment linkerPtr, MemorySegment argsJsonPtr) Sets WASI Preview 2 arguments for the component linker.intcomponentLinkerSetWasiInheritArgs(MemorySegment linkerPtr, int inherit) Sets whether to inherit arguments from host in WASI Preview 2.intcomponentLinkerSetWasiInheritEnv(MemorySegment linkerPtr, int inherit) Sets whether to inherit environment from host in WASI Preview 2.intcomponentLinkerSetWasiInheritStderr(MemorySegment linkerPtr, int inherit) Sets whether to inherit stderr individually.intcomponentLinkerSetWasiInheritStdin(MemorySegment linkerPtr, int inherit) Sets whether to inherit stdin individually.intcomponentLinkerSetWasiInheritStdio(MemorySegment linkerPtr, int inherit) Sets whether to inherit stdio from host in WASI Preview 2.intcomponentLinkerSetWasiInheritStdout(MemorySegment linkerPtr, int inherit) Sets whether to inherit stdout individually.intcomponentLinkerSetWasiInsecureRandom(MemorySegment linkerPtr, MemorySegment fillBytesFn, long callbackId) Sets a custom insecure random callback.intcomponentLinkerSetWasiInsecureRandomSeed(MemorySegment linkerPtr, long seed) Sets the insecure random seed.intcomponentLinkerSetWasiMaxRandomSize(MemorySegment linkerPtr, long maxSize) Sets the maximum random buffer size for WASI random operations.intcomponentLinkerSetWasiMonotonicClock(MemorySegment linkerPtr, MemorySegment nowFn, MemorySegment resolutionFn, long callbackId) Sets a custom monotonic clock callback.intcomponentLinkerSetWasiSecureRandom(MemorySegment linkerPtr, MemorySegment fillBytesFn, long callbackId) Sets a custom secure random callback.intcomponentLinkerSetWasiSocketAddrCheck(MemorySegment linkerPtr, MemorySegment checkFn, long callbackId) Sets a socket address check callback.intcomponentLinkerSetWasiStdinBytes(MemorySegment linkerPtr, MemorySegment data, long dataLen) Sets stdin bytes for the WASI context.intcomponentLinkerSetWasiWallClock(MemorySegment linkerPtr, MemorySegment nowFn, MemorySegment resolutionFn, long callbackId) Sets a custom wall clock callback.intcomponentLinkerSubstitutedTypeJson(MemorySegment linkerHandle, MemorySegment componentHandle, MemorySegment jsonOut) Gets the substituted component type as a JSON string.intcomponentLinkerWasiHttpEnabled(MemorySegment linkerPtr) Checks if WASI HTTP is enabled in the linker.intcomponentLinkerWasiP2Enabled(MemorySegment linkerPtr) Checks if WASI Preview 2 is enabled in the linker.intcomponentSerialize(MemorySegment componentPtr, MemorySegment dataPtrOut, MemorySegment lenOut) Serializes a component to bytes.intcomponentValidate(MemorySegment componentPtr, MemorySegment witInterface) Validates a component against a WIT interface.createAsyncValCloseAction(long handle) Creates aRunnableclose action that invokesasyncValClose(long)for the given handle.voiddestroyComponent(MemorySegment componentPtr) Destroys a component.Creates an enhanced component engine for managing component instances.voidenhancedComponentEngineDestroy(MemorySegment engineHandle) Destroys an enhanced component engine and all its instances.booleanenhancedComponentEngineIsAsync(MemorySegment enginePtr) Checks if async support is enabled for an enhanced component engine.intenhancedComponentGetExports(MemorySegment engineHandle, long instanceId, MemorySegment functionsOut, MemorySegment countOut) Gets the list of exported function names using instance ID.intenhancedComponentInstanceGetExport(MemorySegment enginePtr, long instanceId, MemorySegment parentIndexPtr, MemorySegment namePtr, long nameLen, MemorySegment outIndexPtr) Looks up a general export by name on a component instance.intenhancedComponentInstanceGetModule(MemorySegment enginePtr, long instanceId, MemorySegment moduleName, MemorySegment moduleOut) Looks up a core module exported by a component instance.intenhancedComponentInstanceHasFunc(MemorySegment enginePtr, long instanceId, MemorySegment functionName) Checks if a component instance has a specific function export.intenhancedComponentInstanceHasFuncByIndex(MemorySegment enginePtr, long instanceId, MemorySegment indexPtr) Checks if a component instance has a function at the given export index.intenhancedComponentInstanceHasResource(MemorySegment enginePtr, long instanceId, MemorySegment resourceName) Checks if a resource type is exported by a component instance.intenhancedComponentInstantiate(MemorySegment engineHandle, MemorySegment componentHandle, MemorySegment instanceIdOut) Instantiates a component and returns an instance ID.intenhancedComponentInvoke(MemorySegment engineHandle, long instanceId, MemorySegment functionName, MemorySegment paramsPtr, int paramsCount, MemorySegment resultsOut, MemorySegment resultsCountOut) Invokes a component function using instance ID.intenhancedComponentLoadFromBytes(MemorySegment engineHandle, MemorySegment wasmBytes, long wasmSize, MemorySegment componentOut) Loads (compiles) a component from WebAssembly bytes.intenhancedComponentRunConcurrent(MemorySegment enginePtr, long instanceId, MemorySegment jsonPtr, long jsonLen, MemorySegment resultPtr, MemorySegment resultLen) Executes concurrent component function calls via the enhanced component engine.protected Object[]extractValueForNative(ai.tegmentum.wasmtime4j.WasmValue value) Extracts value components from WasmValue for passing to native code.voidfreeConcurrentResult(MemorySegment ptr, long len) Frees a result buffer allocated by the concurrent call function.protected ai.tegmentum.wasmtime4j.panama.NativeBindingsBase.FunctionBindinggetFunctionBinding(String functionName) Gets a registered function binding by name.static NativeComponentBindingsGets the singleton instance.booleanChecks if the bindings are initialized and available.protected voidMarks this binding set as initialized.intpanamaComponentDeserialize(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment componentPtrOut) Deserializes a component from bytes using the enhanced component engine.intpanamaComponentDeserializeFile(MemorySegment enginePtr, MemorySegment pathPtr, long pathLen, MemorySegment componentPtrOut) Deserializes a component from a file using the enhanced component engine.intpanamaComponentResourcesRequired(MemorySegment componentPtr, MemorySegment numMemoriesOut, MemorySegment maxMemoryOut, MemorySegment numTablesOut, MemorySegment maxTableOut) Gets the resources required by a component.intresourceAnyDrop(MemorySegment enginePtr, long instanceId, long resourceHandle) Drops a ResourceAny held in the global resource registry.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.intwitValueDeserialize(int typeDiscriminator, MemorySegment dataPtr, long dataLen, MemorySegment outValue, MemorySegment outLen) Deserializes a WIT value from binary format.voidwitValueFreeBuffer(MemorySegment ptr, long len) Frees a buffer allocated by WIT value marshalling functions.intwitValueSerialize(int typeDiscriminator, MemorySegment valuePtr, long valueLen, MemorySegment outData, MemorySegment outLen) Serializes a WIT value to binary format.booleanwitValueValidateDiscriminator(int typeDiscriminator) Validates a type discriminator.
-
Method Details
-
getInstance
Gets the singleton instance.- Returns:
- the singleton instance
- Throws:
RuntimeException- if initialization fails
-
destroyComponent
Destroys a component.- Parameters:
componentPtr- pointer to the component to destroy
-
componentGetSize
Gets the size of a component.- Parameters:
componentHandle- the component handle- Returns:
- the component size in bytes
-
componentExportsInterface
Checks if a component exports an interface.- Parameters:
componentHandle- the component handleinterfaceName- the interface name (C string)- Returns:
- 1 if exports the interface, 0 otherwise
-
componentImportsInterface
Checks if a component imports an interface.- Parameters:
componentHandle- the component handleinterfaceName- the interface name (C string)- Returns:
- 1 if imports the interface, 0 otherwise
-
componentExportCount
Gets the count of exports in a component.- Parameters:
componentHandle- the component handle- Returns:
- number of exports
-
componentImportCount
Gets the count of imports in a component.- Parameters:
componentHandle- the component handle- Returns:
- number of imports
-
componentGetExportName
Gets an export interface name by index.- Parameters:
componentHandle- the component handleindex- the export indexnameOut- pointer to receive the name string- Returns:
- 0 on success, non-zero on error
-
componentGetImportName
Gets an import interface name by index.- Parameters:
componentHandle- the component handleindex- the import indexnameOut- pointer to receive the name string- Returns:
- 0 on success, non-zero on error
-
componentFreeString
Frees a string returned by component functions.- Parameters:
stringPtr- the string pointer to free
-
componentGetFullTypeJson
public int componentGetFullTypeJson(MemorySegment componentHandle, MemorySegment engineHandle, MemorySegment jsonOut) Gets the full component type as a JSON string with complete type information.- Parameters:
componentHandle- the component handleengineHandle- the engine handlejsonOut- pointer to receive the JSON string- Returns:
- 0 on success, non-zero on error
-
componentLinkerSubstitutedTypeJson
public int componentLinkerSubstitutedTypeJson(MemorySegment linkerHandle, MemorySegment componentHandle, MemorySegment jsonOut) Gets the substituted component type as a JSON string.- Parameters:
linkerHandle- the linker handlecomponentHandle- the component handlejsonOut- pointer to receive the JSON string- Returns:
- 0 on success, non-zero on error
-
componentFreeStringArray
Frees an array of C strings returned by component functions.- Parameters:
stringsPtr- pointer to array of string pointerscount- number of strings in the array
-
enhancedComponentEngineCreate
Creates an enhanced component engine for managing component instances.- Returns:
- pointer to the enhanced component engine, or NULL on failure
-
enhancedComponentLoadFromBytes
public int enhancedComponentLoadFromBytes(MemorySegment engineHandle, MemorySegment wasmBytes, long wasmSize, MemorySegment componentOut) Loads (compiles) a component from WebAssembly bytes.- Parameters:
engineHandle- the enhanced component engine handlewasmBytes- the WebAssembly component byteswasmSize- the size of the WebAssembly bytescomponentOut- output parameter for the component handle- Returns:
- error code (0 for success)
-
componentCompileWat
public int componentCompileWat(MemorySegment engineHandle, MemorySegment watBytes, long watLen, MemorySegment componentOut) Compiles a component from WAT text.- Parameters:
engineHandle- the enhanced component engine handlewatBytes- pointer to WAT text byteswatLen- length of WAT text bytescomponentOut- output parameter for the component pointer- Returns:
- 0 on success, non-zero error code on failure
-
componentValidate
Validates a component against a WIT interface.- Parameters:
componentPtr- pointer to the componentwitInterface- C string pointer to the WIT interface text- Returns:
- 1 if valid, 0 if invalid, negative on error
-
enhancedComponentInstantiate
public int enhancedComponentInstantiate(MemorySegment engineHandle, MemorySegment componentHandle, MemorySegment instanceIdOut) Instantiates a component and returns an instance ID.- Parameters:
engineHandle- the enhanced component engine handlecomponentHandle- the component handleinstanceIdOut- output parameter for the instance ID (u64)- Returns:
- 0 on success, non-zero error code on failure
-
enhancedComponentInvoke
public int enhancedComponentInvoke(MemorySegment engineHandle, long instanceId, MemorySegment functionName, MemorySegment paramsPtr, int paramsCount, MemorySegment resultsOut, MemorySegment resultsCountOut) Invokes a component function using instance ID.- Parameters:
engineHandle- the enhanced component engine handleinstanceId- the instance ID returned from instantiationfunctionName- the function name to invokeparamsPtr- pointer to the parameters arrayparamsCount- number of parametersresultsOut- output parameter for results arrayresultsCountOut- output parameter for results count- Returns:
- 0 on success, non-zero error code on failure
-
enhancedComponentGetExports
public int enhancedComponentGetExports(MemorySegment engineHandle, long instanceId, MemorySegment functionsOut, MemorySegment countOut) Gets the list of exported function names using instance ID.- Parameters:
engineHandle- the enhanced component engine handleinstanceId- the instance IDfunctionsOut- output parameter for array of function name pointerscountOut- output parameter for count of functions- Returns:
- 0 on success, non-zero error code on failure
-
enhancedComponentEngineIsAsync
Checks if async support is enabled for an enhanced component engine.- Parameters:
enginePtr- pointer to the enhanced component engine- Returns:
- true if async support is enabled
-
enhancedComponentInstanceHasFunc
public int enhancedComponentInstanceHasFunc(MemorySegment enginePtr, long instanceId, MemorySegment functionName) Checks if a component instance has a specific function export.- Parameters:
enginePtr- pointer to the enhanced component engineinstanceId- the component instance IDfunctionName- C string with the function name- Returns:
- 1 if found, 0 if not found, -1 on error
-
enhancedComponentInstanceGetModule
public int enhancedComponentInstanceGetModule(MemorySegment enginePtr, long instanceId, MemorySegment moduleName, MemorySegment moduleOut) Looks up a core module exported by a component instance.- Parameters:
enginePtr- pointer to the enhanced component engineinstanceId- the component instance IDmoduleName- C string with the module namemoduleOut- output pointer for the module handle- Returns:
- 0 on success, non-zero on error
-
enhancedComponentInstanceHasResource
public int enhancedComponentInstanceHasResource(MemorySegment enginePtr, long instanceId, MemorySegment resourceName) Checks if a resource type is exported by a component instance.- Parameters:
enginePtr- pointer to the enhanced component engineinstanceId- the component instance IDresourceName- C string with the resource name- Returns:
- 1 if found, 0 if not found, -1 on error
-
enhancedComponentEngineDestroy
Destroys an enhanced component engine and all its instances.- Parameters:
engineHandle- the enhanced component engine handle
-
witValueSerialize
public int witValueSerialize(int typeDiscriminator, MemorySegment valuePtr, long valueLen, MemorySegment outData, MemorySegment outLen) Serializes a WIT value to binary format.- Parameters:
typeDiscriminator- the type discriminator (1-6)valuePtr- pointer to the value datavalueLen- length of the value dataoutData- output buffer for serialized dataoutLen- output parameter for data length- Returns:
- 0 on success, non-zero on error
-
witValueDeserialize
public int witValueDeserialize(int typeDiscriminator, MemorySegment dataPtr, long dataLen, MemorySegment outValue, MemorySegment outLen) Deserializes a WIT value from binary format.- Parameters:
typeDiscriminator- the type discriminator (1-6)dataPtr- pointer to the serialized datadataLen- length of the dataoutValue- output buffer for deserialized valueoutLen- output parameter for value length- Returns:
- 0 on success, non-zero on error
-
witValueValidateDiscriminator
public boolean witValueValidateDiscriminator(int typeDiscriminator) Validates a type discriminator.- Parameters:
typeDiscriminator- the type discriminator to validate- Returns:
- true if valid (1), false otherwise (0)
-
witValueFreeBuffer
Frees a buffer allocated by WIT value marshalling functions.- Parameters:
ptr- pointer to the buffer to freelen- length of the buffer
-
componentLinkerCreateWithEngine
Creates a new component linker from a Wasmtime engine.- Parameters:
enginePtr- pointer to the Wasmtime engine- Returns:
- pointer to the new component linker, or null on failure
-
componentLinkerDestroy
Destroys a component linker.- Parameters:
linkerPtr- pointer to the component linker to destroy
-
componentLinkerIsValid
Checks if a component linker is valid.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 1 if valid, 0 if invalid
-
componentLinkerEnableWasiP2
Enables WASI Preview 2 in the component linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 0 on success, non-zero on error
-
componentLinkerEnableWasiHttp
Enables WASI HTTP in the component linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 0 on success, non-zero on error
-
componentLinkerEnableWasiHttpWithConfig
Enables WASI HTTP with configuration in the component linker.- Parameters:
linkerPtr- pointer to the component linkerfieldSizeLimit- maximum HTTP header field size (0 for default)- Returns:
- 0 on success, non-zero on error
-
componentLinkerEnableWasiConfig
Enables WASI Config in the component linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetConfigVariables
Sets configuration variables for WASI Config.Allocates native memory for the key-value string arrays, calls the native function, and releases memory when done.
- Parameters:
linkerPtr- pointer to the component linkervariables- the configuration variables as key-value pairs- Returns:
- 0 on success, non-zero on error
-
componentLinkerGetInterfaces
Gets all defined interfaces from the native linker as a JSON array string.- Parameters:
linkerPtr- pointer to the component linkerjsonOut- pointer to receive the JSON string (must be freed with componentFreeString)- Returns:
- 0 on success, non-zero on error
-
componentLinkerGetFunctions
public int componentLinkerGetFunctions(MemorySegment linkerPtr, MemorySegment namespace, MemorySegment interfaceName, MemorySegment jsonOut) Gets all defined functions for a specific interface as a JSON array string.- Parameters:
linkerPtr- pointer to the component linkernamespace- pointer to the interface namespace C stringinterfaceName- pointer to the interface name C stringjsonOut- pointer to receive the JSON string (must be freed with componentFreeString)- Returns:
- 0 on success, non-zero on error
-
componentLinkerHostFunctionCount
Gets the number of host functions defined in the linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- the host function count
-
componentLinkerInterfaceCount
Gets the number of interfaces defined in the linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- the interface count
-
componentLinkerWasiP2Enabled
Checks if WASI Preview 2 is enabled in the linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 1 if enabled, 0 if not, FFI_ERROR on error
-
componentLinkerWasiHttpEnabled
Checks if WASI HTTP is enabled in the linker.- Parameters:
linkerPtr- pointer to the component linker- Returns:
- 1 if enabled, 0 if not, FFI_ERROR on error
-
componentLinkerSetAsyncSupport
Sets async support on the linker.- Parameters:
linkerPtr- pointer to the component linkerenabled- 1 to enable, 0 to disable- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiMaxRandomSize
Sets the maximum random buffer size for WASI random operations.- Parameters:
linkerPtr- pointer to the component linkermaxSize- the maximum size in bytes- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiArgs
Sets WASI Preview 2 arguments for the component linker.- Parameters:
linkerPtr- pointer to the component linkerargsJsonPtr- pointer to JSON array of argument strings- Returns:
- 0 on success, non-zero on error
-
componentLinkerAddWasiEnv
public int componentLinkerAddWasiEnv(MemorySegment linkerPtr, MemorySegment keyPtr, MemorySegment valuePtr) Adds a WASI Preview 2 environment variable to the component linker.- Parameters:
linkerPtr- pointer to the component linkerkeyPtr- pointer to environment variable key stringvaluePtr- pointer to environment variable value string- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritEnv
Sets whether to inherit environment from host in WASI Preview 2.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritArgs
Sets whether to inherit arguments from host in WASI Preview 2.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritStdio
Sets whether to inherit stdio from host in WASI Preview 2.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerAddWasiPreopenDir
public int componentLinkerAddWasiPreopenDir(MemorySegment linkerPtr, MemorySegment hostPathPtr, MemorySegment guestPathPtr, int dirPermsBits, int filePermsBits) Adds a preopened directory for WASI Preview 2 with granular permissions.- Parameters:
linkerPtr- pointer to the component linkerhostPathPtr- pointer to host path stringguestPathPtr- pointer to guest path stringdirPermsBits- directory permission bits (DirPerms)filePermsBits- file permission bits (FilePerms)- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiAllowNetwork
Sets whether network access is allowed in WASI Preview 2.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritStdin
Sets whether to inherit stdin individually.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritStdout
Sets whether to inherit stdout individually.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInheritStderr
Sets whether to inherit stderr individually.- Parameters:
linkerPtr- pointer to the component linkerinherit- 1 to inherit, 0 to not inherit- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiStdinBytes
public int componentLinkerSetWasiStdinBytes(MemorySegment linkerPtr, MemorySegment data, long dataLen) Sets stdin bytes for the WASI context.- Parameters:
linkerPtr- pointer to the component linkerdata- pointer to the byte datadataLen- length of the byte data- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiAllowTcp
Sets whether TCP sockets are allowed.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiAllowUdp
Sets whether UDP sockets are allowed.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiAllowIpNameLookup
Sets whether IP name lookup (DNS) is allowed.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiAllowBlockingCurrentThread
Sets whether blocking the current thread is allowed.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInsecureRandomSeed
Sets the insecure random seed.- Parameters:
linkerPtr- pointer to the component linkerseed- the seed value- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiWallClock
public int componentLinkerSetWasiWallClock(MemorySegment linkerPtr, MemorySegment nowFn, MemorySegment resolutionFn, long callbackId) Sets a custom wall clock callback.- Parameters:
linkerPtr- pointer to the component linkernowFn- function pointer for now() callbackresolutionFn- function pointer for resolution() callbackcallbackId- identifier for the Java-side clock- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiMonotonicClock
public int componentLinkerSetWasiMonotonicClock(MemorySegment linkerPtr, MemorySegment nowFn, MemorySegment resolutionFn, long callbackId) Sets a custom monotonic clock callback.- Parameters:
linkerPtr- pointer to the component linkernowFn- function pointer for now() callbackresolutionFn- function pointer for resolution() callbackcallbackId- identifier for the Java-side clock- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiSecureRandom
public int componentLinkerSetWasiSecureRandom(MemorySegment linkerPtr, MemorySegment fillBytesFn, long callbackId) Sets a custom secure random callback.- Parameters:
linkerPtr- pointer to the component linkerfillBytesFn- function pointer for fillBytes() callbackcallbackId- identifier for the Java-side random source- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiInsecureRandom
public int componentLinkerSetWasiInsecureRandom(MemorySegment linkerPtr, MemorySegment fillBytesFn, long callbackId) Sets a custom insecure random callback.- Parameters:
linkerPtr- pointer to the component linkerfillBytesFn- function pointer for fillBytes() callbackcallbackId- identifier for the Java-side random source- Returns:
- 0 on success, non-zero on error
-
componentLinkerSetWasiSocketAddrCheck
public int componentLinkerSetWasiSocketAddrCheck(MemorySegment linkerPtr, MemorySegment checkFn, long callbackId) Sets a socket address check callback.- Parameters:
linkerPtr- pointer to the component linkercheckFn- function pointer for check() callbackcallbackId- identifier for the Java-side check- Returns:
- 0 on success, non-zero on error
-
componentLinkerInstantiate
public int componentLinkerInstantiate(MemorySegment linkerPtr, MemorySegment componentPtr, MemorySegment instanceOutPtr) Instantiates a component using the component linker.- Parameters:
linkerPtr- pointer to the component linkercomponentPtr- pointer to the componentinstanceOutPtr- pointer to store the instance pointer- Returns:
- 0 on success, non-zero on error
-
componentSerialize
public int componentSerialize(MemorySegment componentPtr, MemorySegment dataPtrOut, MemorySegment lenOut) Serializes a component to bytes.The caller must free the returned data using
componentFreeSerializedData(java.lang.foreign.MemorySegment, long).- Parameters:
componentPtr- the component pointerdataPtrOut- output pointer to receive the serialized data pointerlenOut- output pointer to receive the data length- Returns:
- 0 on success, non-zero on error
-
componentFreeSerializedData
Frees serialized component data previously returned bycomponentSerialize(java.lang.foreign.MemorySegment, java.lang.foreign.MemorySegment, java.lang.foreign.MemorySegment).- Parameters:
dataPtr- the data pointer to freelen- the length of the data
-
panamaComponentDeserialize
public int panamaComponentDeserialize(MemorySegment enginePtr, MemorySegment dataPtr, long len, MemorySegment componentPtrOut) Deserializes a component from bytes using the enhanced component engine.- Parameters:
enginePtr- pointer to the enhanced component enginedataPtr- pointer to the serialized datalen- length of the serialized datacomponentPtrOut- output pointer to receive the new component pointer- Returns:
- 0 on success, non-zero on error
-
panamaComponentDeserializeFile
public int panamaComponentDeserializeFile(MemorySegment enginePtr, MemorySegment pathPtr, long pathLen, MemorySegment componentPtrOut) Deserializes a component from a file using the enhanced component engine.- Parameters:
enginePtr- pointer to the enhanced component enginepathPtr- pointer to the file path bytes (UTF-8)pathLen- length of the file pathcomponentPtrOut- output pointer to receive the new component pointer- Returns:
- 0 on success, non-zero on error
-
panamaComponentResourcesRequired
public int panamaComponentResourcesRequired(MemorySegment componentPtr, MemorySegment numMemoriesOut, MemorySegment maxMemoryOut, MemorySegment numTablesOut, MemorySegment maxTableOut) Gets the resources required by a component.- Parameters:
componentPtr- pointer to the componentnumMemoriesOut- output pointer for number of memories (i32)maxMemoryOut- output pointer for max initial memory size (i64, -1 if unbounded)numTablesOut- output pointer for number of tables (i32)maxTableOut- output pointer for max initial table size (i64, -1 if unbounded)- Returns:
- 0 on success, non-zero on error. numMemories=-2 means resources_required() returned None
-
componentImageRange
public int componentImageRange(MemorySegment componentPtr, MemorySegment startPtr, MemorySegment endPtr) Gets the image range of a compiled component.- Parameters:
componentPtr- pointer to the componentstartPtr- output pointer for the start address (u64)endPtr- output pointer for the end address (u64)- Returns:
- 0 on success, negative error code on failure
-
componentInitializeCowImage
Pre-initializes a component's copy-on-write image for faster instantiation.- Parameters:
componentPtr- pointer to the component- Returns:
- 0 on success, negative error code on failure
-
componentLinkerInstantiatePre
public MemorySegment componentLinkerInstantiatePre(MemorySegment linkerPtr, MemorySegment componentPtr) Pre-instantiates a component using the linker.- Parameters:
linkerPtr- pointer to the component linkercomponentPtr- pointer to the component- Returns:
- pointer to the pre-instantiated handle, or null on failure
-
componentLinkerAllowShadowing
Allow or disallow shadowing of previously defined names.- Parameters:
linkerPtr- pointer to the component linkerallow- 1 to allow, 0 to disallow
-
componentLinkerDefineUnknownImportsAsTraps
public int componentLinkerDefineUnknownImportsAsTraps(MemorySegment linkerPtr, MemorySegment componentPtr) Define all unknown imports as traps.- Parameters:
linkerPtr- pointer to the component linkercomponentPtr- pointer to the component- Returns:
- 0 on success, -1 on error
-
componentLinkerDefineResource
public int componentLinkerDefineResource(MemorySegment linkerPtr, MemorySegment interfacePathPtr, long interfacePathLen, MemorySegment resourceNamePtr, long resourceNameLen, int resourceId, MemorySegment destructorFn, long destructorCallbackId) Defines a host resource type on the component linker.- Parameters:
linkerPtr- pointer to the component linkerinterfacePathPtr- UTF-8 encoded interface path (e.g., "wasi:io/streams")interfacePathLen- length of the interface pathresourceNamePtr- UTF-8 encoded resource nameresourceNameLen- length of the resource nameresourceId- unique resource IDdestructorFn- function pointer for the destructor callback (nullable)destructorCallbackId- callback ID passed to the destructor function- Returns:
- 0 on success, non-zero on error
-
componentLinkerDefineModule
public int componentLinkerDefineModule(MemorySegment linkerPtr, MemorySegment instancePathPtr, long instancePathLen, MemorySegment namePtr, long nameLen, MemorySegment modulePtr) Defines a core module on the component linker.- Parameters:
linkerPtr- pointer to the component linkerinstancePathPtr- UTF-8 encoded instance pathinstancePathLen- length of the instance pathnamePtr- UTF-8 encoded module namenameLen- length of the module namemodulePtr- pointer to the native module- Returns:
- 0 on success, non-zero on error
-
componentLinkerDefineHostFunction
public int componentLinkerDefineHostFunction(MemorySegment linkerPtr, MemorySegment witPathPtr, long witPathLen, MemorySegment callbackFn, long callbackId) Defines a host function on the component linker using a WIT path.- Parameters:
linkerPtr- pointer to the component linkerwitPathPtr- UTF-8 encoded WIT path (e.g., "wasi:cli/stdout#print")witPathLen- length of the WIT pathcallbackFn- function pointer for the host function callbackcallbackId- callback ID passed to the function pointer- Returns:
- 0 on success, non-zero on error
-
componentLinkerDefineHostFunctionAsync
public int componentLinkerDefineHostFunctionAsync(MemorySegment linkerPtr, MemorySegment witPathPtr, long witPathLen, MemorySegment callbackFn, long callbackId) Defines an async host function on the component linker using a WIT path.- Parameters:
linkerPtr- pointer to the component linkerwitPathPtr- UTF-8 encoded WIT path (e.g., "wasi:cli/stdout#print")witPathLen- length of the WIT pathcallbackFn- function pointer for the host function callbackcallbackId- callback ID passed to the function pointer- Returns:
- 0 on success, non-zero on error
-
componentHostCallbackAllocResult
Allocates a result buffer for host function callback results.- Parameters:
len- length of the buffer to allocate- Returns:
- pointer to the allocated buffer
-
componentInstancePreInstantiate
Instantiates from a pre-instantiated component.- Parameters:
prePtr- pointer to the pre-instantiated handleinstanceOutPtr- pointer to store the instance pointer- Returns:
- 0 on success, non-zero on error
-
componentInstancePreInstantiateWithConfig
public int componentInstancePreInstantiateWithConfig(MemorySegment prePtr, long fuelLimit, long epochDeadline, long maxMemoryBytes, long maxTableElements, long maxInstances, long maxTables, long maxMemories, byte trapOnGrowFailure, MemorySegment instanceOutPtr) Instantiates from a pre-instantiated component with store configuration.- Parameters:
prePtr- pointer to the pre-instantiated handlefuelLimit- fuel limit for the store (0 for no limit)epochDeadline- epoch deadline for the store (0 for no deadline)maxMemoryBytes- maximum memory in bytes (0 for unlimited)maxTableElements- maximum elements per table (0 for unlimited)maxInstances- maximum wasm instances (0 for unlimited)maxTables- maximum tables (0 for unlimited)maxMemories- maximum memories (0 for unlimited)trapOnGrowFailure- whether to trap on grow failure (1) or return -1 (0)instanceOutPtr- pointer to store the instance pointer- Returns:
- 0 on success, non-zero on error
-
componentInstancePreIsValid
Checks if a pre-instantiated component handle is valid.- Parameters:
prePtr- pointer to the pre-instantiated handle- Returns:
- 1 if valid, 0 if not
-
componentInstancePreInstanceCount
Gets the instance count from a pre-instantiated component.- Parameters:
prePtr- pointer to the pre-instantiated handle- Returns:
- the number of instances created
-
componentInstancePrePreparationTimeNs
Gets the preparation time in nanoseconds from a pre-instantiated component.- Parameters:
prePtr- pointer to the pre-instantiated handle- Returns:
- preparation time in nanoseconds
-
componentInstancePreAvgInstantiationTimeNs
Gets the average instantiation time in nanoseconds from a pre-instantiated component.- Parameters:
prePtr- pointer to the pre-instantiated handle- Returns:
- average instantiation time in nanoseconds
-
componentInstancePreDestroy
Destroys a pre-instantiated component handle.- Parameters:
prePtr- pointer to the pre-instantiated handle to destroy
-
componentGetExportIndex
public int componentGetExportIndex(MemorySegment componentPtr, MemorySegment instanceIndexPtr, MemorySegment name, MemorySegment indexOut) Looks up a component export index by name.- Parameters:
componentPtr- pointer to the componentinstanceIndexPtr- optional parent instance index (may be NULL)name- C string with the export nameindexOut- output pointer for the export index handle- Returns:
- 0 if found, 1 if not found, -1 on error
-
componentExportIndexDestroy
Destroys a component export index handle.- Parameters:
indexPtr- pointer to the export index to destroy
-
enhancedComponentInstanceHasFuncByIndex
public int enhancedComponentInstanceHasFuncByIndex(MemorySegment enginePtr, long instanceId, MemorySegment indexPtr) Checks if a component instance has a function at the given export index.- Parameters:
enginePtr- pointer to the enhanced component engineinstanceId- the component instance IDindexPtr- pointer to the export index- Returns:
- 1 if found, 0 if not found, -1 on error
-
enhancedComponentInstanceGetExport
public int enhancedComponentInstanceGetExport(MemorySegment enginePtr, long instanceId, MemorySegment parentIndexPtr, MemorySegment namePtr, long nameLen, MemorySegment outIndexPtr) Looks up a general export by name on a component instance.Returns the export kind code (0-6) on success, -1 if not found, -2 on error. On success, writes the boxed ComponentExportIndex pointer to outIndexPtr.
- Parameters:
enginePtr- pointer to the enhanced component engineinstanceId- the component instance IDparentIndexPtr- pointer to parent export index (NULL for root)namePtr- pointer to the export name bytesnameLen- length of the export nameoutIndexPtr- pointer to output export index pointer (caller-allocated)- Returns:
- kind code (0-6), -1 if not found, -2 on error
-
enhancedComponentRunConcurrent
public int enhancedComponentRunConcurrent(MemorySegment enginePtr, long instanceId, MemorySegment jsonPtr, long jsonLen, MemorySegment resultPtr, MemorySegment resultLen) Executes concurrent component function calls via the enhanced component engine.- Parameters:
enginePtr- the enhanced engine pointerinstanceId- the component instance IDjsonPtr- pointer to the JSON input bytesjsonLen- length of the JSON input bytesresultPtr- pointer to output result pointer (caller-allocated)resultLen- pointer to output result length (caller-allocated)- Returns:
- 0 on success, -1 on error
-
freeConcurrentResult
Frees a result buffer allocated by the concurrent call function.- Parameters:
ptr- the pointer to the result bufferlen- the length of the result buffer
-
asyncValClose
public int asyncValClose(long handle) Closes an async val handle (Future/Stream/ErrorContext) in the native AsyncValRegistry.This removes the handle from the global registry, dropping the stored Val. Safe to call with handles that have already been consumed or closed (no-op).
- Parameters:
handle- the async val handle to close- Returns:
- 0 on success (handle found and removed), -1 if handle was not found
-
createAsyncValCloseAction
Creates aRunnableclose action that invokesasyncValClose(long)for the given handle. Suitable for use withStreamAny.create(long, Runnable),FutureAny.create(long, Runnable), andErrorContext.create(long, Runnable).- Parameters:
handle- the async val handle- Returns:
- a Runnable that will close the handle when invoked
-
resourceAnyDrop
Drops a ResourceAny held in the global resource registry.Takes the resource from the registry and calls resource_drop on it using the store associated with the given component instance.
- Parameters:
enginePtr- the enhanced component engine pointerinstanceId- the component instance ID that owns the storeresourceHandle- the resource handle ID from the global registry- Returns:
- 0 on success, non-zero on error
-
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]
-