It looks convoluted and uses one additional word of stack space per call, but does not contain any unpredictable indirect branches in the fast path (and in fact reduces overall code size as it can be expected that there are many more sends than methods).
Re:Dissecting objc_msgSend on ARM64
by dfox on Sunday July 02, 2017 @09:40AM
(#14682440)
It is safe as long as everything that can get into the cache starts with the validity checking prologue and there is only one thread. Making this thread-safe is probably non-trivial.
Smalltalk/X takes this to the extreme by compiling all sends into code like:
And generates something like this into every method prologue: It looks convoluted and uses one additional word of stack space per call, but does not contain any unpredictable indirect branches in the fast path (and in fact reduces overall code size as it can be expected that there are many more sends than methods).