r/java • u/yetanotherhooman • Dec 05 '25
I can’t think of an application of this but it looks pretty cool.
https://github.com/devsh0/HelloMachineUsing FFI, it’s now possible to execute raw machine code purely from Java without relying on a C/C++ toolchian.
72
Upvotes
5
u/manifoldjava Dec 05 '25
Well done!
This opens the door to a pure Java assembly interpreter. Allowing you to directly execute the assembly:
Inline assembly in Java ;)
3
u/tomwhoiscontrary Dec 05 '25
Why go through the signal handler? Why not just call into the code through a function pointer?
2
u/davidalayachew Dec 05 '25
Woah, I never would have thought to do this. That's very clever.
Though, isn't this similar to what the JVM does under the hood to our Java methods when they get inlined or whatever it's called?
9
u/lppedd Dec 05 '25
Pretty cool!
I guess we'll get inline assembly sooner or later, maybe with a nice abstraction over it : )
9
u/Environmental-Log215 Dec 05 '25 edited Dec 05 '25
Nice to see fellow FFM enthusiast. https://www.roray.dev/blog/myra-stack/
I am building FFM focused libraries. myra-transport heavily depends on libiouring being called thru Java using FFM
P.S. ofcourse not calling native assembly code but FFM is practical and useful for quite a lot of usecases
2
u/Sacaldur Dec 05 '25
One potential use case could be an emulator with dynamic recompilation of the game it's running (instead of just interpeting it). Whether you want to do something like this is a different matter.
You could compare this to what JIT is doing, but for the games that might be supposed to run on a completely different architecture - just like the JVM is completely different from the computer it's running on.