Debian Codegraph @

rpython/memory/test/test_minimark_gc.py

raw symbols SCIP
1 from rpython.rlib import rgc
2 from rpython.rlib.rarithmetic import LONG_BIT
3
4 from rpython.memory.test import test_semispace_gc
5
6 WORD = LONG_BIT // 8
7
8 class TestMiniMarkGC(test_semispace_gc.TestSemiSpaceGC):
9 from rpython.memory.gc.minimark import MiniMarkGC as GCClass
10 GC_CAN_SHRINK_BIG_ARRAY = False
11 GC_CAN_MALLOC_NONMOVABLE = True
12 BUT_HOW_BIG_IS_A_BIG_STRING = 11*WORD
13
14 def test_bounded_memory_when_allocating_with_finalizers(self):
15 # Issue #2590: when allocating a lot of objects with a finalizer
16 # and little else, the bounds in the (inc)minimark GC are not
17 # set up reasonably and the total memory usage grows without
18 # limit.
19 class B(object):
20 pass
21 b = B()
22 b.num_deleted = 0
23 class A(object):
24 def __init__(self):
25 fq.register_finalizer(self)
26 class FQ(rgc.FinalizerQueue):
27 Class = A
28 def finalizer_trigger(self):
29 while True:
30 a = self.next_dead()
31 if a is None:
32 break
33 b.num_deleted += 1
34 fq = FQ()
35 def f(x, y):
36 i = 0
37 alive_max = 0
38 while i < x:
39 i += 1
40 a = A()
41 a.x = a.y = a.z = i
42 #print i - b.num_deleted, b.num_deleted
43 alive = i - b.num_deleted
44 assert alive >= 0
45 alive_max = max(alive_max, alive)
46 return alive_max
47 res = self.interpret(f, [1000, 0])
48 assert res < 100