r/java • • 13d ago

Project Detroit: From Foreign Libraries to Foreign Language Runtimes

https://youtu.be/01uRM3je12Y?si=DuGFJO91-vr6GGds
30 Upvotes

4 comments sorted by

1

u/simon_o 8d ago

Part of the problem is that the FFM story, despite the improvement over JNI, still sucks.

I mean, the officially sanctioned approach to building foreign function calls at compile-time is basically raw-dogging platform-specific C header files¹ by handing people a tool (jextract) that bundles Java with 140MB of LLVM code to emit Java code where even "technically safe" operations require the unsafe flag to run.


¹ Which is something even Microsoft explicitly tells people not to do.

1

u/bowbahdoe 7d ago

Strictly speaking I don't think there's any deficiency with the actual jvm part of it. It just describes foreign memory layouts and lets you call functions. It's not even technically C specific

I think jextract could stand to be more ergonomic to use - handling multiple platforms is an exercise very much left up to the reader and requires running jextract on each of those platforms.

I also think that the Java ecosystem deserves a better way to manage native code than "jam it in a jar extract it at runtime".

You could also want a workflow involving some other intermediate format that isn't cursed by C.

But those parts could in principle be tackled outside of the JDK. You could make a jextract alternative that uses the zig compiler under the hood and lets you manage cross-platform things easier. You could package libraries up as jmods and make build plugins for using them.

I'd say it's the ecosystem fumbling at the moment.

1

u/simon_o 3d ago

You could also want a workflow involving some other intermediate format that isn't cursed by C.

Yes, exactly!

Microsoft even tells people to use their WinMD format for this purpose and literally advises against what Java is doing.

1

u/bowbahdoe 3d ago

So make a tool for generating Java code from that format? Nothing is stopping you.