Search code examples
iosgenericsxamarin.iosprofilinganonymous-methods

How to profile Monotouch to see count of trampolines (by type) being created at runtime?


There are quite a few posts regarding type 0, type 1 and type 2 trampolines and the runtime error of

"ran out of trampolines"

on iOS devices.

I've got a good understanding of how to increase the number of the different trampoline types during the AOT cross-compile, however, I'm becoming wary of arbitrarily increasing the allocations whenever we run into the ceiling during runtime.

I recently added a component that receives several Func<> arguments, and the majority of consumers of the component are creating the Func<> delegates anonymously. My assumption was that although I could expect that each anonymous delegate would result in the creation of a trampoline, the behavior I seem to be observing is that instead of reusing that trampoline, it continues to create type 0 (ntrampoline [method trampolines?] every time the anon delegate is executed.

What would be extremely helpful is a tool or an api call that would allow me to monitor, log or profile the application at runtime to observe trampoline creation.

Any guidance on side effects of either exposing a generic delegate or anonymous delegate usage would also be appreciated.

Thanks for any tips in the right direction.

Regards, Kevin Ferron


Solution

  • Your best bet is to ask such (very specific) questions to the mono-devel mailing list, i.e. there's several questions (and suggestions wrt profiling) that would make it hard to answer here (even if it could be tagged properly).

    I assume you have already read the links below (but they might help people wondering about trampolines).

    You can also get some statistics from Mono using the --stats option. E.g.

    mono --stats myapp.exe
    
    ...
    JIT statistics
    Unwind info size                    : 198
    Calls to trampolines                : 626
    JIT trampolines                     : 416
    Unbox trampolines                   : 1
    Static rgctx trampolines            : 1
    ...
    

    However it won't help you in MonoTouch context where AOT is used (many thing differs) and where you don't control the execution of the application.