Class GcProxyFactory
java.lang.Object
ai.tegmentum.webassembly4j.runtime.gc.GcProxyFactory
Creates Java interface proxies that marshal method arguments and return values
through WebAssembly GC struct types instead of linear memory.
This is the GC counterpart to
ProxyFactory.
Where ProxyFactory marshals complex types through linear memory using the
Canonical ABI (ptr+len pairs), GcProxyFactory marshals GcMapped-annotated
types as GC struct references on the Wasm managed heap.
The runtime's GC manages the object lifetime — no manual allocation or freeing is needed.
Supported method parameter/return types:
- Primitive numerics:
int,long,float,double - Boolean:
boolean voidreturnsGcMapped-annotated classes and records — automatically marshalled to/from GC struct instances
Example:
@GcMapped
record Point(double x, double y) {}
interface Geometry extends AutoCloseable {
@WasmExport("rotate_point")
Point rotate(Point p, double angle);
}
GcExtension gc = instance.extension(GcExtension.class).orElseThrow();
Geometry geom = GcProxyFactory.create(Geometry.class, engine, module, instance, gc);
Point rotated = geom.rotate(new Point(1, 0), Math.PI / 2);
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tcreate(Class<T> iface, ai.tegmentum.webassembly4j.api.Engine engine, ai.tegmentum.webassembly4j.api.Module module, ai.tegmentum.webassembly4j.api.Instance instance, ai.tegmentum.webassembly4j.api.gc.GcExtension gc) Creates a proxy binding for the given interface using GC-based marshalling.
-
Method Details
-
create
public static <T> T create(Class<T> iface, ai.tegmentum.webassembly4j.api.Engine engine, ai.tegmentum.webassembly4j.api.Module module, ai.tegmentum.webassembly4j.api.Instance instance, ai.tegmentum.webassembly4j.api.gc.GcExtension gc) Creates a proxy binding for the given interface using GC-based marshalling.- Type Parameters:
T- the interface type- Parameters:
iface- the interface to bindengine- the engine (for lifecycle management)module- the compiled moduleinstance- the instantiated modulegc- the GC extension from the instance- Returns:
- a proxy implementing the interface
-