3 Jay Krell (jaykrell@microsoft.com)
5 Copyright 2018 Microsoft
6 Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 http://www.mono-project.com/docs/advanced/runtime/docs/generic-sharing/
9 1. Non-generic non-static methods of reference types have access to the
10 RGCTX via the “this” argument (this->vtable->rgctx).
11 2. a. Non-generic static methods of reference types and b. non-generic methods
12 of value types need to be passed a pointer to the caller’s class’s VTable in the MONO_ARCH_RGCTX_REG register.
13 3. Generic methods need to be passed a pointer to the MRGCTX in the MONO_ARCH_RGCTX_REG register
18 using System.Runtime.CompilerServices;
19 using static System.Runtime.CompilerServices.MethodImplOptions;
23 [MethodImpl (NoInlining)]
24 static int check (long stack1, long stack2)
26 return (stack1 == stack2) ? 0 : 1;
29 [MethodImpl (NoInlining)]
30 public int f1<T> (int counter, long initial_stack, long current_stack)
34 return f2<T> (counter - 1, initial_stack, (long)&local);
35 return check ((long)&local, current_stack);
38 [MethodImpl (NoInlining)]
39 public int f2<T> (int counter, long initial_stack, long current_stack)
43 return f1<T> (counter - 1, initial_stack, (long)&local);
44 return check ((long)&local, current_stack);
50 [MethodImpl (NoInlining)]
51 public static void Main()
54 Environment.Exit(new A().f1<object> (100, (long)&stack, 0));
59 .assembly extern mscorlib { }
61 .assembly 'tailcall-mrgctx' { }
65 .method static int32 check (int64 stack1, int64 stack2) noinlining
79 .method instance int32 f1<T> (int32 counter, int64 initial_stack, int64 current_stack) noinlining
81 .locals init (int32 V_0)
84 ble.s IL_0013 // if (counter <= 0) goto 13.
90 ldarg.2 // initial_stack
91 ldloca.s V_0 // &local
92 conv.u // (long)&local
93 conv.u8 // (long)&local
94 tail. call instance int32 A::f2<!!0> (int32, int64, int64)
98 ldloca.s V_0 // &local
99 conv.u // (long)&local
100 conv.u8 // (long)&local
101 ldarg.3 // current_stack
102 tail. call int32 A::check (int64, int64)
106 .method instance int32 f2<T> (int32 counter, int64 initial_stack, int64 current_stack) noinlining
108 .locals init (int32 V_0)
121 tail. call instance int32 A::f1<!!0> (int32, int64, int64)
129 tail. call int32 A::check (int64, int64)
133 .method instance void .ctor ()
136 tail. call instance void [mscorlib]System.Object::.ctor ()
144 .method static int32 Main () noinlining
147 .locals init (int32 V_0)
148 newobj instance void A::.ctor ()
155 tail. call instance int32 A::f1<object> (int32, int64, int64)
159 .method instance void .ctor ()
162 tail. call instance void [mscorlib]System.Object::.ctor ()