Merge pull request #4938 from kumpera/optimize_ref_queries
[mono.git] / mono / tests / gc-oom-handling2.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Reflection;
4
5
6 class Driver {
7         /*Test that GC handles interning failure correctly*/
8         static void DumpStuff () {
9                 Console.WriteLine ("CWL under OOM - should not print {0}", 99);
10                 Console.WriteLine ("CWL under OOM - should not print {0}{1}", 22, 44.4);
11         }
12
13         static int Main () {
14                 Console.WriteLine ("start");
15                 Assembly corlib = typeof (object).Assembly;
16                 Module module = corlib.GetModules ()[0];
17                 var r = new Random (123456);
18                 var l = new List<object> ();
19                 try {
20                         for (int i = 0; i < 400000; ++i) {
21                                 var foo = new byte[r.Next () % 4000];
22                                 l.Add (foo);
23                         }
24                         Console.WriteLine ("done");
25                         return 1;
26                 } catch (Exception) {
27                         try {
28                                 DumpStuff ();
29                                 return 2;
30                         } catch (Exception) {}
31
32                         try {
33                                 module.GetTypes ();
34                                 return 3;
35                         } catch (Exception) {}
36
37                         try {
38                                 corlib.GetTypes ();
39                                 return 4;
40                         } catch (Exception) {}
41         
42
43                         l.Clear ();
44                         l = null;
45                         Console.WriteLine ("OOM done");
46                 }
47                 return 0;
48         }
49 }
50