What does HackerNews think of jextract?

https://openjdk.org/projects/code-tools

Language: Java

Yes it's possible. The same project developed a tool called jextract that uses clang to convert C headers to Java Panama classes:

https://github.com/openjdk/jextract

This is one level below P/Invoke. It just offers a linking runtime API.

There's also a tool that can generate all the bindings from a C header file automatically: https://github.com/openjdk/jextract

Then it doesn't really matter whether annotations are used or not, or some more low-level linker API (like FFM went with). As a user you just call into the generated bindings.

That's the philosophy: the JDK provides the low-level capabilities, and jextract provides the 'civilization', i.e. a usability focused layer on top. One of the advantages is that the JDK doesn't compete with other existing solutions, and those existing solutions can benefit from the new linking runtime APIs as well.

This is the runtime API, that uses the JITs to generate the trampoline codes necessary to go from the Java calling convention to the C calling convention (upcall and downcall), a kind of like libffi for Java.

If you have a typed langages like Scala, Kotlin, Java, you can use jextract [1] which is a more high level API. jextract uses clang to parse C headers files and generates a jar file with all the C function seen as Java methods with all the glue generated for you (the downside is i believe that this jar is OS specific).

This API is more for dynamic languages like Clojure, Groovy, JRuby, where you want to do dynamic runtime calls and still get performance (as far as i understand, the JIT generates the adapter code once per call and you can reuse it).

[1] https://github.com/openjdk/jextract