PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mono/tests/gc-oom-handling2.cs

https://bitbucket.org/danipen/mono
C# | 50 lines | 41 code | 8 blank | 1 comment | 1 complexity | 6e859ce937dcacb391b5dd23be1cb889 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. class Driver {
  5. /*Test that GC handles interning failure correctly*/
  6. static void DumpStuff () {
  7. Console.WriteLine ("CWL under OOM - should not print {0}", 99);
  8. Console.WriteLine ("CWL under OOM - should not print {0}{1}", 22, 44.4);
  9. }
  10. static int Main () {
  11. Console.WriteLine ("start");
  12. Assembly corlib = typeof (object).Assembly;
  13. Module module = corlib.GetModules ()[0];
  14. var r = new Random (123456);
  15. var l = new List<object> ();
  16. try {
  17. for (int i = 0; i < 400000; ++i) {
  18. var foo = new byte[r.Next () % 4000];
  19. l.Add (foo);
  20. }
  21. Console.WriteLine ("done");
  22. return 1;
  23. } catch (Exception) {
  24. try {
  25. DumpStuff ();
  26. return 2;
  27. } catch (Exception) {}
  28. try {
  29. module.GetTypes ();
  30. return 3;
  31. } catch (Exception) {}
  32. try {
  33. corlib.GetTypes ();
  34. return 4;
  35. } catch (Exception) {}
  36. l.Clear ();
  37. l = null;
  38. Console.WriteLine ("OOM done");
  39. }
  40. return 0;
  41. }
  42. }