Expand description
Java (Panama FFM) trait bridge code generation for plugin systems.
This module generates Java code that wraps C FFI vtables for plugin registration. Since Java cannot expose method references as raw C function pointers, we use Java 21+ Foreign Function & Memory API (Panama) upcall stubs to bridge Java implementations into the C vtable structure.
For each [[trait_bridges]] entry, this module generates:
- A
public interface {TraitName} { ... }with methods matching the trait’s methods plus Plugin lifecycle methods (name, version, initialize, shutdown). - A
{TraitName}Bridgeclass that:- Allocates Panama FFM upcall stubs for each trait method
- Builds the C vtable as a MemorySegment
- Manages memory lifecycle with AutoCloseable
- Registration helper:
public static void register{TraitName}({TraitName} impl)that builds the vtable and calls the C registration function. - Unregistration helper:
public static void unregister{TraitName}(String name).
Functions§
- gen_
trait_ bridge - Generate all trait bridge code for a single
[[trait_bridges]]entry. Returns Java source code as a String.