Class NativeLibraryLoader

java.lang.Object
ai.tegmentum.wasmtime4j.panama.NativeLibraryLoader

public final class NativeLibraryLoader extends Object
Native library loader for Panama FFI implementation.

This class handles native library loading and function discovery for the wasmtime4j-panama module. It uses the shared NativeLibraryUtils for platform detection and library loading, while providing Panama-specific functionality for function symbol lookup and resource management using Arena-based cleanup.

  • Method Details

    • getInstance

      public static NativeLibraryLoader getInstance()
      Gets the singleton instance of the native library loader.
      Returns:
      the singleton instance
      Throws:
      IllegalStateException - if library loading failed
    • isLoaded

      public boolean isLoaded()
      Checks if the native library is loaded and available.
      Returns:
      true if loaded successfully, false otherwise
    • getLoadingError

      public Optional<String> getLoadingError()
      Gets the loading error if library loading failed.
      Returns:
      the loading error, or null if no error occurred
    • getLoadInfo

      public ai.tegmentum.wasmtime4j.nativeloader.NativeLibraryUtils.LibraryLoadInfo getLoadInfo()
      Gets information about the library loading attempt.
      Returns:
      the load info
    • lookupFunction

      public Optional<MethodHandle> lookupFunction(String functionName, FunctionDescriptor descriptor)
      Looks up a function symbol and returns a MethodHandle.
      Parameters:
      functionName - the name of the function to look up
      descriptor - the function descriptor defining signature
      Returns:
      optional containing the MethodHandle, or empty if not found
    • getSymbolLookup

      public SymbolLookup getSymbolLookup()
      Gets the SymbolLookup for the loaded native library.
      Returns:
      the symbol lookup
      Throws:
      IllegalStateException - if the library is not loaded
    • getLibraryArena

      public Arena getLibraryArena()
      Gets the Arena used for library resource management.
      Returns:
      the library arena
    • clearMethodHandleCache

      public void clearMethodHandleCache()
      Clears the method handle cache.
    • close

      public void close()
      Closes the library and cleans up resources. This should only be called during JVM shutdown.
    • getDiagnosticInfo

      public String getDiagnosticInfo()
      Gets diagnostic information about the Panama library loader.
      Returns:
      diagnostic information string