2 using System.Reflection;
3 using System.Runtime.CompilerServices;
4 using System.Collections;
7 * Regression tests for the GC support in the JIT
13 return TestDriver.RunTests (typeof (Tests));
16 public static int test_36_simple () {
17 // Overflow the registers
27 /* Prevent the variables from being local to a bb */
32 return (int)o1 + (int)o2 + (int)o3 + (int)o4 + (int)o5 + (int)o6 + (int)o7 + (int)o8;
37 public static int test_36_liveness () {
39 object o1, o2, o3, o4, o5, o6, o7, o8;
55 return (int)o1 + (int)o2 + (int)o3 + (int)o4 + (int)o5 + (int)o6 + (int)o7 + (int)o8;
65 public FooStruct (int i1, int i, int i2) {
72 public static int test_4_vtype () {
73 FooStruct s = new FooStruct (1, 2, 3);
77 return (int)s.o1 + (int)s.o2;
81 public object o1, o2, o3, o4, o5, o6, o7, o8, o9, o10;
82 public object o11, o12, o13, o14, o15, o16, o17, o18, o19, o20;
83 public object o21, o22, o23, o24, o25, o26, o27, o28, o29, o30;
84 public object o31, o32;
87 static void set_fields (BigClass b) {
123 // Test marking of objects with > 32 fields
124 public static int test_528_mark_runlength_large () {
125 BigClass b = new BigClass ();
128 * Do the initialization in a separate method so no object refs remain in
136 (int)b.o1 + (int)b.o2 + (int)b.o3 + (int)b.o4 + (int)b.o5 +
137 (int)b.o6 + (int)b.o7 + (int)b.o8 + (int)b.o9 + (int)b.o10 +
138 (int)b.o11 + (int)b.o12 + (int)b.o13 + (int)b.o14 + (int)b.o15 +
139 (int)b.o16 + (int)b.o17 + (int)b.o18 + (int)b.o19 + (int)b.o20 +
140 (int)b.o21 + (int)b.o22 + (int)b.o23 + (int)b.o24 + (int)b.o25 +
141 (int)b.o26 + (int)b.o27 + (int)b.o28 + (int)b.o29 + (int)b.o30 +
142 (int)b.o31 + (int)b.o32;
146 * Test liveness and loops.
148 public static int test_0_liveness_2 () {
149 object o = new object ();
150 for (int n = 0; n < 10; ++n) {
151 /* Exhaust all registers so 'o' is stack allocated */
152 int sum = 0, i, j, k, l, m;
153 for (i = 0; i < 100; ++i)
155 for (j = 0; j < 100; ++j)
157 for (k = 0; k < 100; ++k)
159 for (l = 0; l < 100; ++l)
161 for (m = 0; m < 100; ++m)
181 * Test liveness and stack slot sharing
182 * This doesn't work yet, its hard to make the JIT share the stack slots of the
185 public static int test_0_liveness_3 () {
189 /* Exhaust all registers so 'o' is stack allocated */
190 int sum = 0, i, j, k, l, m, n, s;
191 for (i = 0; i < 100; ++i)
193 for (j = 0; j < 100; ++j)
195 for (k = 0; k < 100; ++k)
197 for (l = 0; l < 100; ++l)
199 for (m = 0; m < 100; ++m)
201 for (n = 0; n < 100; ++n)
203 for (s = 0; s < 100; ++s)
207 object o = new object ();
209 /* Make sure o is global */
211 Console.WriteLine ();
219 object o = new object ();
221 /* Make sure o is global */
223 Console.WriteLine ();
228 sum += i + j + k + l + m + n + s;
234 * Test liveness of variables used to handle items on the IL stack.
236 [MethodImplAttribute (MethodImplOptions.NoInlining)]
237 static string call1 () {
241 [MethodImplAttribute (MethodImplOptions.NoInlining)]
242 static string call2 () {
247 public static int test_0_liveness_4 () {
251 /* Exhaust all registers so 'o' is stack allocated */
252 int sum = 0, i, j, k, l, m, n, s;
253 for (i = 0; i < 100; ++i)
255 for (j = 0; j < 100; ++j)
257 for (k = 0; k < 100; ++k)
259 for (l = 0; l < 100; ++l)
261 for (m = 0; m < 100; ++m)
263 for (n = 0; n < 100; ++n)
265 for (s = 0; s < 100; ++s)
268 string o = b ? call1 () : call2 ();
272 sum += i + j + k + l + m + n + s;
279 * Test liveness of volatile variables
281 [MethodImplAttribute (MethodImplOptions.NoInlining)]
282 static void liveness_5_1 (out object o) {
286 public static int test_0_liveness_5 () {
290 /* Exhaust all registers so 'o' is stack allocated */
291 int sum = 0, i, j, k, l, m, n, s;
292 for (i = 0; i < 100; ++i)
294 for (j = 0; j < 100; ++j)
296 for (k = 0; k < 100; ++k)
298 for (l = 0; l < 100; ++l)
300 for (m = 0; m < 100; ++m)
302 for (n = 0; n < 100; ++n)
304 for (s = 0; s < 100; ++s)
309 liveness_5_1 (out o);
311 for (int x = 0; x < 10; ++x) {
318 sum += i + j + k + l + m + n + s;
324 * Test the case when a stack slot becomes dead, then live again due to a backward
328 [MethodImplAttribute (MethodImplOptions.NoInlining)]
329 static object alloc_obj () {
330 return new object ();
333 [MethodImplAttribute (MethodImplOptions.NoInlining)]
334 static bool return_true () {
338 [MethodImplAttribute (MethodImplOptions.NoInlining)]
339 static bool return_false () {
343 public static int test_0_liveness_6 () {
347 /* Exhaust all registers so 'o' is stack allocated */
348 int sum = 0, i, j, k, l, m, n, s;
349 for (i = 0; i < 100; ++i)
351 for (j = 0; j < 100; ++j)
353 for (k = 0; k < 100; ++k)
355 for (l = 0; l < 100; ++l)
357 for (m = 0; m < 100; ++m)
359 for (n = 0; n < 100; ++n)
361 for (s = 0; s < 100; ++s)
364 for (int x = 0; x < 10; ++x) {
368 object o = alloc_obj ();
375 sum += i + j + k + l + m + n + s;
380 public static int test_0_multi_dim_ref_array_wbarrier () {
381 string [,] arr = new string [256, 256];
382 for (int i = 0; i < 256; ++i) {
383 for (int j = 0; j < 100; ++j)
384 arr [i, j] = "" + i + " " + j;
392 * Liveness + out of line bblocks
394 public static int test_0_liveness_7 () {
395 /* Exhaust all registers so 'o' is stack allocated */
396 int sum = 0, i, j, k, l, m, n, s;
397 for (i = 0; i < 100; ++i)
399 for (j = 0; j < 100; ++j)
401 for (k = 0; k < 100; ++k)
403 for (l = 0; l < 100; ++l)
405 for (m = 0; m < 100; ++m)
407 for (n = 0; n < 100; ++n)
409 for (s = 0; s < 100; ++s)
415 if (return_false ()) {
416 // This bblock is in-line
417 object o = alloc_obj ();
419 if (return_false ()) {
420 // This bblock is out-of-line, and o is live here
421 throw new Exception (o.ToString ());
425 // o is dead here too
431 // Liveness + finally clauses
432 public static int test_0_liveness_8 () {
433 /* Exhaust all registers so 'o' is stack allocated */
434 int sum = 0, i, j, k, l, m, n, s;
435 for (i = 0; i < 100; ++i)
437 for (j = 0; j < 100; ++j)
439 for (k = 0; k < 100; ++k)
441 for (l = 0; l < 100; ++l)
443 for (m = 0; m < 100; ++m)
445 for (n = 0; n < 100; ++n)
447 for (s = 0; s < 100; ++s)
461 [MethodImplAttribute (MethodImplOptions.NoInlining)]
462 static object alloc_string () {
466 [MethodImplAttribute (MethodImplOptions.NoInlining)]
467 static object alloc_obj_and_gc () {
469 return new object ();
472 [MethodImplAttribute (MethodImplOptions.NoInlining)]
473 static void clobber_regs_and_gc () {
474 int sum = 0, i, j, k, l, m, n, s;
475 for (i = 0; i < 100; ++i)
477 for (j = 0; j < 100; ++j)
479 for (k = 0; k < 100; ++k)
481 for (l = 0; l < 100; ++l)
483 for (m = 0; m < 100; ++m)
485 for (n = 0; n < 100; ++n)
487 for (s = 0; s < 100; ++s)
492 [MethodImplAttribute (MethodImplOptions.NoInlining)]
493 static void liveness_9_call1 (object o1, object o2, object o3) {
499 // Liveness + JIT temporaries
500 public static int test_0_liveness_9 () {
501 // the result of alloc_obj () goes into a vreg, which gets converted to a
502 // JIT temporary because of the branching introduced by the cast
503 // FIXME: This doesn't crash if MONO_TYPE_I is not treated as a GC ref
504 liveness_9_call1 (alloc_obj (), (string)alloc_string (), alloc_obj_and_gc ());
508 // Liveness for registers
509 public static int test_0_liveness_10 () {
510 // Make sure this goes into a register
511 object o = alloc_obj ();
518 // Break the bblock so o doesn't become a local vreg
520 // Clobber it with a call and run a GC
521 clobber_regs_and_gc ();
527 // Liveness for spill slots holding managed pointers
528 public static int test_0_liveness_11 () {
529 Tests[] arr = new Tests [10];
530 // This uses an ldelema internally
531 // FIXME: This doesn't crash if mp-s are not correctly tracked, just writes to
538 public static Tests operator >> (Tests bi1, int shiftVal) {
539 clobber_regs_and_gc ();
543 [MethodImplAttribute (MethodImplOptions.NoInlining)]
544 public static void liveness_12_inner (int a, int b, int c, int d, int e, int f, object o) {
549 // Liveness for param area
550 public static int test_0_liveness_12 () {
551 // The ref argument should be passed on the stack
552 liveness_12_inner (1, 2, 3, 4, 5, 6, new object ());
556 public static void liveness_13_inner (ref ArrayList arr) {
557 // The value of arr will be stored in a spill slot
558 arr.Add (alloc_obj_and_gc ());
561 // Liveness for byref arguments in spill slots
562 public static int test_0_liveness_13 () {
563 var arr = new ArrayList ();
564 liveness_13_inner (ref arr);