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