[Mono-dev] JIT: translate a method two times : one with hook and the other without hook function?

Okehee Goh okehee at gmail.com
Wed Apr 19 13:56:20 EDT 2006

I am trying to do a small experiment by extending MONO internal.

<the first requirement>
I'd like to add a certain hook function in front of some methods. There were
some approaches discussed before about it like using pre-processor to
manipulate C# source code or assembly file. But, I'd like to make it work by
extending MONO. The hook function is also an internal function within MONO.

<the second requirement>
Methods of a class are class-based. That is, the objects from the class use
same methods.
But, I'd like to make methods perform some different action per object.
For example,
A  class C1 has a method method1(). The objects O1 and O2 are instances of
the class C1.
When O1.method1() is called, it performs some action through a hook
function, and then executes method1().
When O2.method1() is called, it just executes method1().

One approach might generate two different native codes for the method: one
with hook function, and the other without hook function. Then, create two
vtable: one with the method with hook (name it as vtable1), and the other
with the method without hook function (vtable2).
Then, let the objects to point to different vtable like O1 pointing to
vtable1 and O2 pointing to vtable2.

<Question1> It doesn't need to be this approach as long as calling
O2.method1() performs the hook first, then execute its main method. But,
making the hook call the method might not be easy because there is  no way
to define an internal function in runtime, which comply with the signature
of the method?

<Question2 : what i' d like to know>
To do it, I'd like to get some hints which source parts of MONO I have to
look at. There are two parts I have to figure out in mono:
 (first) how to insert a hook? mono_method_to_ir() in mini.c seems to be the
spot to insert a hook.
 (second)   where to have a method translated two time? Should it be
somewhere of mini_method_compile()?

One assumption is that I already know which methods and objects are
the target.

Sorry about this long posting.
I appreciate any hint or opinion.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060419/d990a81e/attachment.html 

More information about the Mono-devel-list mailing list