[Mono-list] Jit Method Compilation
Paolo Molaro
lupus@ximian.com
Thu, 8 Jan 2004 13:38:14 +0100
On 01/07/04 Marco Dubacher wrote:
> I'm about reading the code of the jit engine. I asked me know where the
> compiled code of the main-method gets actually executed. It must be
> somewhere within the architecture dependend code (e.g. mini-x86.c). Could
> somebody point me to this method or line of code?
The jit uses mono_runtime_run_main() defined in metadata/object.c,
this in tunr calls mono_runtime_exec_main() which eventually calls
mono_runtime_invoke().
mono_runtime_invoke() is the function that is needed to go into the
managed world from the unmanaged one: it deals with a number of issues,
like call convention differences, exception handling etc.
The runtime invoke function is specific to an execution engine, so
the jit-specific one is in mini.c: mono_jit_runtime_invoke().
To make porting easier, the code that handles the unmanaged->managed
transition is created at runtime as IL code (using
mono_marshal_get_runtime_invoke()): this code is jitted and run
from inside mono_jit_runtime_invoke().
> Any comments on that and the re-triggering of the compilation of further
> methods with magic trampolin are of course appreciated.
Right now there is no re-triggering of the compilation of a method.
When the jit sees a call to a method, it inserts a call to a trampoline:
the trampoline will compile the method and transfer arguments and the
control to the newly compiled code. I have posted a while ago a proposal
with the changes needed to allow recompilation of methods (needed, for
example, by runtime profile-driven recompilation).
The trampoline is arch-specific and you'll find the sources in
mini/tramp-{x86,ppc}.c. To avoid the trampoline overhead, we also
patch the call site to call the newly compiled code instead of the
trampoline.
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better