This backend consumes the shared binding model and generates a Java API and JNI C++ glue. It has no Radient dependency. The standalone conformance project uses the shared native fixtures, declared with the real Diligent API macros. Its tests/API.json selects supported APIs from that common reference. Java assertions stay in tests/; runtime-name collision and native exception fixtures stay in tests/fixtures/.
Generated sources are build artifacts. generate.py accepts --model, --module, --package, --library, one or more --header arguments, and --output. --adapters optionally loads the shared adapter configuration. --surface writes the effective native binding contract for the shared api_surface.py checker. Each backend keeps its own explicitly reviewed baseline.
Java exposes Uint8 as short, Uint16 as int, and Uint32 as long, with checked ranges. Uint64 uses the complete bit pattern of a long; callers can use Java's unsigned-long utilities. Arrays follow their element type's mapping. JNI copies array data and validates the supplied count before invoking native code. Nullable arrays preserve null separately from non-null empty arrays in both directions. Required input arrays accept Java null only with count zero and provide non-null empty native storage in that case. Native array results are independent Java snapshots.
Raw byte inputs are copied into temporary native storage. Borrowed results and filled output buffers become independent Java arrays. Nullability and required empty-buffer normalization follow the array rules above. Descriptor byte fields must point to const data; writable inputs require a copyback adapter. Acquire/release access uses the scoped adapter described below; direct native-memory views are not exposed.
Input pointers and references must borrow storage for the duration of the call, including pointers inside nested descriptors. Retained inputs and ownership transfers require adapters and currently fail generation. Owned raw pointer results (including descriptor pointers) also require a release adapter; copying such a result into Java would otherwise leak its native allocation.
Array results with length_method obtain their element count from a no-argument method on the same interface or its base. Output parameters with length_from obtain their count from a retained interface argument's const no-argument method, optionally through an unsigned field of its returned descriptor. Both forms use unsigned 32-bit or 64-bit counts, checked against Java's array-length limit before allocation or copying. No extra Java count argument is needed.
Descriptor pointer fields can instead use the shared field_count_functions adapter. The native helper receives the containing descriptor and returns an unsigned element count (a byte count for void* fields). On input, ordinary fields are converted first, then the helper is called once per computed field before its array is copied. On output, the helper reads the returned native descriptor. The usual count checks, nullability, input lifetimes, and snapshot cleanup still apply. Inherited fields retain their base descriptor's adapter. Helpers must compute sizes from metadata already available at that point, without reading the input field's not-yet-populated array or depending on another computed field's conversion order.
Count queries, native calls, and result copying happen within one JNI call. All inputs are converted before querying an output capacity; that capacity is reused for result conversion even if the operation changes the source's subsequent count. Borrowed results query their count after the native call while the owner is retained. This protects lifetime, but callers must still obey the native API's synchronization contract so borrowed pointers and counts describe stable data.
Methods with output parameters return a generated result object. returnValue holds the native return value; the other fields retain the parameter names. Compatible interface overrides reuse the base method's result class and field names, including when the override renames native output parameters. Status values, including failures and pending results, are returned unchanged. An unwritten output starts with native value initialization. Native exceptions are contained at the JNI boundary and reported as Java exceptions.
Interface wrappers implement AutoCloseable; use try-with-resources or close() for deterministic release. Closing twice is harmless, and using a closed wrapper throws IllegalStateException. Borrowed results acquire their own reference. A Cleaner is a fallback for forgotten wrappers. JNI retains interface arguments for the duration of each call, including when another thread closes the wrapper. This protects lifetime; it does not change the native API's threading contract. Interface fields and array elements in returned snapshots each acquire their own reference, even when several refer to the same native object. Close each returned wrapper; the containing descriptor or array does not implement AutoCloseable. Input descriptor fields and array elements are retained for the full JNI call. If conversion fails partway through a snapshot, including nested descriptors and arrays, every reference acquired for that snapshot is released before returning.
object.QueryInterface(IMutable.class) uses the selected interface's native IID and returns a typed, independently owned wrapper, or null if unsupported. Close each successful query result, even when it refers to the original native object. Query targets must be generated interface classes with an IID; interfaces without an IID can still be used normally and serve as query sources. Inherited calls and derived-to-base arguments use native pointer conversions while retaining the original wrapper's ownership.
This first backend does not yet cover the entire JavaScript surface. Unsupported shapes fail generation: callbacks, multiple interface bases, mutable descriptor pointees, recursive descriptor graphs, inout parameters, and non-null native-address constant exports. Native default arguments may be present, but Java callers currently supply every input argument. Production Radient integration and its CPU tests are described in the Radient Java bindings. Packaging, Android integration, and rendering are later steps.
Pass --adapters with the shared scoped_bytes contract to bind acquire/release pairs. Acquisition returns the usual result object: returnValue is the native status and the pointer output becomes a ReadByteScope or WriteByteScope. Only the configured success status acquires access, including for empty spans; other statuses return a null scope. The release method is hidden on the owner.
Both scope types provide byteLength(), readByte(index), copyTo(byte[]), copyTo(byte[], sourceOffset), and toByteArray(). Reads return unsigned byte values from 0 to 255. Writable scopes additionally provide writeByte(index, value) and copyFrom(byte[], destinationOffset) (the offset may be omitted). Bulk copies preserve every bit. Bounds, null arrays, and use after closing are checked; no native pointer or unchecked buffer view is exposed. Whole-scope snapshots must fit in a Java array, while smaller copies can address larger native spans.
Scopes retain the native owner independently of its Java wrapper. close() calls the native release once. release() also returns its status; subsequent calls return that same status without repeating the release. A native failure status still consumes access. Failures during size validation or result construction roll back a successful acquisition. Byte operations synchronize with closing so an in-flight copy cannot lose its storage.
Use try-with-resources: scopes have no Cleaner fallback, since the native release may require the acquiring thread. Synchronization protects scope lifetime, not the native API's broader threading contract. The native API must keep the span valid and its size fixed until release and enforce any reader/writer exclusion itself.
Java-specific adapter configuration may extend the shared adapter file with function_adapters, mapping a selected free function to a qualified C++ function. The adapter receives the calling JNIEnv* followed by the original native arguments, and returns the original native result type. This supports platform context injection without exposing JVM pointers to Java. Supply its declaration through --header; method adapters are not supported. The API surface guard records these mappings.
Requirements: CMake 3.24+, a native C++17 compiler, JDK 11 or later, and the same Python/LLVM 22 environment used by the shared binding model. The JDK and compiler must target the same architecture. Set JAVA_HOME if Java is not discoverable.
The build extracts the fixture API, generates and compiles JNI, and compiles the Java tests. CTest only runs the prepared tests. Each Java suite prints individual case results and runs with -Xcheck:jni. Fixtures count live native objects and verify inputs independently, including ordinary UTF-8 byte sequences and exact unsigned values; tests also check failure cleanup and use after disposal. Concurrent-close tests use a native gate, with unconditional release during cleanup. CleanerTest runs in its own JVM and waits for observed destruction with a bounded deadline; it does not assume that a single GC request is enough. Large-descriptor tests use the default JVM stack, including simultaneous input and output storage. Large native values use heap storage while small descriptors remain inline. Subclass field-hiding tests verify that defaults and marshalling access the generated declaring class's fields, including concurrent first use. Field IDs are resolved once per descriptor and shared by input/output conversion; inherited descriptors reuse their base's IDs. The cache retains no Java objects or class references, so it does not keep a class loader alive.
Generator tests cover selection, determinism, native defaults, and rejection of unsupported shapes. Fixture sources and Java/Python test files are discovered by CMake; adding a suite does not require another source-list entry. No browser, renderer, Maven/Gradle dependency, or duplicate native Radient test suite is used.