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