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
15 Test case 2b, with a small type.
18 using System.Runtime.CompilerServices;
19 using static System.Runtime.CompilerServices.MethodImplOptions;
29 [MethodImpl (NoInlining)]
30 static int check (long stack1, long stack2)
32 return (stack1 == stack2) ? 0 : 1;
35 [MethodImpl (NoInlining)]
36 public int Method1 (int counter, long initial_stack, long current_stack)
39 object a = new T[101];
41 return Method2 (counter - 1, initial_stack, (long)&local);
42 return check ((long)&local, current_stack);
45 [MethodImpl (NoInlining)]
46 public int Method2 (int counter, long initial_stack, long current_stack)
49 object a = new T[101];
51 return Method1 (counter - 1, initial_stack, (long)&local);
52 return check ((long)&local, current_stack);
58 [MethodImpl (NoInlining)]
59 public static void Main()
62 Environment.Exit(new A<int>().Method1 (100, (long)&stack, 0));
67 .assembly extern mscorlib { }
69 .assembly 'tailcall-rgctxb' { }
73 // Remove this change the test a lot and make it pass.
74 // It is ok in this case because the ValueType is small.
75 extends [mscorlib]System.ValueType
78 .method static int32 check (int64 stack1, int64 stack2) noinlining
92 .method instance int32 Method1 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
94 .locals init (int32 V_0)
108 tail. call instance int32 valuetype A`1<!T>::Method2 (int32, int64, int64)
116 tail. call int32 valuetype A`1<!T>::check (int64, int64)
120 .method instance int32 Method2 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
122 .locals init (int32 V_0)
135 tail. call instance int32 valuetype A`1<!T>::Method1 (int32, int64, int64)
143 tail. call int32 valuetype A`1<!T>::check (int64, int64)
148 .class B extends [mscorlib]System.Object
151 .method static int32 Main() noinlining
154 .locals init (int32 V_0, valuetype A`1<int32> V_1)
156 initobj valuetype A`1<int32>
166 tail. call instance int32 valuetype A`1<int32>::Method1 (int32, int64, int64)
170 .method instance void .ctor()
173 tail. call instance void [mscorlib]System.Object::.ctor ()