Merge pull request #5082 from kumpera/fix-ro-fs-file-delete
[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 int list_size = 0;
21
22     static PinList MakeList (int length)
23     {
24         PinList l = null;
25         for (int i = 0; i < length; ++i)
26             l = new PinList (l);
27         return l;
28     }
29
30     static void AssignReferences (PinList l, Pinned[] objs)
31     {
32         int i = 0;
33         int n = objs.Length;
34         while (l != null)
35         {
36             l.reference = objs [i++ % n];
37             l = l.next;
38         }
39     }
40
41     static Pinned Work (PinList list, Pinned[] objs, int i)
42     {
43         if (i >= objs.Length)
44         {
45             for (int j = 0; j < 10; ++j)
46             {
47                 MakeList (list_size >> 5);
48                 AssignReferences (list, objs);
49             }
50             return null;
51         }
52         else
53         {
54             Pinned obj = new Pinned ();
55             objs [i] = obj;
56             Pinned dummy = Work (list, objs, i + 1);
57             return obj != dummy ? obj : dummy; // to keep obj alive
58         }
59     }
60
61     static void Benchmark (PinList list, int n)
62     {
63         Pinned[] objs = new Pinned [n];
64         Work (list, objs, 0);
65     }
66
67     public static void Main ()
68     {
69         list_size = 1 << 15;
70         TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 5));
71
72         for (int it1 = 1; it1 <= 10; it1++, list_size <<= 1) {
73                 PinList list = MakeList (list_size);
74                 Console.WriteLine ("long list constructed {0}", it1);
75                 for (int it2 = 0; it2 < 5; it2++) {
76                         Benchmark (list, 10 * it1);
77                         GC.Collect (1);
78
79                         if (!timeout.HaveTimeLeft)
80                                 return;
81                 }
82         }
83     }
84 }