Skip to main content

Module trait_bridge

Module trait_bridge 

Source
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:

  1. A public interface {TraitName} { ... } with methods matching the trait’s methods plus Plugin lifecycle methods (name, version, initialize, shutdown).
  2. A {TraitName}Bridge class that:
    • Allocates Panama FFM upcall stubs for each trait method
    • Builds the C vtable as a MemorySegment
    • Manages memory lifecycle with AutoCloseable
  3. Registration helper: public static void register{TraitName}({TraitName} impl) that builds the vtable and calls the C registration function.
  4. 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.