Merge pull request #756 from akoeplinger/fix-xmlreader
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
1 /*
2  * dtest-app.cs:
3  *
4  *   Application program used by the debugger tests.
5  */
6 using System;
7 using System.Runtime.CompilerServices;
8 using System.Reflection;
9 using System.Reflection.Emit;
10 using System.Diagnostics;
11 using System.Threading;
12 using System.Collections.Generic;
13 using System.Linq;
14
15 public class TestsBase
16 {
17 #pragma warning disable 0414
18 #pragma warning disable 0169
19         public int base_field_i;
20         public string base_field_s;
21         static int base_static_i = 57;
22         static string base_static_s = "C";
23 #pragma warning restore 0414
24 #pragma warning restore 0169
25 }
26
27 public enum AnEnum {
28         A = 0,
29         B= 1
30 }
31
32 public sealed class Tests3 {
33         public static void M1 () {
34         }
35
36         static void M2 () {
37         }
38
39         public void M3 () {
40         }
41
42         void M4 () {
43         }
44
45 }
46
47 public static class Tests4 {
48         static Tests4 () {
49         }
50 }
51
52 public class AAttribute : Attribute {
53         public int afield;
54 }
55
56 public class BAttribute : AAttribute {
57         public int bfield;
58 }
59
60 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
61 [DebuggerTypeProxy (typeof (Tests))]
62 [BAttribute (afield = 1, bfield = 2)]
63 public class Tests2 {
64         [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
65         public int field_j;
66         public static int static_field_j;
67
68         [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
69         public int AProperty {
70                 get {
71                         return 0;
72                 }
73         }
74
75         public void invoke () {
76         }
77 }
78
79 public struct AStruct {
80         public int i;
81         public string s;
82         public byte k;
83         public IntPtr j;
84
85         [MethodImplAttribute (MethodImplOptions.NoInlining)]
86         public int foo (int val) {
87                 return val;
88         }
89
90         [MethodImplAttribute (MethodImplOptions.NoInlining)]
91         public static int static_foo (int val) {
92                 return val;
93         }
94
95         [MethodImplAttribute (MethodImplOptions.NoInlining)]
96         public int invoke_return_int () {
97                 return i;
98         }
99
100         [MethodImplAttribute (MethodImplOptions.NoInlining)]
101         public static int invoke_static () {
102                 return 5;
103         }
104
105         [MethodImplAttribute (MethodImplOptions.NoInlining)]
106         public IntPtr invoke_return_intptr () {
107                 return j;
108         }
109 }
110
111 public class GClass<T> {
112         public T field;
113         public static T static_field;
114
115         [MethodImplAttribute (MethodImplOptions.NoInlining)]
116         public GClass () {
117         }
118
119         [MethodImplAttribute (MethodImplOptions.NoInlining)]
120         public void bp<T2> () {
121         }
122 }
123
124 public struct GStruct<T> {
125         public T i;
126
127         public int j;
128
129         [MethodImplAttribute (MethodImplOptions.NoInlining)]
130         public int invoke_return_int () {
131                 return j;
132         }
133 }
134
135 interface ITest
136 {
137         void Foo ();
138         void Bar ();
139 }
140
141 interface ITest<T>
142 {
143         void Foo ();
144         void Bar ();
145 }
146
147 class TestIfaces : ITest
148 {
149         void ITest.Foo () {
150         }
151
152         void ITest.Bar () {
153         }
154
155         TestIfaces<int> Baz () {
156                 return null;
157         }
158 }
159
160 class TestIfaces<T> : ITest<T>
161 {
162         void ITest<T>.Foo () {
163         }
164
165         void ITest<T>.Bar () {
166         }
167 }
168
169 public interface ITest2
170 {
171         int invoke_iface ();
172 }
173
174 public class Tests : TestsBase, ITest2
175 {
176 #pragma warning disable 0414
177         int field_i;
178         string field_s;
179         AnEnum field_enum;
180         bool field_bool1, field_bool2;
181         char field_char;
182         byte field_byte;
183         sbyte field_sbyte;
184         short field_short;
185         ushort field_ushort;
186         long field_long;
187         ulong field_ulong;
188         float field_float;
189         double field_double;
190         Thread field_class;
191         IntPtr field_intptr;
192         int? field_nullable;
193         static int static_i = 55;
194         static string static_s = "A";
195         public const int literal_i = 56;
196         public const string literal_s = "B";
197         public object child;
198         public AStruct field_struct;
199         public object field_boxed_struct;
200         public GStruct<int> generic_field_struct;
201         public KeyValuePair<int, object> boxed_struct_field;
202         [ThreadStatic]
203         public static int tls_i;
204         public static bool is_attached = Debugger.IsAttached;
205
206 #pragma warning restore 0414
207
208         public class NestedClass {
209         }
210
211         public int IntProperty {
212                 get {
213                         return field_i;
214                 }
215                 set {
216                         field_i = value;
217                 }
218         }
219
220         public int ReadOnlyProperty {
221                 get {
222                         return field_i;
223                 }
224         }
225
226         public int this [int index] {
227                 get {
228                         return field_i;
229                 }
230         }
231
232         public static void wait_one ()
233         {
234                 ManualResetEvent evt = new ManualResetEvent (false);
235                 evt.WaitOne ();
236         }
237
238         public static int Main (String[] args) {
239                 tls_i = 42;
240
241                 if (args.Length > 0 && args [0] == "suspend-test")
242                         /* This contains an infinite loop, so execute it conditionally */
243                         suspend ();
244                 if (args.Length >0 && args [0] == "unhandled-exception") {
245                         unhandled_exception ();
246                         return 0;
247                 }
248                 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
249                         unhandled_exception_endinvoke ();
250                         return 0;
251                 }
252                 if (args.Length >0 && args [0] == "unhandled-exception-user") {
253                         unhandled_exception_user ();
254                         return 0;
255                 }
256                 if (args.Length >0 && args [0] == "wait-one") {
257                         wait_one ();
258                         return 0;
259                 }
260                 breakpoints ();
261                 single_stepping ();
262                 arguments ();
263                 objects ();
264                 objrefs ();
265                 vtypes ();
266                 locals ();
267                 line_numbers ();
268                 type_info ();
269                 assembly_load ();
270                 invoke ();
271                 exceptions ();
272                 exception_filter ();
273                 threads ();
274                 dynamic_methods ();
275                 user ();
276                 type_load ();
277                 regress ();
278                 gc_suspend ();
279                 if (args.Length > 0 && args [0] == "domain-test")
280                         /* This takes a lot of time, so execute it conditionally */
281                         domains ();
282                 if (args.Length > 0 && args [0] == "ref-emit-test")
283                         ref_emit ();
284                 if (args.Length > 0 && args [0] == "frames-in-native")
285                         frames_in_native ();
286                 if (args.Length > 0 && args [0] == "invoke-single-threaded")
287                         new Tests ().invoke_single_threaded ();
288                 return 3;
289         }
290
291         public static void breakpoints () {
292                 /* Call these early so it is JITted by the time a breakpoint is placed on it */
293                 bp3 ();
294                 bp7<int> ();
295                 bp7<string> ();
296
297                 bp1 ();
298                 bp2 ();
299                 bp3 ();
300                 bp4 ();
301                 bp4 ();
302                 bp4 ();
303                 bp5 ();
304                 bp6<string> (new GClass <int> ());
305                 bp7<int> ();
306                 bp7<string> ();
307         }
308
309         [MethodImplAttribute (MethodImplOptions.NoInlining)]
310         public static void bp1 () {
311         }
312
313         [MethodImplAttribute (MethodImplOptions.NoInlining)]
314         public static void bp2 () {
315         }
316
317         [MethodImplAttribute (MethodImplOptions.NoInlining)]
318         public static void bp3 () {
319         }
320
321         [MethodImplAttribute (MethodImplOptions.NoInlining)]
322         public static void bp4 () {
323         }
324
325         [MethodImplAttribute (MethodImplOptions.NoInlining)]
326         public static void bp5 () {
327         }
328
329         [MethodImplAttribute (MethodImplOptions.NoInlining)]
330         public static void bp6<T> (GClass<int> gc) {
331                 gc.bp<int> ();
332         }
333
334         [MethodImplAttribute (MethodImplOptions.NoInlining)]
335         public static void bp7<T> () {
336         }
337
338         [MethodImplAttribute (MethodImplOptions.NoInlining)]
339         public static void single_stepping () {
340                 bool b = true;
341                 ss1 ();
342                 ss2 ();
343                 ss3 ();
344                 ss3_2 ();
345                 ss4 ();
346                 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
347                 try {
348                         ss6 (b);
349                 } catch {
350                 }
351                 ss7 ();
352                 ss_nested ();
353                 ss_regress_654694 ();
354         }
355
356         [MethodImplAttribute (MethodImplOptions.NoInlining)]
357         public static void ss1 () {
358         }
359
360         [MethodImplAttribute (MethodImplOptions.NoInlining)]
361         public static void ss2 () {
362         }
363
364         [MethodImplAttribute (MethodImplOptions.NoInlining)]
365         public static int ss3 () {
366                 int sum = 0;
367
368                 for (int i = 0; i < 10; ++i)
369                         sum += i;
370
371                 return sum;
372         }
373
374         [MethodImplAttribute (MethodImplOptions.NoInlining)]
375         public static void ss3_2 () {
376                 ss3_2_2 ();
377         }
378
379         [MethodImplAttribute (MethodImplOptions.NoInlining)]
380         public static void ss3_2_2 () {
381         }
382
383         [MethodImplAttribute (MethodImplOptions.NoInlining)]
384         public static int ss4 () {
385                 ss1 (); ss1 ();
386                 ss2 ();
387                 return 0;
388         }
389
390         [MethodImplAttribute (MethodImplOptions.NoInlining)]
391         public static void ss5 (int[] arr, Func<int, bool> selector) {
392                 // Call into linq which calls back into this assembly
393                 arr.Count (selector);
394         }
395
396         [MethodImplAttribute (MethodImplOptions.NoInlining)]
397         public static void ss6 (bool b) {
398                 if (b) {
399                         ss6_2 ();
400                         throw new Exception ();
401                 }
402         }
403
404         [MethodImplAttribute (MethodImplOptions.NoInlining)]
405         public static void ss6_2 () {
406         }
407
408         [MethodImplAttribute (MethodImplOptions.NoInlining)]
409         public static void ss7 () {
410                 try {
411                         ss7_2 ();
412                         ss7_3 ();
413                 } catch {
414                 }
415                 ss7_2 ();
416         }
417
418         [MethodImplAttribute (MethodImplOptions.NoInlining)]
419         public static void ss7_2 () {
420         }
421
422         [MethodImplAttribute (MethodImplOptions.NoInlining)]
423         public static void ss7_3 () {
424                 throw new Exception ();
425         }
426
427         [MethodImplAttribute (MethodImplOptions.NoInlining)]
428         public static void ss_nested () {
429                 ss_nested_1 (ss_nested_2 ());
430                 ss_nested_1 (ss_nested_2 ());
431                 ss_nested_3 ();
432         }
433
434         [MethodImplAttribute (MethodImplOptions.NoInlining)]
435         public static void ss_nested_1 (int i) {
436         }
437
438         [MethodImplAttribute (MethodImplOptions.NoInlining)]
439         public static int ss_nested_2 () {
440                 return 0;
441         }
442
443         [MethodImplAttribute (MethodImplOptions.NoInlining)]
444         public static void ss_nested_3 () {
445         }
446
447         [MethodImplAttribute (MethodImplOptions.NoInlining)]
448         public static bool is_even (int i) {
449                 return i % 2 == 0;
450         }
451
452         /*
453                 lock (static_s) {
454                         Console.WriteLine ("HIT!");
455                 }
456                 return 0;
457         }
458         */
459
460         [MethodImplAttribute (MethodImplOptions.NoInlining)]
461         public static void arguments () {
462                 arg1 (SByte.MaxValue - 5, Byte.MaxValue - 5, true, Int16.MaxValue - 5, UInt16.MaxValue - 5, 'F', Int32.MaxValue - 5, UInt32.MaxValue - 5, Int64.MaxValue - 5, UInt64.MaxValue - 5, 1.2345f, 6.78910, new IntPtr (Int32.MaxValue - 5), new UIntPtr (UInt32.MaxValue - 5));
463                 int i = 42;
464                 arg2 ("FOO", null, "BLA", ref i, new GClass <int> { field = 42 }, new object ());
465                 Tests t = new Tests () { field_i = 42, field_s = "S" };
466                 t.arg3 ("BLA");
467         }
468
469         [MethodImplAttribute (MethodImplOptions.NoInlining)]
470         public static int arg1 (sbyte sb, byte b, bool bl, short s, ushort us, char c, int i, uint ui, long l, ulong ul, float f, double d, IntPtr ip, UIntPtr uip) {
471                 return (int)(sb + b + (bl ? 0 : 1) + s + us + (int)c + i + ui + l + (long)ul + f + d + (int)ip + (int)uip);
472         }
473
474         [MethodImplAttribute (MethodImplOptions.NoInlining)]
475         public static string arg2 (string s, string s3, object o, ref int i, GClass <int> gc, object o2) {
476                 return s + (s3 != null ? "" : "") + o + i + gc.field + o2;
477         }
478
479         [MethodImplAttribute (MethodImplOptions.NoInlining)]
480         public object arg3 (string s) {
481                 return s + s + s + s + this;
482         }
483
484         [MethodImplAttribute (MethodImplOptions.NoInlining)]
485         public static void objects () {
486                 Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5), field_nullable = null };
487                 t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
488                 o2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, (int[,])Array.CreateInstance (typeof (int), new int [] { 2, 2}, new int [] { 1, 3}), new int[] { 0 });
489         }
490
491         [MethodImplAttribute (MethodImplOptions.NoInlining)]
492         public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
493                 if (t == null || gc1 == null || gc2 == null)
494                         return null;
495                 else
496                         return this;
497         }
498
499         [MethodImplAttribute (MethodImplOptions.NoInlining)]
500         public static string o2 (string[] s2, int[] s3, int[,] s4, int[,] s5, IList<int> s6) {
501                 return s2 [0] + s3 [0] + s4 [0, 0] + s6 [0];
502         }
503
504         [MethodImplAttribute (MethodImplOptions.NoInlining)]
505         public static void objrefs () {
506                 Tests t = new Tests () {};
507                 set_child (t);
508                 t.objrefs1 ();
509                 t.child = null;
510                 GC.Collect ();
511                 objrefs2 ();
512         }
513
514         [MethodImplAttribute (MethodImplOptions.NoInlining)]
515         public static void set_child (Tests t) {
516                 t.child = new Tests ();
517         }
518
519         [MethodImplAttribute (MethodImplOptions.NoInlining)]
520         public void objrefs1 () {
521         }
522
523         [MethodImplAttribute (MethodImplOptions.NoInlining)]
524         public static void objrefs2 () {
525         }
526
527         public static void vtypes () {
528                 Tests t = new Tests () { field_struct = new AStruct () { i = 42, s = "S", k = 43 }, generic_field_struct = new GStruct<int> () { i = 42 }, field_boxed_struct = new AStruct () { i = 42 }, boxed_struct_field = new KeyValuePair<int, object> (1, (long)42 ) };
529                 AStruct s = new AStruct { i = 44, s = "T", k = 45 };
530                 AStruct[] arr = new AStruct[] { 
531                         new AStruct () { i = 1, s = "S1" },
532                         new AStruct () { i = 2, s = "S2" } };
533                 t.vtypes1 (s, arr);
534                 vtypes2 (s);
535                 vtypes3 (s);
536         }
537
538         [MethodImplAttribute (MethodImplOptions.NoInlining)]
539         public object vtypes1 (AStruct s, AStruct[] arr) {
540                 if (arr != null)
541                         return this;
542                 else
543                         return null;
544         }
545
546         [MethodImplAttribute (MethodImplOptions.NoInlining)]
547         public static void vtypes2 (AStruct s) {
548                 s.foo (5);
549         }
550
551         [MethodImplAttribute (MethodImplOptions.NoInlining)]
552         public static void vtypes3 (AStruct s) {
553                 AStruct.static_foo (5);
554         }
555
556         [MethodImplAttribute (MethodImplOptions.NoInlining)]
557         public static void locals () {
558                 string s = null;
559                 locals1 (null);
560                 locals2<string> (null, 5, "ABC", ref s);
561                 locals3 ();
562                 locals6 ();
563                 locals7<int> (22);
564         }
565
566         [MethodImplAttribute (MethodImplOptions.NoInlining)]
567         static void locals11 (double a, ref double b) {
568         }
569
570         [MethodImplAttribute (MethodImplOptions.NoInlining)]
571         public static void locals1 (string[] args) {
572                 long foo = 42;
573
574                 double ri = 1;
575                 locals11 (b: ref ri, a: ri);
576
577                 for (int j = 0; j < 10; ++j) {
578                         foo ++;
579                 }
580         }
581
582         [MethodImplAttribute (MethodImplOptions.NoInlining)]
583 #if NET_4_5
584         [StateMachine (typeof (int))]
585 #endif
586         public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
587                 long i = 42;
588                 string s = "AB";
589
590                 for (int j = 0; j < 10; ++j) {
591                         if (s != null)
592                                 i ++;
593                         if (t != null)
594                                 i ++;
595                 }
596                 rs = "A";
597         }
598
599
600         [MethodImplAttribute (MethodImplOptions.NoInlining)]
601         public static void locals3 () {
602                 string s = "B";
603                 s.ToString ();
604
605                 {
606                         long i = 42;
607                         i ++;
608                         locals4 ();
609                 }
610                 {
611                         string i = "A";
612                         i.ToString ();
613                         locals5 ();
614                 }
615                 {
616                         long j = 42;
617                         j ++;
618                 }
619         }
620
621         [MethodImplAttribute (MethodImplOptions.NoInlining)]
622         public static void locals4 () {
623         }
624
625         [MethodImplAttribute (MethodImplOptions.NoInlining)]
626         public static void locals5 () {
627         }
628
629         [MethodImplAttribute (MethodImplOptions.NoInlining)]
630         public static void locals6 () {
631                 int i = 0;
632                 int j = 0;
633                 for (i = 0; i < 10; ++i)
634                         j ++;
635                 sbyte sb = 0;
636                 for (i = 0; i < 10; ++i)
637                         sb ++;
638                 locals6_1 ();
639                 locals6_2 (j);
640                 locals6_3 ();
641                 locals6_4 (j);
642                 locals6_5 ();
643                 locals6_6 (sb);
644         }
645
646         [MethodImplAttribute (MethodImplOptions.NoInlining)]
647         public static void locals6_1 () {
648         }
649
650         [MethodImplAttribute (MethodImplOptions.NoInlining)]
651         public static void locals6_2 (int arg) {
652         }
653
654         [MethodImplAttribute (MethodImplOptions.NoInlining)]
655         public static void locals6_3 () {
656                 // Clobber all registers
657                 int sum = 0, i, j, k, l, m;
658                 for (i = 0; i < 100; ++i)
659                         sum ++;
660                 for (j = 0; j < 100; ++j)
661                         sum ++;
662                 for (k = 0; k < 100; ++k)
663                         sum ++;
664                 for (l = 0; l < 100; ++l)
665                         sum ++;
666                 for (m = 0; m < 100; ++m)
667                         sum ++;
668         }
669
670         [MethodImplAttribute (MethodImplOptions.NoInlining)]
671         public static void locals6_4 (int arg) {
672         }
673
674         [MethodImplAttribute (MethodImplOptions.NoInlining)]
675         public static void locals6_5 () {
676         }
677
678         [MethodImplAttribute (MethodImplOptions.NoInlining)]
679         public static void locals6_6 (int arg) {
680         }
681
682         [MethodImplAttribute (MethodImplOptions.NoInlining)]
683         public static void locals7<T> (T arg) {
684                 T t = arg;
685                 T t2 = t;
686         }
687
688         [MethodImplAttribute (MethodImplOptions.NoInlining)]
689         public static void line_numbers () {
690                 LineNumbers.ln1 ();
691         }
692
693         [MethodImplAttribute (MethodImplOptions.NoInlining)]
694         public static void suspend () {
695                 long i = 5;
696
697                 while (true) {
698                         i ++;
699                 }
700         }
701
702         [MethodImplAttribute (MethodImplOptions.NoInlining)]
703         public static void type_info () {
704                 Tests t = new Tests () { field_i = 42, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B };
705                 t.ti1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
706                 int val = 0;
707                 unsafe {
708                         AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
709
710                         ti2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, ref val, (int*)IntPtr.Zero, 5, s, new Tests (), new Tests2 (), new GClass <int> (), AnEnum.B);
711                 }
712         }
713
714         [MethodImplAttribute (MethodImplOptions.NoInlining)]
715         public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
716                 if (t == null || gc1 == null || gc2 == null)
717                         return null;
718                 else
719                         return this;
720         }
721
722         [MethodImplAttribute (MethodImplOptions.NoInlining)]
723         public static unsafe string ti2 (string[] s2, int[] s3, int[,] s4, ref int ri, int* ptr, int i, AStruct s, Tests t, Tests2 t2, GClass<int> g, AnEnum ae) {
724                 return s2 [0] + s3 [0] + s4 [0, 0];
725         }
726
727         [MethodImplAttribute (MethodImplOptions.NoInlining)]
728         public static void assembly_load () {
729                 assembly_load_2 ();
730         }
731
732         [MethodImplAttribute (MethodImplOptions.NoInlining)]
733         public static void assembly_load_2 () {
734                 // This will load System.dll while holding the loader lock
735                 new Foo ();
736         }
737
738         [MethodImplAttribute (MethodImplOptions.NoInlining)]
739         public static void invoke () {
740                 new Tests ().invoke1 (new Tests2 (), new AStruct () { i = 42, j = (IntPtr)43 }, new GStruct<int> { j = 42 });
741                 new Tests ().invoke_ex ();
742         }
743
744         [MethodImplAttribute (MethodImplOptions.NoInlining)]
745         public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
746                 invoke2 ();
747         }
748
749         [MethodImplAttribute (MethodImplOptions.NoInlining)]
750         public void invoke2 () {
751         }
752
753         [MethodImplAttribute (MethodImplOptions.NoInlining)]
754         public void invoke_ex () {
755                 invoke_ex_inner ();
756         }
757
758         [MethodImplAttribute (MethodImplOptions.NoInlining)]
759         public void invoke_ex_inner () {
760                 try {
761                         throw new Exception ();
762                 } catch {
763                 }
764         }
765
766         int counter;
767
768         [MethodImplAttribute (MethodImplOptions.NoInlining)]
769         public void invoke_single_threaded () {
770                 // Spawn a thread incrementing a counter
771                 bool finished = false;
772
773                 new Thread (delegate () {
774                                 while (!finished)
775                                         counter ++;
776                 }).Start ();
777
778                 Thread.Sleep (100);
779
780                 invoke_single_threaded_2 ();
781
782                 finished = true;
783         }
784
785         [MethodImplAttribute (MethodImplOptions.NoInlining)]
786         public void invoke_single_threaded_2 () {
787         }
788
789         public void invoke_return_void () {
790         }
791
792         public string invoke_return_ref () {
793                 return "ABC";
794         }
795
796         public object invoke_return_null () {
797                 return null;
798         }
799
800         public int invoke_return_primitive () {
801                 return 42;
802         }
803
804         public int? invoke_return_nullable () {
805                 return 42;
806         }
807
808         public int? invoke_return_nullable_null () {
809                 return null;
810         }
811
812         public void invoke_type_load () {
813                 new Class3 ();
814         }
815
816         class Class3 {
817         }
818
819         public long invoke_pass_primitive (byte ub, sbyte sb, short ss, ushort us, int i, uint ui, long l, ulong ul, char c, bool b, float f, double d) {
820                 return ub + sb + ss + us + i + ui + l + (long)ul + (int)c + (b ? 1 : 0) + (int)f + (int)d;
821         }
822
823         public int invoke_pass_primitive2 (bool b) {
824                 return b ? 1 : 0;
825         }
826
827         public string invoke_pass_ref (string s) {
828                 return s;
829         }
830
831         public static string invoke_static_pass_ref (string s) {
832                 return s;
833         }
834
835         public static void invoke_static_return_void () {
836         }
837
838         public static void invoke_throws () {
839                 throw new Exception ();
840         }
841
842         public int invoke_iface () {
843                 return 42;
844         }
845
846         [MethodImplAttribute (MethodImplOptions.NoInlining)]
847         public static void exceptions () {
848                 try {
849                         throw new OverflowException ();
850                 } catch (Exception) {
851                 }
852                 try {
853                         throw new OverflowException ();
854                 } catch (Exception) {
855                 }
856                 try {
857                         throw new ArgumentException ();
858                 } catch (Exception) {
859                 }
860                 try {
861                         throw new OverflowException ();
862                 } catch (Exception) {
863                 }
864
865                 object o = null;
866                 try {
867                         o.GetType ();
868                 } catch (Exception) {
869                 }
870
871                 try {
872                         exceptions2 ();
873                 } catch (Exception) {
874                 }
875         }
876
877         [MethodImplAttribute (MethodImplOptions.NoInlining)]
878         public static void unhandled_exception () {
879                 ThreadPool.QueueUserWorkItem (delegate {
880                                 throw new InvalidOperationException ();
881                         });
882                 Thread.Sleep (10000);
883         }
884
885         [MethodImplAttribute (MethodImplOptions.NoInlining)]
886         public static void unhandled_exception_endinvoke_2 () {
887         }
888
889         [MethodImplAttribute (MethodImplOptions.NoInlining)]
890         public static void unhandled_exception_endinvoke () {
891                         Action action = new Action (() => 
892                         {
893                                 throw new Exception ("thrown");
894                         });
895                         action.BeginInvoke ((ar) => {
896                                 try {
897                                         action.EndInvoke (ar);
898                                 } catch (Exception ex) {
899                                         //Console.WriteLine (ex);
900                                 }
901                         }, null);
902                 Thread.Sleep (1000);
903                 unhandled_exception_endinvoke_2 ();
904         }
905
906         [MethodImplAttribute (MethodImplOptions.NoInlining)]
907         public static void unhandled_exception_user () {
908 #if NET_4_5
909                 System.Threading.Tasks.Task.Factory.StartNew (() => {
910                                 Throw ();
911                         });
912                 Thread.Sleep (10000);
913 #endif
914         }
915
916         [MethodImplAttribute (MethodImplOptions.NoInlining)]
917         public static void Throw () {
918                 throw new Exception ();
919         }
920
921         internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
922         {
923                 if (dlg == null)
924                         throw new ArgumentNullException ();
925                 if (dlg.Target != null)
926                         throw new ArgumentException ();
927                 if (dlg.Method == null)
928                         throw new ArgumentException ();
929
930                 var ret_type = dlg.Method.ReturnType;
931                 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
932
933                 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
934                 var ig = dynamic.GetILGenerator ();
935
936                 LocalBuilder retval = null;
937                 if (ret_type != typeof (void))
938                         retval = ig.DeclareLocal (ret_type);
939
940                 var label = ig.BeginExceptionBlock ();
941
942                 for (int i = 0; i < param_types.Length; i++)
943                         ig.Emit (OpCodes.Ldarg, i);
944                 ig.Emit (OpCodes.Call, dlg.Method);
945
946                 if (retval != null)
947                         ig.Emit (OpCodes.Stloc, retval);
948
949                 ig.Emit (OpCodes.Leave, label);
950
951                 ig.BeginExceptFilterBlock ();
952
953                 ig.Emit (OpCodes.Call, filter_method);
954
955                 ig.BeginCatchBlock (null);
956
957                 ig.Emit (OpCodes.Pop);
958
959                 ig.EndExceptionBlock ();
960
961                 if (retval != null)
962                         ig.Emit (OpCodes.Ldloc, retval);
963
964                 ig.Emit (OpCodes.Ret);
965
966                 return dynamic.CreateDelegate (dlg.GetType ());
967         }
968
969         [MethodImplAttribute (MethodImplOptions.NoInlining)]
970         static void exception_filter_method () {
971                 throw new InvalidOperationException ();
972         }
973
974         [MethodImplAttribute (MethodImplOptions.NoInlining)]
975         static int exception_filter_filter (Exception exc) {
976                 return 1;
977         }
978
979         [MethodImplAttribute (MethodImplOptions.NoInlining)]
980         public static void exception_filter () {
981                 var method = typeof (Tests).GetMethod (
982                         "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
983                 var filter_method = typeof (Tests).GetMethod (
984                         "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
985
986                 var dlg = Delegate.CreateDelegate (typeof (Action), method);
987
988                 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
989
990                 wrapper ();
991         }
992
993         [MethodImplAttribute (MethodImplOptions.NoInlining)]
994         public static bool return_true () {
995                 return true;
996         }
997
998         [MethodImplAttribute (MethodImplOptions.NoInlining)]
999         public static void exceptions2 () {
1000                 if (return_true ())
1001                         throw new Exception ();
1002                 Console.WriteLine ();
1003         }
1004
1005         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1006         public static void threads () {
1007                 Thread t = new Thread (delegate () {});
1008
1009                 t.Start ();
1010                 t.Join ();
1011         }
1012
1013         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1014         public static void domains () {
1015                 AppDomain domain = AppDomain.CreateDomain ("domain");
1016
1017                 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1018                                    typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1019
1020                 domains_2 (o, new CrossDomain ());
1021
1022                 o.invoke_2 ();
1023
1024                 o.invoke ();
1025
1026                 o.invoke_2 ();
1027
1028                 AppDomain.Unload (domain);
1029
1030                 domains_3 ();
1031         }
1032
1033         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1034         public static void domains_2 (object o, object o2) {
1035         }
1036
1037         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1038         public static void domains_3 () {
1039         }
1040
1041         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1042         public static void invoke_in_domain () {
1043         }
1044
1045         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1046         public static void invoke_in_domain_2 () {
1047         }
1048
1049         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1050         public static void dynamic_methods () {
1051                 var m = new DynamicMethod ("dyn_method", typeof (void), new Type []  { typeof (int) }, typeof (object).Module);
1052                 var ig = m.GetILGenerator ();
1053
1054                 ig.Emit (OpCodes.Ldstr, "FOO");
1055                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1056                 ig.Emit (OpCodes.Ret);
1057
1058                 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1059
1060                 del (0);
1061         }
1062
1063         public static void dyn_call (string s) {
1064         }
1065
1066         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1067         public static void ref_emit () {
1068                 AssemblyName assemblyName = new AssemblyName ();
1069                 assemblyName.Name = "foo";
1070
1071                 AssemblyBuilder assembly =
1072                         Thread.GetDomain ().DefineDynamicAssembly (
1073                                                                                                            assemblyName, AssemblyBuilderAccess.RunAndSave);
1074
1075                 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
1076
1077                 TypeBuilder tb = module.DefineType ("foo", TypeAttributes.Public, typeof (object));
1078                 MethodBuilder mb = tb.DefineMethod ("ref_emit_method", MethodAttributes.Public|MethodAttributes.Static, CallingConventions.Standard, typeof (void), new Type [] { });
1079                 ILGenerator ig = mb.GetILGenerator ();
1080                 ig.Emit (OpCodes.Ldstr, "FOO");
1081                 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("ref_emit_call"));
1082                 ig.Emit (OpCodes.Ret);
1083
1084                 Type t = tb.CreateType ();
1085
1086                 t.GetMethod ("ref_emit_method").Invoke (null, null);
1087         }
1088
1089         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1090         public static void ref_emit_call (string s) {
1091         }
1092
1093         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1094         public static void frames_in_native () {
1095                 Thread.Sleep (500);
1096                 var evt = new ManualResetEvent (false);
1097                 
1098                 object mon = new object ();
1099                 ThreadPool.QueueUserWorkItem (delegate {
1100                                 frames_in_native_2 ();
1101                                 evt.Set ();
1102                         });
1103                 evt.WaitOne ();
1104         }
1105
1106         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1107         static void frames_in_native_2 () {
1108                 frames_in_native_3 ();
1109         }
1110
1111         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1112         static void frames_in_native_3 () {
1113         }
1114
1115         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1116         public static void string_call (string s) {
1117         }
1118
1119         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1120         public static void ss_regress_654694 () {
1121                 if (true) {
1122                         string h = "hi";
1123                         string_call (h);
1124                 }
1125         }
1126
1127         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1128         public static void user () {
1129                 Debugger.Break ();
1130
1131                 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1132         }
1133
1134         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1135         public static void type_load () {
1136                 type_load_2 ();
1137         }
1138
1139         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1140         static void type_load_2 () {
1141                 var c1 = new Dictionary<int, int> ();
1142                 c1.ToString ();
1143                 var c = new TypeLoadClass ();
1144                 c.ToString ();
1145                 var c2 = new TypeLoadClass2 ();
1146                 c2.ToString ();
1147         }
1148
1149         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1150         public static void regress () {
1151                 regress_2755 (DateTime.Now);
1152         }
1153
1154         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1155         public static unsafe void regress_2755 (DateTime d) {
1156                 int* buffer = stackalloc int [128];
1157
1158                 regress_2755_2 ();
1159
1160                 int sum = 0;
1161                 for (int i = 0; i < 128; ++i)
1162                         sum += buffer [i];
1163
1164                 regress_2755_3 (sum);
1165         }
1166
1167         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1168         public static void regress_2755_2 () {
1169         }
1170
1171         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1172         public static void regress_2755_3 (int sum) {
1173         }
1174
1175         static object gc_suspend_field;
1176
1177         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1178         static unsafe void set_gc_suspend_field () {
1179                 set_gc_suspend_field_2 ();
1180                 // Clear stack
1181                 int* buffer = stackalloc int [4096];
1182         }
1183
1184         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1185         static void set_gc_suspend_field_2 () {
1186                 gc_suspend_field = new object ();
1187         }
1188
1189         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1190         static void gc_suspend_1 () {
1191         }
1192
1193         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1194         public static void gc_suspend_invoke () {
1195                 gc_suspend_field = null;
1196                 GC.Collect ();
1197                 GC.WaitForPendingFinalizers ();
1198         }
1199
1200         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1201         public static void gc_suspend () {
1202                 set_gc_suspend_field ();
1203                 gc_suspend_1 ();
1204         }
1205
1206         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1207         public static void generic_method<T> () where T : class {
1208         }
1209 }
1210
1211 class TypeLoadClass {
1212 }
1213
1214 class TypeLoadClass2 {
1215 }
1216
1217 public class CrossDomain : MarshalByRefObject
1218 {
1219         public void invoke () {
1220                 Tests.invoke_in_domain ();
1221         }
1222
1223         public void invoke_2 () {
1224                 Tests.invoke_in_domain_2 ();
1225         }
1226
1227         public int invoke_3 () {
1228                 return 42;
1229         }
1230 }       
1231
1232 public class Foo
1233 {
1234         public ProcessStartInfo info;
1235 }
1236
1237 // Class used for line number info testing, don't change its layout
1238 public class LineNumbers
1239 {
1240         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1241         public static void ln1 () {
1242                 // Column 3
1243                 ln2 ();
1244                 ln3 ();
1245         }
1246
1247         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1248         public static void ln2 () {
1249         }
1250
1251         [MethodImplAttribute (MethodImplOptions.NoInlining)]
1252         public static void ln3 () {
1253 #pragma warning disable 0219
1254                 int i = 5;
1255 #pragma warning restore 0219
1256                 #line 55 "FOO"
1257         }
1258 }