Merge pull request #4178 from ntherning/fix-broken-windows-build
[mono-project.git] / mono / tests / sgen-cementing-stress.cs
blob33c0bfa5bef4326432e2c9598e656956670df4ea
1 using System;
3 class PinList
5 class Pinned
7 public Pinned ()
12 Pinned reference;
13 PinList next;
15 PinList (PinList n)
17 next = n;
20 static PinList MakeList (int length)
22 PinList l = null;
23 for (int i = 0; i < length; ++i)
24 l = new PinList (l);
25 return l;
28 static void AssignReferences (PinList l, Pinned[] objs)
30 int i = 0;
31 int n = objs.Length;
32 while (l != null)
34 l.reference = objs [i++ % n];
35 l = l.next;
39 static Pinned Work (PinList list, Pinned[] objs, int i)
41 if (i >= objs.Length)
43 for (int j = 0; j < 10; ++j)
45 MakeList (1 << 19);
46 AssignReferences (list, objs);
48 return null;
50 else
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
59 static void Benchmark (PinList list, int n)
61 Pinned[] objs = new Pinned [n];
62 Work (list, objs, 0);
65 public static void Main ()
67 PinList list = MakeList (1 << 24);
68 Console.WriteLine ("long list constructed");
69 Benchmark (list, 10);
70 GC.Collect (1);
71 Benchmark (list, 100);