[Mono-dev] Long execution time on first execution (in AOT case)

Martin Däumler mdae at cs.tu-chemnitz.de
Wed May 26 08:45:54 EDT 2010


Hi,

a lot of thanks for your answer.

On 04.05.10 10:59 pm, Zoltan Varga wrote:

>     mono is designed to initialize most things lazily, so the first time
> <x> is done, it will take more time. In particular, loading an aot image
> might load it from disk, calling a pinvoke method
> causes the shared libraries referenced by the pinvoke declaration to be
> loaded from disk, etc.

Okay, the aot-image is loaded from disk in scope of the method 
mono_assembly_open() in the mono_main() method. As far as I understood
the Mono source code, the shared libraries referenced by the PInvoke
declaration are loaded in the method mono_lookup_pinvoke_call() in scope
of the chain of methods of the JIT compilation.

> Even calling a method does not initialize all the stuff needed by it,
> some things will only be
> initialized just before it is needed. So if you want to do soft real
> time stuff, mono might not be
> the perfect tool for that.

Well, I investigate how to make the execution of managed code as
deterministic as, say, C/C++ code. So far, I identified some temporal
non-determinisms. The JIT compilation can be brought forward, as
JIT compiled methods are handled by a Mono-internal cache. So, I
adapted the Mono VM to do some kind of "pre-JIT compilation" of the
methods of the assembly to be executed, similar to the "--compile-all"
option. However, it has to be extended to library functions.

What's open at the moment are the handling of trampolines (including 
vtables) and wrapper methods. GC or memory stuff is not investigated
so far.

So my questions are:

1. Which method calls require creating a wrapper? Only those, who may
cause an exception? There are which types of wrappers? Any documentation
about that?

2. Is it possible to execute an assembly with Mono while Mono uses the
standard mscorlib and the assembly uses a custom mscorlib for library
function calls etc.?


> There are some steps that can be taken to decrease the latencies:
> - For pinvoke, there is a Marshal.Prelink method which loads/looks up
> the pinvoked function.

Thank you for that great link. However, Mono crashes while executing
this command in the JIT case. In the AOT case, it works fine and
really reduces first time invocation time.


> On Tue, May 4, 2010 at 2:16 PM, Martin Däumler <mdae at cs.tu-chemnitz.de
> <mailto:mdae at cs.tu-chemnitz.de>> wrote:
>
[...]
>        - Why is the execution of code snippets in a loop faster than
>        when rolling out the loop in the JIT case?

Because the trampoline called the first time patched the native code
to the target address. So, the second call directly goes to the mehtod
instead of jumping into a trampoline. In the JIT case, this is done in
a per-call way, in the AOT case, it is realized by table lookups, so
the table has to be initialized during the first call of a certain
method. Right?


With kind regards,
Martin Däumler


More information about the Mono-devel-list mailing list