[msvc] Update csproj files
[mono.git] / mono / tests / sgen-cementing-stress.cs
1 using System;
2
3 class PinList
4 {
5     class Pinned
6     {
7         public Pinned ()
8         {
9         }
10     }
11
12     Pinned reference;
13     PinList next;
14
15     PinList (PinList n)
16     {
17         next = n;
18     }
19
20     static PinList MakeList (int length)
21     {
22         PinList l = null;
23         for (int i = 0; i < length; ++i)
24             l = new PinList (l);
25         return l;
26     }
27
28     static void AssignReferences (PinList l, Pinned[] objs)
29     {
30         int i = 0;
31         int n = objs.Length;
32         while (l != null)
33         {
34             l.reference = objs [i++ % n];
35             l = l.next;
36         }
37     }
38
39     static Pinned Work (PinList list, Pinned[] objs, int i)
40     {
41         if (i >= objs.Length)
42         {
43             for (int j = 0; j < 10; ++j)
44             {
45                 MakeList (1 << 19);
46                 AssignReferences (list, objs);
47             }
48             return null;
49         }
50         else
51         {
52             Pinned obj = new Pinned ();
53             objs [i] = obj;
54             Pinned dummy = Work (list, objs, i + 1);
55             return obj != dummy ? obj : dummy; // to keep obj alive
56         }
57     }
58
59     static void Benchmark (PinList list, int n)
60     {
61         Pinned[] objs = new Pinned [n];
62         Work (list, objs, 0);
63     }
64
65     public static void Main ()
66     {
67         PinList list = MakeList (1 << 24);
68         Console.WriteLine ("long list constructed");
69         Benchmark (list, 10);
70         GC.Collect (1);
71         Benchmark (list, 100);
72     }
73 }