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