Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. using System;
  2. public class Program {
  3. string str = "str";
  4. /* Nursery size 4 000 000 000 */
  5. public const int NURSERY_SIZE = 4000000;
  6. public const int SIZEOF_OBJECT = 24;
  7. public const int NUM_ELEMENTS = (NURSERY_SIZE * 2 / 3)/ SIZEOF_OBJECT;
  8. public static void Main (string[] args)
  9. {
  10. /* Array in major heap */
  11. Program[] array = new Program [NUM_ELEMENTS * 2];
  12. /* Fill nursery with objects, we have wbarriers for half the array */
  13. for (int i = 0; i < NUM_ELEMENTS; i++)
  14. array [i] = new Program ();
  15. /* We reverse array, the other half of the array will have missing remsets due to bug */
  16. Array.Reverse (array);
  17. /* We promote all objects, gc will fail to update refs for half the array */
  18. GC.Collect (0);
  19. /* Clear the nursery */
  20. for (int i = 0; i < NURSERY_SIZE; i++)
  21. new object ();
  22. /* Half of the references in the array will be junk, crash here */
  23. for (int i = NUM_ELEMENTS; i < (NUM_ELEMENTS * 2); i++) {
  24. if (!string.Equals (array [i].str, "str")) {
  25. Console.WriteLine ("We have a junk object, str {0}", array [i].str);
  26. break;
  27. }
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement