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