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