$ show java-native-access/jna
JNA (Java Native Access) is a Java library for calling native shared libraries without writing JNI glue code. Instead of manually implementing native methods, developers declare `Library` interfaces or use `Native.register` direct mapping; the runtime proxies those calls through `NativeLibrary`, resolves symbols, and dispatches through a native JNI bridge backed by a vendored libffi copy. The core also supplies memory management (`Pointer`, `Memory`, `Structure`, `Union`), callbacks via native trampolines, string/array marshalling, custom type converters, and Windows stdcall/UNICODE mapping utilities.
The LLM identified 4 files worth highlighting for reuse:
A finalizer-free native resource cleaner built on PhantomReference, ReferenceQueue, a daemon thread, and a doubly-linked list of cleanup actions. It is self-contained, extractable, and demonstrates a robust pattern for deallocating native memory when Java objects become unreachable.
Pure-Java parser that inspects ELF headers to determine architecture, endianness, and hard/soft-float ABI settings. It is useful for build-time native library selection and shows a clean, dependency-free binary-format inspection pattern.
Small, focused helper that keeps a backing native Memory object alive as long as a derived ByteBuffer is still referenced, preventing premature deallocation of NIO buffers. The pattern is directly transferable to any JNI/NIO bridge.
Abstract base class for modeling C integer typedefs as type-safe Java Number subclasses with configurable size, unsigned behavior, and null-safe comparisons. It demonstrates a reusable pattern for wrapping native integer types and enum flags without losing type identity.