File: test_minimark.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (70 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from rpython.rtyper.lltypesystem import llmemory
from rpython.memory.gc.minimark import MiniMarkGC
from rpython.rlib.rarithmetic import LONG_BIT

# Note that most tests are in test_direct.py.


def test_card_marking_words_for_length():
    gc = MiniMarkGC(None, card_page_indices=128)
    assert gc.card_page_shift == 7
    P = 128 * LONG_BIT
    assert gc.card_marking_words_for_length(1) == 1
    assert gc.card_marking_words_for_length(P) == 1
    assert gc.card_marking_words_for_length(P+1) == 2
    assert gc.card_marking_words_for_length(P+P) == 2
    assert gc.card_marking_words_for_length(P+P+1) == 3
    assert gc.card_marking_words_for_length(P+P+P+P+P+P+P+P) == 8
    assert gc.card_marking_words_for_length(P+P+P+P+P+P+P+P+1) == 9

def test_card_marking_bytes_for_length():
    gc = MiniMarkGC(None, card_page_indices=128)
    assert gc.card_page_shift == 7
    P = 128 * 8
    assert gc.card_marking_bytes_for_length(1) == 1
    assert gc.card_marking_bytes_for_length(P) == 1
    assert gc.card_marking_bytes_for_length(P+1) == 2
    assert gc.card_marking_bytes_for_length(P+P) == 2
    assert gc.card_marking_bytes_for_length(P+P+1) == 3
    assert gc.card_marking_bytes_for_length(P+P+P+P+P+P+P+P) == 8
    assert gc.card_marking_bytes_for_length(P+P+P+P+P+P+P+P+1) == 9

def test_set_major_threshold():
    gc = MiniMarkGC(None, major_collection_threshold=2.0,
                    growth_rate_max=1.5)
    gc.min_heap_size = 100.0
    gc.max_heap_size = 300.0
    gc.next_major_collection_initial = 0.0
    gc.next_major_collection_threshold = 0.0
    # first, we don't grow past min_heap_size
    for i in range(5):
        gc.set_major_threshold_from(100.0)
        assert gc.next_major_collection_threshold == 100.0
    # then we grow a lot
    b = gc.set_major_threshold_from(100 * 2.0)
    assert b is False
    assert gc.next_major_collection_threshold == 150.0
    b = gc.set_major_threshold_from(150 * 2.0)
    assert b is False
    assert gc.next_major_collection_threshold == 225.0
    b = gc.set_major_threshold_from(225 * 2.0)
    assert b is True
    assert gc.next_major_collection_threshold == 300.0   # max reached
    b = gc.set_major_threshold_from(300 * 2.0)
    assert b is True
    assert gc.next_major_collection_threshold == 300.0
    # then we shrink instantly
    b = gc.set_major_threshold_from(100.0)
    assert b is False
    assert gc.next_major_collection_threshold == 100.0
    # then we grow a bit
    b = gc.set_major_threshold_from(100 * 1.25)
    assert b is False
    assert gc.next_major_collection_threshold == 125.0
    b = gc.set_major_threshold_from(125 * 1.25)
    assert b is False
    assert gc.next_major_collection_threshold == 156.25
    # check that we cannot shrink below min_heap_size
    b = gc.set_major_threshold_from(42.7)
    assert b is False
    assert gc.next_major_collection_threshold == 100.0