Buoy - fast & clean native interop with Panama

As pretty much everyone here knows, interop between Java & native code has always been kind of a pain - if you’re lucky enough to have a good binding you’re in good shape, but if nobody has made a binding yet (or you have a binding but it’s poor quality) you’re stuck writing JNI code. With the JDK’s Project Panama out of incubation and available as a preview feature, the situation is a lot better - you don’t have to resort to JNI because you can create bindings purely in Java, but Panama is a low-level and quite verbose API. That’s where Buoy comes into the picture - it’s a very high-level, declarative library that allows you to define bindings in pure Java (optionally with nothing more than some annotations) with very little code. It also supports injecting native function handles, global and struct field accessors, and struct pointers into Java object fields (mapping).

Just like Panama itself, Buoy is in its early stages and will be undergoing further evolution before being ready for real-world use. However, if anyone’s interested in checking out the concept or kicking the tires a bit, it’s available at MyWorldLLC/Buoy: Simple and clean native binding library for Java (github.com). I’d appreciate any feedback!


I’ve ported Buoy from JDK 19 to JDK 20. JDK 21 will bring additional Panama API changes, though from what I’ve seen so far I think they’ll be significantly less intrusive (& therefore faster to port Buoy to) than the 19 → 20 change - the biggest two I see are Arena lifecycle management of memory segments (which should require only minimal, if any, changes on Buoy’s part) and an optional linker optimization for short-lived, non-upcalling native function stubs (new feature on Buoy’s part, should be quite simple to support). It seems that Panama’s public API is beginning to stabilize somewhat!


I navigated the source code of Buoy, very nice indeed, what is really missing is to separate the native module into an examples module with native and Java sources and good documentation.

1 Like

Very good point - I’ve not bothered yet with examples/docs because the API for Panama (& with it Buoy) isn’t yet stabilized so I’d likely be rewriting them both at least once. Once Panama is finalized I will definitely be providing both docs and examples.