总结
最终调用mono_jit_compile_method_with_opt
,使用JIT对方法进行编译优化,返回JIT方法指针。
源码
CSharp函数声明
RuntimeMethodHandle.cs#L81
1 2 3 4 5 6 7
| [MethodImpl (MethodImplOptions.InternalCall)] static extern IntPtr GetFunctionPointer (IntPtr m);
public IntPtr GetFunctionPointer () { return GetFunctionPointer (value); }
|
声明为MethodImplOptions.InternalCall
声明
icall-def-netcore.h#L387
1
| HANDLES(MHAN_1, "GetFunctionPointer", ves_icall_RuntimeMethodHandle_GetFunctionPointer, gpointer, 1, (MonoMethod_ptr))
|
实现
icall.c#L7768
1 2 3 4 5
| gpointer ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method, MonoError *error) { return mono_compile_method_checked (method, error); }
|
mono_compile_method_checked
声明
object-internals.h#L2128
1 2
| void* mono_compile_method_checked (MonoMethod *method, MonoError *error);
|
实现
object.c#L797
1 2 3 4 5 6 7 8 9 10 11 12 13
| gpointer mono_compile_method_checked (MonoMethod *method, MonoError *error) { gpointer res;
MONO_REQ_GC_NEUTRAL_MODE
error_init (error);
g_assert (callbacks.compile_method); res = callbacks.compile_method (method, error); return res; }
|
callbacks.compile_method
mini-runtime.c#L4445
1 2
| #ifdef JIT_TRAMPOLINES_WORK callbacks.compile_method = mono_jit_compile_method;
|
mono_jit_compile_method
mini-runtime.c#L2755
1 2 3 4 5 6 7 8
| gpointer mono_jit_compile_method (MonoMethod *method, MonoError *error) { gpointer code;
code = mono_jit_compile_method_with_opt (method, mono_get_optimizations_for_method (method, default_opt), FALSE, error); return code; }
|