Convert MonoGenericContainer/Param accessor macros to inline functions
[mono.git] / mono / tests / sgen-bridge-major-fragmentation.cs
1 using System;
2 using System.Threading;
3
4 //64 / 128 size
5 public class NonBridge {
6         public object a,b,c,d,e,f,g,h,i,j,k,l,m,n;
7 }
8
9 public class Bridge {
10         public object a,b,c,d,e,f,g,h,i,j,k,l,m,n;
11         
12         ~Bridge () {}
13 }
14
15 class Driver {
16         //we fill 16Mb worth of stuff, eg, 256k objects
17         const int major_fill = 1024 * 256;
18
19         //4mb nursery with 64 bytes objects -> alloc half
20         const int nursery_obj_count = 16 * 1024;
21
22         static void CrashMainLoop () {
23                 var arr = new object [major_fill];
24                 for (int i = 0; i < major_fill; ++i)
25                         arr [i] = new NonBridge ();
26                 GC.Collect (1);
27                 Console.WriteLine ("major fill done");
28
29                 //induce massive fragmentation
30                 for (int i = 0; i < major_fill; i += 4) {
31                         arr [i + 1] = null;
32                         arr [i + 2] = null;
33                         arr [i + 3] = null;
34                 }
35                 GC.Collect (1);
36                 Console.WriteLine ("fragmentation done");
37
38                 //since 50% is garbage, do 2 fill passes
39                 for (int j = 0; j < 2; ++j) {
40                         for (int i = 0; i < major_fill; ++i) {
41                                 if ((i % 1000) == 0)
42                                         new Bridge ();
43                                 else
44                                         arr [i] = new Bridge ();
45                         }
46                 }
47                 Console.WriteLine ("done spewing bridges");
48                 
49                 for (int i = 0; i < major_fill; ++i)
50                         arr [i] = null;
51                 GC.Collect ();
52         }
53         
54
55         static void Main () {
56                 const int loops = 4;
57                 for (int i = 0; i < loops; ++i) {
58                         Console.WriteLine ("CrashLoop {0}/{1}", i + 1, loops);
59                         CrashMainLoop ();
60                 }
61                 Console.WriteLine ("done");
62                 GC.Collect ();
63                 GC.WaitForPendingFinalizers ();
64                 GC.Collect ();
65                 GC.WaitForPendingFinalizers ();
66         }
67 }