Created
November 18, 2019 16:15
-
-
Save BrzVlad/1277d6c47726295b21d6c469ad9b2a2d to your computer and use it in GitHub Desktop.
GC Prototype testcase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple testcase for verifying basic GC functionality | |
// (allocation, collection, root scanning, object scanning, write barriers) | |
using System; | |
using System.Collections.Generic; | |
public class Program { | |
public string s; | |
public static List<Program> list = new List<Program> (); | |
public static int Main (string[] args) | |
{ | |
const int N = 300000; | |
// Allocate many objects | |
for (int i = 0; i < N; i++) { | |
Program p = new Program (); | |
p.s = "Hello World"; | |
list.Add (p); | |
} | |
Console.WriteLine ("Hello World"); | |
GC.Collect (); | |
// Replace some references, dirty some cards | |
for (int i = N / 2; i < N; i++) | |
list [i].s = new string ("Hello World2"); | |
GC.Collect (); | |
// Make sure everything is still OK | |
for (int i = 0; i < N / 2; i++) { | |
if (list [i].s != "Hello World") { | |
Console.WriteLine ("Hello World != {0}", list [i].s); | |
return 1; | |
} | |
} | |
for (int i = N / 2; i < N; i++) { | |
if (list [i].s != "Hello World2") { | |
Console.WriteLine ("Hello World2 != {0}", list [i].s); | |
return 2; | |
} | |
} | |
Console.WriteLine ("Hello world OK"); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment