Class PanamaStore

java.lang.Object
ai.tegmentum.wasmtime4j.panama.PanamaStore
All Implemented Interfaces:
ai.tegmentum.wasmtime4j.Store, Closeable, AutoCloseable

public final class PanamaStore extends Object implements ai.tegmentum.wasmtime4j.Store
Panama FFI implementation of WebAssembly Store.

A Store represents an execution context for WebAssembly instances.

Since:
1.0.0
  • Constructor Details

    • PanamaStore

      public PanamaStore(PanamaEngine engine) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Creates a new Panama store.
      Parameters:
      engine - the engine that owns this store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException - if store creation fails
    • PanamaStore

      public PanamaStore(PanamaEngine engine, ai.tegmentum.wasmtime4j.config.StoreLimits limits) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Creates a new Panama store with resource limits.
      Parameters:
      engine - the engine that owns this store
      limits - the resource limits to apply
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException - if store creation fails
  • Method Details

    • forModule

      public static PanamaStore forModule(ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Creates a new store that is compatible with the given module.

      CRITICAL: This method creates a Store that shares the exact same Engine Arc as the module. This is required because Wasmtime's Instance::new() uses Arc::ptr_eq() to verify that the Store and Module were created from the same Engine. Using PanamaEngine.createStore() will create a Store with a different Arc clone, causing "cross-Engine instantiation is not currently supported" errors.

      Usage Example:

      
       try (PanamaEngine engine = new PanamaEngine()) {
         PanamaModule module = (PanamaModule) engine.compileModule(wasmBytes);
      
         // CORRECT: Use forModule to create a compatible store
         try (PanamaStore store = PanamaStore.forModule(module)) {
           PanamaInstance instance = (PanamaInstance) module.instantiate(store);
           // Instance created successfully
         }
       }
       
      Parameters:
      module - the module to create a compatible store for
      Returns:
      a new store that shares the same Engine Arc as the module
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException - if store creation fails
      IllegalArgumentException - if module is null or not a PanamaModule
    • getEngine

      public ai.tegmentum.wasmtime4j.Engine getEngine()
      Specified by:
      getEngine in interface ai.tegmentum.wasmtime4j.Store
    • getData

      public Object getData()
      Specified by:
      getData in interface ai.tegmentum.wasmtime4j.Store
    • setData

      public void setData(Object data)
      Specified by:
      setData in interface ai.tegmentum.wasmtime4j.Store
    • setResourceLimiter

      public void setResourceLimiter(ai.tegmentum.wasmtime4j.config.ResourceLimiter limiter) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setResourceLimiter in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setResourceLimiterAsync

      public void setResourceLimiterAsync(ai.tegmentum.wasmtime4j.config.ResourceLimiterAsync limiter) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setResourceLimiterAsync in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setFuel

      public void setFuel(long fuel) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getFuel

      public long getFuel() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      getFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • addFuel

      public void addFuel(long fuel) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      addFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setEpochDeadline

      public void setEpochDeadline(long ticks) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setEpochDeadline in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • consumeFuel

      public long consumeFuel(long fuel) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      consumeFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • hostcallFuel

      public long hostcallFuel() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      hostcallFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setHostcallFuel

      public void setHostcallFuel(long fuel) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setHostcallFuel in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createHostFunction

      public ai.tegmentum.wasmtime4j.WasmFunction createHostFunction(String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createHostFunction in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createHostFunctionUnchecked

      public ai.tegmentum.wasmtime4j.WasmFunction createHostFunctionUnchecked(String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createHostFunctionUnchecked in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getWasiContext

      public Optional<ai.tegmentum.wasmtime4j.wasi.WasiContext> getWasiContext()
      Specified by:
      getWasiContext in interface ai.tegmentum.wasmtime4j.Store
    • reapplyWasiContext

      public void reapplyWasiContext() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      reapplyWasiContext in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createGlobal

      public ai.tegmentum.wasmtime4j.WasmGlobal createGlobal(ai.tegmentum.wasmtime4j.WasmValueType valueType, boolean isMutable, ai.tegmentum.wasmtime4j.WasmValue initialValue) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createGlobal in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createTable

      public ai.tegmentum.wasmtime4j.WasmTable createTable(ai.tegmentum.wasmtime4j.WasmValueType elementType, int initialSize, int maxSize) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createTable in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createTable

      public ai.tegmentum.wasmtime4j.WasmTable createTable(ai.tegmentum.wasmtime4j.WasmValueType elementType, int initialSize, int maxSize, ai.tegmentum.wasmtime4j.WasmValue initValue) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createTable in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createTable

      public ai.tegmentum.wasmtime4j.WasmTable createTable(ai.tegmentum.wasmtime4j.type.TableType tableType) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createTable in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createTable

      public ai.tegmentum.wasmtime4j.WasmTable createTable(ai.tegmentum.wasmtime4j.type.TableType tableType, ai.tegmentum.wasmtime4j.WasmValue initValue) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createTable in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createMemory

      public ai.tegmentum.wasmtime4j.WasmMemory createMemory(int initialPages, int maxPages) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createMemory in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createMemory

      public ai.tegmentum.wasmtime4j.WasmMemory createMemory(ai.tegmentum.wasmtime4j.type.MemoryType memoryType) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createMemory in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createSharedMemory

      public ai.tegmentum.wasmtime4j.WasmMemory createSharedMemory(int initialPages, int maxPages) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createSharedMemory in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createFunctionReference

      public ai.tegmentum.wasmtime4j.func.FunctionReference createFunctionReference(ai.tegmentum.wasmtime4j.func.HostFunction implementation, ai.tegmentum.wasmtime4j.type.FunctionType functionType) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createFunctionReference in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createFunctionReference

      public ai.tegmentum.wasmtime4j.func.FunctionReference createFunctionReference(ai.tegmentum.wasmtime4j.WasmFunction function) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createFunctionReference in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getCallbackRegistry

      public ai.tegmentum.wasmtime4j.func.CallbackRegistry getCallbackRegistry()
      Specified by:
      getCallbackRegistry in interface ai.tegmentum.wasmtime4j.Store
    • createInstance

      public ai.tegmentum.wasmtime4j.Instance createInstance(ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createInstance in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • createInstance

      public ai.tegmentum.wasmtime4j.Instance createInstance(ai.tegmentum.wasmtime4j.Module module, ai.tegmentum.wasmtime4j.Extern[] imports) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      createInstance in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface ai.tegmentum.wasmtime4j.Store
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ai.tegmentum.wasmtime4j.Store
    • getNativeStore

      public MemorySegment getNativeStore()
      Gets the native store pointer.
      Returns:
      native store memory segment
    • getResourceManager

      public ArenaResourceManager getResourceManager()
      Gets the resource manager for this store.
      Returns:
      the arena resource manager
    • gc

      public void gc() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      gc in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • throwException

      @Deprecated public <R> R throwException(ai.tegmentum.wasmtime4j.ExnRef exceptionRef) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Deprecated.
      Specified by:
      throwException in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • takePendingException

      public ai.tegmentum.wasmtime4j.ExnRef takePendingException() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      takePendingException in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • hasPendingException

      public boolean hasPendingException()
      Specified by:
      hasPendingException in interface ai.tegmentum.wasmtime4j.Store
    • epochDeadlineAsyncYieldAndUpdate

      public void epochDeadlineAsyncYieldAndUpdate(long deltaTicks) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      epochDeadlineAsyncYieldAndUpdate in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • epochDeadlineTrap

      public void epochDeadlineTrap() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      epochDeadlineTrap in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • epochDeadlineCallback

      public void epochDeadlineCallback(ai.tegmentum.wasmtime4j.Store.EpochDeadlineCallback callback) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      epochDeadlineCallback in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setDebugHandler

      public void setDebugHandler(ai.tegmentum.wasmtime4j.debug.DebugHandler handler)
      Specified by:
      setDebugHandler in interface ai.tegmentum.wasmtime4j.Store
    • clearDebugHandler

      public void clearDebugHandler()
      Specified by:
      clearDebugHandler in interface ai.tegmentum.wasmtime4j.Store
    • setCallHook

      public void setCallHook(ai.tegmentum.wasmtime4j.func.CallHookHandler handler) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setCallHook in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setCallHookAsync

      public void setCallHookAsync(ai.tegmentum.wasmtime4j.Store.AsyncCallHookHandler handler) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setCallHookAsync in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • setFuelAsyncYieldInterval

      public void setFuelAsyncYieldInterval(long interval) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      setFuelAsyncYieldInterval in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getFuelAsyncYieldInterval

      public long getFuelAsyncYieldInterval()
      Specified by:
      getFuelAsyncYieldInterval in interface ai.tegmentum.wasmtime4j.Store
    • captureBacktrace

      public ai.tegmentum.wasmtime4j.debug.WasmBacktrace captureBacktrace() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      captureBacktrace in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • forceCaptureBacktrace

      public ai.tegmentum.wasmtime4j.debug.WasmBacktrace forceCaptureBacktrace() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      forceCaptureBacktrace in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • debugInstanceCount

      public int debugInstanceCount() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      debugInstanceCount in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • debugModuleCount

      public int debugModuleCount() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      debugModuleCount in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • isSingleStep

      public boolean isSingleStep()
      Specified by:
      isSingleStep in interface ai.tegmentum.wasmtime4j.Store
    • debugExitFrames

      public List<ai.tegmentum.wasmtime4j.debug.FrameHandle> debugExitFrames() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      debugExitFrames in interface ai.tegmentum.wasmtime4j.Store
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • isAsync

      public boolean isAsync()
      Specified by:
      isAsync in interface ai.tegmentum.wasmtime4j.Store
    • breakpoints

      public Optional<List<ai.tegmentum.wasmtime4j.debug.Breakpoint>> breakpoints()
      Specified by:
      breakpoints in interface ai.tegmentum.wasmtime4j.Store
    • editBreakpoints

      public Optional<ai.tegmentum.wasmtime4j.debug.BreakpointEditor> editBreakpoints()
      Specified by:
      editBreakpoints in interface ai.tegmentum.wasmtime4j.Store
    • gcAsync

      public CompletableFuture<Void> gcAsync()
      Specified by:
      gcAsync in interface ai.tegmentum.wasmtime4j.Store
    • createInstanceAsync

      public CompletableFuture<ai.tegmentum.wasmtime4j.Instance> createInstanceAsync(ai.tegmentum.wasmtime4j.Module module)
      Specified by:
      createInstanceAsync in interface ai.tegmentum.wasmtime4j.Store
    • createMemoryAsync

      public CompletableFuture<ai.tegmentum.wasmtime4j.WasmMemory> createMemoryAsync(ai.tegmentum.wasmtime4j.type.MemoryType memoryType)
      Specified by:
      createMemoryAsync in interface ai.tegmentum.wasmtime4j.Store
    • createTableAsync

      public CompletableFuture<ai.tegmentum.wasmtime4j.WasmTable> createTableAsync(ai.tegmentum.wasmtime4j.type.TableType tableType)
      Specified by:
      createTableAsync in interface ai.tegmentum.wasmtime4j.Store