PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/rpython/memory/gc/test/test_minimark.py

https://bitbucket.org/alex_gaynor/pypy-postgresql/
Python | 69 lines | 58 code | 5 blank | 6 comment | 1 complexity | c25835848158741019058a368bf28cf0 MD5 | raw file
  1. from pypy.rpython.lltypesystem import llmemory
  2. from pypy.rpython.memory.gc.minimark import MiniMarkGC
  3. from pypy.rlib.rarithmetic import LONG_BIT
  4. # Note that most tests are in test_direct.py.
  5. def test_card_marking_words_for_length():
  6. gc = MiniMarkGC(None, card_page_indices=128)
  7. assert gc.card_page_shift == 7
  8. P = 128 * LONG_BIT
  9. assert gc.card_marking_words_for_length(1) == 1
  10. assert gc.card_marking_words_for_length(P) == 1
  11. assert gc.card_marking_words_for_length(P+1) == 2
  12. assert gc.card_marking_words_for_length(P+P) == 2
  13. assert gc.card_marking_words_for_length(P+P+1) == 3
  14. assert gc.card_marking_words_for_length(P+P+P+P+P+P+P+P) == 8
  15. assert gc.card_marking_words_for_length(P+P+P+P+P+P+P+P+1) == 9
  16. def test_card_marking_bytes_for_length():
  17. gc = MiniMarkGC(None, card_page_indices=128)
  18. assert gc.card_page_shift == 7
  19. P = 128 * 8
  20. assert gc.card_marking_bytes_for_length(1) == 1
  21. assert gc.card_marking_bytes_for_length(P) == 1
  22. assert gc.card_marking_bytes_for_length(P+1) == 2
  23. assert gc.card_marking_bytes_for_length(P+P) == 2
  24. assert gc.card_marking_bytes_for_length(P+P+1) == 3
  25. assert gc.card_marking_bytes_for_length(P+P+P+P+P+P+P+P) == 8
  26. assert gc.card_marking_bytes_for_length(P+P+P+P+P+P+P+P+1) == 9
  27. def test_set_major_threshold():
  28. gc = MiniMarkGC(None, major_collection_threshold=2.0,
  29. growth_rate_max=1.5)
  30. gc.min_heap_size = 100.0
  31. gc.max_heap_size = 300.0
  32. gc.next_major_collection_threshold = 0.0
  33. # first, we don't grow past min_heap_size
  34. for i in range(5):
  35. gc.set_major_threshold_from(100.0)
  36. assert gc.next_major_collection_threshold == 100.0
  37. # then we grow a lot
  38. b = gc.set_major_threshold_from(100 * 2.0)
  39. assert b is False
  40. assert gc.next_major_collection_threshold == 150.0
  41. b = gc.set_major_threshold_from(150 * 2.0)
  42. assert b is False
  43. assert gc.next_major_collection_threshold == 225.0
  44. b = gc.set_major_threshold_from(225 * 2.0)
  45. assert b is True
  46. assert gc.next_major_collection_threshold == 300.0 # max reached
  47. b = gc.set_major_threshold_from(300 * 2.0)
  48. assert b is True
  49. assert gc.next_major_collection_threshold == 300.0
  50. # then we shrink instantly
  51. b = gc.set_major_threshold_from(100.0)
  52. assert b is False
  53. assert gc.next_major_collection_threshold == 100.0
  54. # then we grow a bit
  55. b = gc.set_major_threshold_from(100 * 1.25)
  56. assert b is False
  57. assert gc.next_major_collection_threshold == 125.0
  58. b = gc.set_major_threshold_from(125 * 1.25)
  59. assert b is False
  60. assert gc.next_major_collection_threshold == 156.25
  61. # check that we cannot shrink below min_heap_size
  62. b = gc.set_major_threshold_from(42.7)
  63. assert b is False
  64. assert gc.next_major_collection_threshold == 100.0