You can directly link RealObjectUnderTest CompiledMethod using the ObjectsAsMethodsWrapper library . This provides a convenient API for installing and removing shells along with some handy predefined shells.
They will intercept self-sending, since the wrappers are installed in the dictionary of real objects and, thus, can make arbitrary changes to the message before passing it to the base CompiledMethod .
While my example shows how to memoize a method call without touching the source code, it should provide you with the basic knowledge needed to retrieve method calls.
There is a limitation in this particular method: it intercepts self-sends messages that the class itself defines. Therefore, if Foo subclasses Bar and you install wrappers in Foo , you will not intercept messages that form part of the Bar protocol (unless, of course, you wrap them).
You will not be able to intercept ifTrue:ifFalse: timesRepeat or similar messages in a Squeak or Pharo image (and probably in GNU Smalltalk too), because these are not message sendings: compile-time transformations built into this message send in transfer byte codes. (The illusion of sending a message is relatively convincing, because Decompiler knows how not to convert bytecodes back to ifTrue:ifFalse: or something else.)
source share