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
16 This passes on desktop but not Mono.
18 It fails because Mono will not tailcall when "this" is a valuetype,
19 in case it is in current frame. A range check could handle this.
21 Another test tailcall-rgctxb-static should be provided.
24 using System.Runtime.CompilerServices;
25 using static System.Runtime.CompilerServices.MethodImplOptions;
31 a = b = c = d = e = f = g = h = 1;
33 public int a, b, c, d, e, f, g, h;
35 [MethodImpl (NoInlining)]
36 static int check (long stack1, long stack2)
38 return (stack1 == stack2) ? 0 : 1;
41 [MethodImpl (NoInlining)]
42 public int f1 (int counter, long initial_stack, long current_stack)
45 object a = new T[101];
47 return f2 (counter - 1, initial_stack, (long)&local);
48 return check ((long)&local, current_stack);
51 [MethodImpl (NoInlining)]
52 public int f2 (int counter, long initial_stack, long current_stack)
55 object a = new T[101];
57 return f1 (counter - 1, initial_stack, (long)&local);
58 return check ((long)&local, current_stack);
64 [MethodImpl (NoInlining)]
65 public static void Main()
68 Environment.Exit(new A<int>().f1 (100, (long)&stack, 0));
73 .assembly extern mscorlib { }
75 .assembly 'tailcall-rgctxb' { }
79 // Remove this change the test a lot and make it pass.
80 extends [mscorlib]System.ValueType
83 .method static int32 check (int64 stack1, int64 stack2) noinlining
97 .method instance int32 f1 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
99 .locals init (int32 V_0)
113 tail. call instance int32 valuetype A`1<!T>::f2 (int32, int64, int64)
121 tail. call int32 valuetype A`1<!T>::check (int64, int64)
125 .method instance int32 f2 (int32 counter, int64 initial_stack, int64 current_stack) noinlining
127 .locals init (int32 V_0)
140 tail. call instance int32 valuetype A`1<!T>::f1 (int32, int64, int64)
148 tail. call int32 valuetype A`1<!T>::check (int64, int64)
153 .class B extends [mscorlib]System.Object
156 .method static int32 Main() noinlining
159 .locals init (int32 V_0, valuetype A`1<int32> V_1)
161 initobj valuetype A`1<int32>
171 tail. call instance int32 valuetype A`1<int32>::f1 (int32, int64, int64)
175 .method instance void .ctor()
178 tail. call instance void [mscorlib]System.Object::.ctor ()