4 ms·
It certainly uses native machine code, but I don't think it generates any at runtime outside of the reverse-FFI closures (at least on linux)? PROT_EXEC at least
by dzaima 2y ago
It certainly uses native machine code, but I don't think it generates any at runtime outside of the reverse-FFI closures (at least on linux)? PROT_EXEC at least isn't used outside of them, which'd be a minimum requirement for linux JITting.
Running in a debugger an ffi_call to a "int add(int a, int b)" leads me to https://github.com/libffi/libffi/blob/1716f81e9a115d340429504563bc8e7fb2eeef2b/src/x86/unix64.S#L84-L104 https://github.com/libffi/libffi/blob/1716f81e9a115d34042950... as the assembly directly before the function is invoked, and, besides clearly not being JITted from me being able to link to it, it is clearly inefficient and unnecessarily general for the given call, loading 7 arguments instead of just the two necessary ones.
- nialv7 2y agoOops, you are right. I think because the other direction of libffi - ffi_closure - has a jitted trampoline, I mistakenly thought both directions are jitted. Thanks for the correction.
- dzaima 2y agoAnd the JITting in closures amounts to a total of three instructions; certainly not for speed, rather just as the bare minimum to generate distinct function pointers at runtime.