[Mono-devel-list] Is native codes for C# methods and CLI internal calls different?
Paolo Molaro
lupus at ximian.com
Mon Feb 28 05:28:28 EST 2005
On 02/25/05 Okehee Goh wrote:
> I'm using mono1.1.4 with JIT in Linux on X86.
> I'd like to check native codes generated for C# applications with JIT.
> I want to see how C# methods and Mono Internal calls are translated
> into native codes, and also how stack frames for them are different?
> Ultimately I'd like to know that we could distinguish whether certain
> stack frames of a thread are from C# methods or CLI internal functions
> by checking stack frames?
>
> For example, Directory.GetCurrentDirectory () is C# method. This is
> eventually implemented by calling CLI internal function
> ves_icall_System_IO_MonoIO_GetCurrentDirectory().
> Are they both translated into 'call' assembly instruction in X86, for example?
When going from managed stack frames to unmanaged stack frames (this happens
both to call internal calls and to call p/invoke functions), we use a
wrapper method that takes care of adjusting for differences in the calling
convention, marshaling types if needed and setting up the data the JIT
needs to unwind the stack. The latter consists in setting up a MonoLMF
(Last Managed Frame) structure on the stack and linking it in a thread-lcoal
list. The MonoLMF contains the registers, a pointer to the method
info etc.
> In summary, my question is (1) how i can see native codes generated
> for method invocations
> and internal function calls, and (2) whether i can distinguish the stack frames?
To see the code generated you can run mono -v -v program.exe.
You can grep for "managed-to-native" to find the wrapper methods.
The meat of the code for wrapper methods is generated from
mini/mini-ARCH.c, search for save_lmf.
Stack frames are distinguished by the instruction pointer: from the instruction
pointer you can get the MonoJitInfo using mono_jit_info_table_find().
If it returns NULL, the frame belongs to the unmanaged world, so
it could be an external library or a mono internal call (there is no
easy way to distinguish the last two). From the MonoJitInfo struct
you can inspect the MonoMethod and see if the method was a wrapper
or a completely managed method etc.
More information about the Mono-devel-list
mailing list