Debian Codegraph @

rpython/memory/gc/test/test_minimark.py

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