4 * Application program used by the debugger tests.
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;
15 public class TestsBase
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
32 public sealed class Tests3 {
33 public static void M1 () {
47 public static class Tests4 {
52 public class AAttribute : Attribute {
56 public class BAttribute : AAttribute {
60 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
61 [DebuggerTypeProxy (typeof (Tests))]
62 [BAttribute (afield = 1, bfield = 2)]
64 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
66 public static int static_field_j;
68 [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
69 public int AProperty {
75 public void invoke () {
79 public struct AStruct {
85 [MethodImplAttribute (MethodImplOptions.NoInlining)]
86 public int foo (int val) {
90 [MethodImplAttribute (MethodImplOptions.NoInlining)]
91 public static int static_foo (int val) {
95 [MethodImplAttribute (MethodImplOptions.NoInlining)]
96 public int invoke_return_int () {
100 [MethodImplAttribute (MethodImplOptions.NoInlining)]
101 public static int invoke_static () {
105 [MethodImplAttribute (MethodImplOptions.NoInlining)]
106 public IntPtr invoke_return_intptr () {
111 public class GClass<T> {
113 public static T static_field;
115 [MethodImplAttribute (MethodImplOptions.NoInlining)]
119 [MethodImplAttribute (MethodImplOptions.NoInlining)]
120 public void bp<T2> () {
124 public struct GStruct<T> {
129 [MethodImplAttribute (MethodImplOptions.NoInlining)]
130 public int invoke_return_int () {
135 public struct NestedStruct {
136 NestedInner nested1, nested2;
139 public struct NestedInner {
154 class TestIfaces : ITest
162 TestIfaces<int> Baz () {
167 class TestIfaces<T> : ITest<T>
169 void ITest<T>.Foo () {
172 void ITest<T>.Bar () {
176 public interface ITest2
181 public class Tests : TestsBase, ITest2
183 #pragma warning disable 0414
187 bool field_bool1, field_bool2;
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";
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;
210 public static int tls_i;
211 public static bool is_attached = Debugger.IsAttached;
212 public NestedStruct nested_struct;
214 #pragma warning restore 0414
216 public class NestedClass {
219 public int IntProperty {
228 public int ReadOnlyProperty {
234 public int this [int index] {
240 public static void wait_one ()
242 ManualResetEvent evt = new ManualResetEvent (false);
246 public static int Main (String[] args) {
249 if (args.Length > 0 && args [0] == "suspend-test")
250 /* This contains an infinite loop, so execute it conditionally */
252 if (args.Length >0 && args [0] == "unhandled-exception") {
253 unhandled_exception ();
256 if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
257 unhandled_exception_endinvoke ();
260 if (args.Length >0 && args [0] == "unhandled-exception-user") {
261 unhandled_exception_user ();
264 if (args.Length >0 && args [0] == "wait-one") {
287 if (args.Length > 0 && args [0] == "domain-test")
288 /* This takes a lot of time, so execute it conditionally */
290 if (args.Length > 0 && args [0] == "ref-emit-test")
292 if (args.Length > 0 && args [0] == "frames-in-native")
294 if (args.Length > 0 && args [0] == "invoke-single-threaded")
295 new Tests ().invoke_single_threaded ();
299 public static void breakpoints () {
300 /* Call these early so it is JITted by the time a breakpoint is placed on it */
312 bp6<string> (new GClass <int> ());
317 [MethodImplAttribute (MethodImplOptions.NoInlining)]
318 public static void bp1 () {
321 [MethodImplAttribute (MethodImplOptions.NoInlining)]
322 public static void bp2 () {
325 [MethodImplAttribute (MethodImplOptions.NoInlining)]
326 public static void bp3 () {
329 [MethodImplAttribute (MethodImplOptions.NoInlining)]
330 public static void bp4 () {
333 [MethodImplAttribute (MethodImplOptions.NoInlining)]
334 public static void bp5 () {
337 [MethodImplAttribute (MethodImplOptions.NoInlining)]
338 public static void bp6<T> (GClass<int> gc) {
342 [MethodImplAttribute (MethodImplOptions.NoInlining)]
343 public static void bp7<T> () {
346 [MethodImplAttribute (MethodImplOptions.NoInlining)]
347 public static void single_stepping () {
354 ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
361 ss_regress_654694 ();
367 [MethodImplAttribute (MethodImplOptions.NoInlining)]
368 public static void ss1 () {
371 [MethodImplAttribute (MethodImplOptions.NoInlining)]
372 public static void ss2 () {
375 [MethodImplAttribute (MethodImplOptions.NoInlining)]
376 public static int ss3 () {
379 for (int i = 0; i < 10; ++i)
385 [MethodImplAttribute (MethodImplOptions.NoInlining)]
386 public static void ss3_2 () {
390 [MethodImplAttribute (MethodImplOptions.NoInlining)]
391 public static void ss3_2_2 () {
394 [MethodImplAttribute (MethodImplOptions.NoInlining)]
395 public static int ss4 () {
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);
407 [MethodImplAttribute (MethodImplOptions.NoInlining)]
408 public static void ss6 (bool b) {
411 throw new Exception ();
415 [MethodImplAttribute (MethodImplOptions.NoInlining)]
416 public static void ss6_2 () {
419 [MethodImplAttribute (MethodImplOptions.NoInlining)]
420 public static void ss7 () {
429 [MethodImplAttribute (MethodImplOptions.NoInlining)]
430 public static void ss7_2 () {
433 [MethodImplAttribute (MethodImplOptions.NoInlining)]
434 public static void ss7_3 () {
435 throw new Exception ();
438 [MethodImplAttribute (MethodImplOptions.NoInlining)]
439 public static void ss_nested () {
440 ss_nested_1 (ss_nested_2 ());
441 ss_nested_1 (ss_nested_2 ());
445 [MethodImplAttribute (MethodImplOptions.NoInlining)]
446 public static void ss_nested_1 (int i) {
449 [MethodImplAttribute (MethodImplOptions.NoInlining)]
450 public static int ss_nested_2 () {
454 [MethodImplAttribute (MethodImplOptions.NoInlining)]
455 public static void ss_nested_3 () {
458 [MethodImplAttribute (MethodImplOptions.NoInlining)]
459 public static void ss_step_through () {
461 StepThroughClass.step_through_2 ();
465 [DebuggerStepThrough]
466 [MethodImplAttribute (MethodImplOptions.NoInlining)]
467 public static void step_through_1 () {
470 [DebuggerStepThrough]
471 class StepThroughClass {
472 [MethodImplAttribute (MethodImplOptions.NoInlining)]
473 public static void step_through_2 () {
477 [DebuggerStepThrough]
478 [MethodImplAttribute (MethodImplOptions.NoInlining)]
479 public static void step_through_3 () {
482 [MethodImplAttribute (MethodImplOptions.NoInlining)]
483 public static void ss_recursive (int n) {
486 ss_recursive (n + 1);
489 [MethodImplAttribute (MethodImplOptions.NoInlining)]
490 public static void ss_fp_clobber () {
491 double v = ss_fp_clobber_1 (5.0);
495 [MethodImplAttribute (MethodImplOptions.NoInlining)]
496 public static double ss_fp_clobber_1 (double d) {
500 [MethodImplAttribute (MethodImplOptions.NoInlining)]
501 public static void ss_fp_clobber_2 (double d) {
504 [MethodImplAttribute (MethodImplOptions.NoInlining)]
505 public static bool is_even (int i) {
511 Console.WriteLine ("HIT!");
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));
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" };
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);
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;
536 [MethodImplAttribute (MethodImplOptions.NoInlining)]
537 public object arg3 (string s) {
538 return s + s + s + s + this;
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 });
548 [MethodImplAttribute (MethodImplOptions.NoInlining)]
549 public object o1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
550 if (t == null || gc1 == null || gc2 == null)
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];
561 [MethodImplAttribute (MethodImplOptions.NoInlining)]
562 public static void objrefs () {
563 Tests t = new Tests () {};
571 [MethodImplAttribute (MethodImplOptions.NoInlining)]
572 public static void set_child (Tests t) {
573 t.child = new Tests ();
576 [MethodImplAttribute (MethodImplOptions.NoInlining)]
577 public void objrefs1 () {
580 [MethodImplAttribute (MethodImplOptions.NoInlining)]
581 public static void objrefs2 () {
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" } };
595 [MethodImplAttribute (MethodImplOptions.NoInlining)]
596 public object vtypes1 (AStruct s, AStruct[] arr) {
603 [MethodImplAttribute (MethodImplOptions.NoInlining)]
604 public static void vtypes2 (AStruct s) {
608 [MethodImplAttribute (MethodImplOptions.NoInlining)]
609 public static void vtypes3 (AStruct s) {
610 AStruct.static_foo (5);
613 [MethodImplAttribute (MethodImplOptions.NoInlining)]
614 public static void locals () {
616 var astruct = new AStruct () { i = 42 };
618 locals2<string> (null, 5, "ABC", ref s, ref astruct);
624 [MethodImplAttribute (MethodImplOptions.NoInlining)]
625 static void locals11 (double a, ref double b) {
628 [MethodImplAttribute (MethodImplOptions.NoInlining)]
629 public static void locals1 (string[] args) {
633 locals11 (b: ref ri, a: ri);
635 for (int j = 0; j < 10; ++j) {
640 [MethodImplAttribute (MethodImplOptions.NoInlining)]
642 [StateMachine (typeof (int))]
644 public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
648 for (int j = 0; j < 10; ++j) {
653 astruct = new AStruct ();
659 [MethodImplAttribute (MethodImplOptions.NoInlining)]
660 public static void locals3 () {
680 [MethodImplAttribute (MethodImplOptions.NoInlining)]
681 public static void locals4 () {
684 [MethodImplAttribute (MethodImplOptions.NoInlining)]
685 public static void locals5 () {
688 [MethodImplAttribute (MethodImplOptions.NoInlining)]
689 public static void locals6 () {
692 for (i = 0; i < 10; ++i)
695 for (i = 0; i < 10; ++i)
705 [MethodImplAttribute (MethodImplOptions.NoInlining)]
706 public static void locals6_1 () {
709 [MethodImplAttribute (MethodImplOptions.NoInlining)]
710 public static void locals6_2 (int arg) {
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)
719 for (j = 0; j < 100; ++j)
721 for (k = 0; k < 100; ++k)
723 for (l = 0; l < 100; ++l)
725 for (m = 0; m < 100; ++m)
729 [MethodImplAttribute (MethodImplOptions.NoInlining)]
730 public static void locals6_4 (int arg) {
733 [MethodImplAttribute (MethodImplOptions.NoInlining)]
734 public static void locals6_5 () {
737 [MethodImplAttribute (MethodImplOptions.NoInlining)]
738 public static void locals6_6 (int arg) {
741 [MethodImplAttribute (MethodImplOptions.NoInlining)]
742 public static void locals7<T> (T arg) {
747 [MethodImplAttribute (MethodImplOptions.NoInlining)]
748 public static void line_numbers () {
752 [MethodImplAttribute (MethodImplOptions.NoInlining)]
753 public static void suspend () {
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" });
767 AStruct s = new AStruct () { i = 42, s = "S", k = 43 };
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);
773 [MethodImplAttribute (MethodImplOptions.NoInlining)]
774 public object ti1 (Tests2 t, GClass <int> gc1, GClass <string> gc2) {
775 if (t == null || gc1 == null || gc2 == null)
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];
786 [MethodImplAttribute (MethodImplOptions.NoInlining)]
787 public static void assembly_load () {
791 [MethodImplAttribute (MethodImplOptions.NoInlining)]
792 public static void assembly_load_2 () {
793 // This will load System.dll while holding the loader lock
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 ();
803 [MethodImplAttribute (MethodImplOptions.NoInlining)]
804 public void invoke1 (Tests2 t, AStruct s, GStruct<int> g) {
808 [MethodImplAttribute (MethodImplOptions.NoInlining)]
809 public void invoke2 () {
812 [MethodImplAttribute (MethodImplOptions.NoInlining)]
813 public void invoke_ex () {
817 [MethodImplAttribute (MethodImplOptions.NoInlining)]
818 public void invoke_ex_inner () {
820 throw new Exception ();
827 [MethodImplAttribute (MethodImplOptions.NoInlining)]
828 public void invoke_single_threaded () {
829 // Spawn a thread incrementing a counter
830 bool finished = false;
832 new Thread (delegate () {
839 invoke_single_threaded_2 ();
844 [MethodImplAttribute (MethodImplOptions.NoInlining)]
845 public void invoke_single_threaded_2 () {
848 public void invoke_return_void () {
851 public string invoke_return_ref () {
855 public object invoke_return_null () {
859 public int invoke_return_primitive () {
863 public int? invoke_return_nullable () {
867 public int? invoke_return_nullable_null () {
871 public void invoke_type_load () {
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;
882 public int invoke_pass_primitive2 (bool b) {
886 public string invoke_pass_ref (string s) {
890 public static string invoke_static_pass_ref (string s) {
894 public static void invoke_static_return_void () {
897 public static void invoke_throws () {
898 throw new Exception ();
901 public int invoke_iface () {
905 [MethodImplAttribute (MethodImplOptions.NoInlining)]
906 public static void exceptions () {
908 throw new OverflowException ();
909 } catch (Exception) {
912 throw new OverflowException ();
913 } catch (Exception) {
916 throw new ArgumentException ();
917 } catch (Exception) {
920 throw new OverflowException ();
921 } catch (Exception) {
925 throw new OverflowException ();
926 } catch (Exception) {
929 throw new Exception ();
930 } catch (Exception) {
936 } catch (Exception) {
941 } catch (Exception) {
945 [MethodImplAttribute (MethodImplOptions.NoInlining)]
946 public static void unhandled_exception () {
947 ThreadPool.QueueUserWorkItem (delegate {
948 throw new InvalidOperationException ();
950 Thread.Sleep (10000);
953 [MethodImplAttribute (MethodImplOptions.NoInlining)]
954 public static void unhandled_exception_endinvoke_2 () {
957 [MethodImplAttribute (MethodImplOptions.NoInlining)]
958 public static void unhandled_exception_endinvoke () {
959 Action action = new Action (() =>
961 throw new Exception ("thrown");
963 action.BeginInvoke ((ar) => {
965 action.EndInvoke (ar);
966 } catch (Exception ex) {
967 //Console.WriteLine (ex);
971 unhandled_exception_endinvoke_2 ();
974 [MethodImplAttribute (MethodImplOptions.NoInlining)]
975 public static void unhandled_exception_user () {
977 System.Threading.Tasks.Task.Factory.StartNew (() => {
980 Thread.Sleep (10000);
984 [MethodImplAttribute (MethodImplOptions.NoInlining)]
985 public static void Throw () {
986 throw new Exception ();
989 internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
992 throw new ArgumentNullException ();
993 if (dlg.Target != null)
994 throw new ArgumentException ();
995 if (dlg.Method == null)
996 throw new ArgumentException ();
998 var ret_type = dlg.Method.ReturnType;
999 var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
1001 var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
1002 var ig = dynamic.GetILGenerator ();
1004 LocalBuilder retval = null;
1005 if (ret_type != typeof (void))
1006 retval = ig.DeclareLocal (ret_type);
1008 var label = ig.BeginExceptionBlock ();
1010 for (int i = 0; i < param_types.Length; i++)
1011 ig.Emit (OpCodes.Ldarg, i);
1012 ig.Emit (OpCodes.Call, dlg.Method);
1015 ig.Emit (OpCodes.Stloc, retval);
1017 ig.Emit (OpCodes.Leave, label);
1019 ig.BeginExceptFilterBlock ();
1021 ig.Emit (OpCodes.Call, filter_method);
1023 ig.BeginCatchBlock (null);
1025 ig.Emit (OpCodes.Pop);
1027 ig.EndExceptionBlock ();
1030 ig.Emit (OpCodes.Ldloc, retval);
1032 ig.Emit (OpCodes.Ret);
1034 return dynamic.CreateDelegate (dlg.GetType ());
1037 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1038 static void exception_filter_method () {
1039 throw new InvalidOperationException ();
1042 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1043 static int exception_filter_filter (Exception exc) {
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);
1054 var dlg = Delegate.CreateDelegate (typeof (Action), method);
1056 var wrapper = (Action) create_filter_delegate (dlg, filter_method);
1061 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1062 public static bool return_true () {
1066 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1067 public static void exceptions2 () {
1069 throw new Exception ();
1070 Console.WriteLine ();
1073 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1074 public static void threads () {
1075 Thread t = new Thread (delegate () {});
1081 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1082 public static void domains () {
1083 AppDomain domain = AppDomain.CreateDomain ("domain");
1085 CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
1086 typeof (CrossDomain).Assembly.FullName, "CrossDomain");
1088 domains_2 (o, new CrossDomain ());
1096 AppDomain.Unload (domain);
1101 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1102 public static void domains_2 (object o, object o2) {
1105 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1106 public static void domains_3 () {
1109 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1110 public static void invoke_in_domain () {
1113 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1114 public static void invoke_in_domain_2 () {
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 ();
1122 ig.Emit (OpCodes.Ldstr, "FOO");
1123 ig.Emit (OpCodes.Call, typeof (Tests).GetMethod ("dyn_call"));
1124 ig.Emit (OpCodes.Ret);
1126 var del = (Action<int>)m.CreateDelegate (typeof (Action<int>));
1131 public static void dyn_call (string s) {
1134 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1135 public static void ref_emit () {
1136 AssemblyName assemblyName = new AssemblyName ();
1137 assemblyName.Name = "foo";
1139 AssemblyBuilder assembly =
1140 Thread.GetDomain ().DefineDynamicAssembly (
1141 assemblyName, AssemblyBuilderAccess.RunAndSave);
1143 ModuleBuilder module = assembly.DefineDynamicModule ("foo.dll");
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);
1152 Type t = tb.CreateType ();
1154 t.GetMethod ("ref_emit_method").Invoke (null, null);
1157 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1158 public static void ref_emit_call (string s) {
1161 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1162 public static void frames_in_native () {
1164 var evt = new ManualResetEvent (false);
1166 object mon = new object ();
1167 ThreadPool.QueueUserWorkItem (delegate {
1168 frames_in_native_2 ();
1174 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1175 static void frames_in_native_2 () {
1176 frames_in_native_3 ();
1179 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1180 static void frames_in_native_3 () {
1183 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1184 public static void string_call (string s) {
1187 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1188 public static void ss_regress_654694 () {
1195 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1196 public static void user () {
1199 Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
1202 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1203 public static void type_load () {
1207 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1208 static void type_load_2 () {
1209 var c1 = new Dictionary<int, int> ();
1211 var c = new TypeLoadClass ();
1213 var c2 = new TypeLoadClass2 ();
1217 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1218 public static void regress () {
1219 regress_2755 (DateTime.Now);
1222 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1223 public static unsafe void regress_2755 (DateTime d) {
1224 int* buffer = stackalloc int [128];
1229 for (int i = 0; i < 128; ++i)
1232 regress_2755_3 (sum);
1235 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1236 public static void regress_2755_2 () {
1239 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1240 public static void regress_2755_3 (int sum) {
1243 static object gc_suspend_field;
1245 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1246 static unsafe void set_gc_suspend_field () {
1247 set_gc_suspend_field_2 ();
1249 int* buffer = stackalloc int [4096];
1252 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1253 static void set_gc_suspend_field_2 () {
1254 gc_suspend_field = new object ();
1257 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1258 static void gc_suspend_1 () {
1261 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1262 public static void gc_suspend_invoke () {
1263 gc_suspend_field = null;
1265 GC.WaitForPendingFinalizers ();
1268 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1269 public static void gc_suspend () {
1270 set_gc_suspend_field ();
1274 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1275 public static void generic_method<T> () where T : class {
1279 class TypeLoadClass {
1282 class TypeLoadClass2 {
1285 public class CrossDomain : MarshalByRefObject
1287 public void invoke () {
1288 Tests.invoke_in_domain ();
1291 public void invoke_2 () {
1292 Tests.invoke_in_domain_2 ();
1295 public int invoke_3 () {
1302 public ProcessStartInfo info;
1305 // Class used for line number info testing, don't change its layout
1306 public class LineNumbers
1308 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1309 public static void ln1 () {
1315 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1316 public static void ln2 () {
1319 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1320 public static void ln3 () {
1321 #pragma warning disable 0219
1323 #pragma warning restore 0219