Merge pull request #205 from m3rlinez/master
[mono.git] / mono / tests / sgen-descriptors.cs
1 using System;
2
3 public struct SmallMixed
4 {
5         public int a;
6         public object b;
7         public int c;
8         public object d;
9 }
10
11 public struct LargeMixed {
12         public SmallMixed a,b,c,d,e;
13 }
14
15 public class SmallBitMap {
16         public SmallMixed a;
17 }
18
19 public class LargeBitMap {
20         public SmallMixed a;
21         public long b,c,d,e,f,g,h;
22         public SmallMixed k;
23 }
24
25 public class ComplexBitMap {
26         public SmallMixed a,b,c,d,e,f,g,h,i,j,k,l;
27 }
28
29 public class PtrFree {
30         public int a,b,c,d;
31 }
32
33 public struct LargeStruct {
34         public long a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15;
35 }
36
37 public struct LargeStruct2 {
38         public LargeStruct a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15;
39 }
40
41 public struct LargeStruct3 {
42         public LargeStruct2 a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15;
43 }
44
45 public class HugePtrFree {
46         public LargeStruct3 a,b;
47         public LargeStruct2 c;
48 }
49
50 /*
51 This is a stress test for descriptors.
52 */
53 class Driver {
54         static char[] FOO = new char[] { 'f', 'o', 'b' };
55
56         static void Fill (int cycles) {
57                 object[] root = new object [12];
58                 object[] current = root;
59                 for (int i = 0; i < cycles; ++i) {
60                         current [0] = new object [12];
61                         current [1] = new int [6];
62                         current [2] = new int [2,3];
63                         current [3] = new string (FOO);
64                         current [4] = new SmallBitMap ();
65                         current [5] = new LargeBitMap ();
66                         current [6] = new ComplexBitMap ();
67                         current [7] = new PtrFree ();
68                         current [8] = new SmallMixed [3];
69                         current [9] = new LargeMixed [3];
70
71                         if ((i % 50000) == 0)
72                                 current [10] = new HugePtrFree ();
73                         if ((i %  10000) == 0)
74                                 current [11] = new LargeStruct2 [1];
75         
76                         current = (object[])current [0];
77                 }
78         }
79
80         static void Main () {
81                 int loops = 3;
82                 int cycles = 200000;
83                 for (int i = 0; i < loops; ++i) {
84                         Fill (cycles);
85                 }
86         }
87 }