ffmbindings manual bindings to C++

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Mar 4 12:19:44 UTC 2025


Hi Lain, this is some interesting work. When looking at the 
documentation, and at the examples provided, it is not clear to me how 
some features of C++ are supported. E.g. it seems to me that the 
bindings you create (esp. downcall handles) are completely static. That 
is, if you have B extends A, and both A and B define a virtual method, 
you will add a downcall handle in both classes, one for A

and the other for B

. Then you kind of rely on /Java's/ (not C++'s !!) dynamic dispatch to 
make things work -- e.g. when you call A

on an instance of B, the JVM will call B

-- which will result in the correct C++ method being invoked. While this 
works for simple examples -- I'm a bit skeptical about the generality of 
this approach. Of course, as long as there's no multiple inheritance, 
and as long as all the C++ classes are created from the Java side of the 
fence, this might even work correctly.

But if some C++ method returns some A* -- what Java wrapper will we 
create? The problem here is that the choice of the wrapper (A vs. B) 
determines which set of methods will be invoked on that instance 
(because we're effectively bypassing C++'s virtual dispatch).

All things considered, this approach doesn't seem very different from 
the jextract PoC I shared -- in the sense that it models some C++ 
features /to some degree/ without really providing full language interop 
support which, IMHO, is not possible w/o having a C++ compiler on your 
side (inline functions are another issue). But maybe, what you are 
trying to say is that, even with a simple PoC like the one I provided, 
it's possible to provide meaningful interop for at least /some/ C++ 
libraries (like eigen) ?

Cheers Maurizio

On 26/02/2025 02:13, Lain Lain wrote:

> Hi,
> We would like to present you ffmbindings project which helps to do 
> manual bindings to C++ libraries from Java using FFM.
> Currently it contains bindings to eigen C++ library but we are going 
> to publish few more this month.
> Source code: https://bitbucket.org/ffmbindings
> Documentation: https://ffmbindings.onrender.com
> Any feedback are welcome.
> Thank you,
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jextract-dev/attachments/20250304/9d5e10b8/attachment-0001.htm>


More information about the jextract-dev mailing list