Debian Codegraph @

rpython/memory/gc/hybrid.py

raw symbols SCIP
1 import sys
2 from rpython.memory.gc.semispace import SemiSpaceGC
3 from rpython.memory.gc.generation import GenerationGC, WORD
4 from rpython.memory.gc.semispace import GCFLAG_EXTERNAL, GCFLAG_FORWARDED
5 from rpython.memory.gc.semispace import GCFLAG_HASHMASK
6 from rpython.memory.gc.generation import GCFLAG_NO_YOUNG_PTRS
7 from rpython.memory.gc.generation import GCFLAG_NO_HEAP_PTRS
8 from rpython.memory.gc.semispace import GC_HASH_TAKEN_ADDR
9 from rpython.memory.gc.semispace import GC_HASH_HASFIELD
10 from rpython.rtyper.lltypesystem import lltype, llmemory, llarena
11 from rpython.rtyper.lltypesystem.llmemory import raw_malloc_usage
12 from rpython.rtyper.lltypesystem.lloperation import llop
13 from rpython.rlib.debug import ll_assert, have_debug_prints
14 from rpython.rlib.debug import debug_print, debug_start, debug_stop
15 from rpython.rlib.rarithmetic import ovfcheck
16 from rpython.rtyper.lltypesystem import rffi
17
18 # _______in the semispaces_________ ______external (non-moving)_____
19 # / \ / \
20 # ___raw_malloc'ed__ _prebuilt_
21 # +----------------------------------+ / \ / \
22 # | | | | | | | |
23 # | | | | | | | | age < max age == max
24 # |nur-|o|o|o|o| | | +---+ +---+ +---+
25 # |sery|b|b|b|b|free| empty | |obj| |obj| |obj|
26 # | |j|j|j|j| | | +---+ +---+ +---+
27 # | | | | | | | | +---+ +---+ +---+
28 # +-----------------+----------------+ |obj| |obj| |obj|
29 # age <= max +---+ +---+ +---+
30 #
31 # |gen1|------------- generation 2 -----------------|-----generation 3-----|
32 #
33 # Object lists:
34 # * gen2_rawmalloced_objects
35 # * gen3_rawmalloced_objects
36 # * old_objects_pointing_to_young: gen2or3 objs that point to gen1 objs
37 # * last_generation_root_objects: gen3 objs that point to gen1or2 objs
38 #
39 # How to tell the objects apart:
40 # * external: tid & GCFLAG_EXTERNAL
41 # * gen1: is_in_nursery(obj)
42 # * gen3: (tid & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
43 # (GCFLAG_EXTERNAL|GCFLAG_AGE_MAX)
44 #
45 # Some invariants:
46 # * gen3 are either GCFLAG_NO_HEAP_PTRS or in 'last_generation_root_objects'
47 # * between collections, GCFLAG_UNVISITED set exactly for gen2_rawmalloced
48 #
49 # A malloc_varsize() of large objects returns objects that are external
50 # but initially of generation 2. Old objects from the semispaces are
51 # moved to external objects directly as generation 3.
52
53 # The "age" of an object is the number of times it survived a full
54 # collections, without counting the step that moved it out of the nursery.
55 # When a semispace-based object would grow older than MAX_SEMISPACE_AGE,
56 # it is instead copied to a nonmoving location. For example, a value of 3
57 # ensures that an object is copied at most 5 times in total: from the
58 # nursery to the semispace, then three times between the two spaces,
59 # then one last time to a nonmoving location.
60 MAX_SEMISPACE_AGE = 3
61
62 GCFLAG_UNVISITED = GenerationGC.first_unused_gcflag << 0
63 _gcflag_next_bit = GenerationGC.first_unused_gcflag << 1
64 GCFLAG_AGE_ONE = _gcflag_next_bit
65 GCFLAG_AGE_MAX = _gcflag_next_bit * MAX_SEMISPACE_AGE
66 GCFLAG_AGE_MASK = 0
67 while GCFLAG_AGE_MASK < GCFLAG_AGE_MAX:
68 GCFLAG_AGE_MASK |= _gcflag_next_bit
69 _gcflag_next_bit <<= 1
70
71 # The 3rd generation objects are only collected after the following
72 # number of calls to semispace_collect():
73 GENERATION3_COLLECT_THRESHOLD = 20
74
75 class HybridGC(GenerationGC):
76 """A two-generations semi-space GC like the GenerationGC,
77 except that objects above a certain size are handled separately:
78 they are allocated via raw_malloc/raw_free in a mark-n-sweep fashion.
79 """
80 first_unused_gcflag = _gcflag_next_bit
81 prebuilt_gc_objects_are_static_roots = True
82
83 # the following values override the default arguments of __init__ when
84 # translating to a real backend.
85 TRANSLATION_PARAMS = GenerationGC.TRANSLATION_PARAMS.copy()
86 TRANSLATION_PARAMS['large_object'] = 6*1024 # XXX adjust
87 TRANSLATION_PARAMS['large_object_gcptrs'] = 31*1024 # XXX adjust
88 TRANSLATION_PARAMS['min_nursery_size'] = 128*1024
89 # condition: large_object <= large_object_gcptrs < min_nursery_size/4
90
91 def __init__(self, *args, **kwds):
92 large_object = kwds.pop('large_object', 6*WORD)
93 large_object_gcptrs = kwds.pop('large_object_gcptrs', 8*WORD)
94 self.generation3_collect_threshold = kwds.pop(
95 'generation3_collect_threshold', GENERATION3_COLLECT_THRESHOLD)
96 GenerationGC.__init__(self, *args, **kwds)
97
98 # Objects whose total size is at least 'large_object' bytes are
99 # allocated separately in a mark-n-sweep fashion. If the object
100 # has GC pointers in its varsized part, we use instead the
101 # higher limit 'large_object_gcptrs'. The idea is that
102 # separately allocated objects are allocated immediately "old"
103 # and it's not good to have too many pointers from old to young
104 # objects.
105
106 # In this class, we assume that the 'large_object' limit is not
107 # very high, so that all objects that wouldn't easily fit in the
108 # nursery are considered large by this limit. This is the
109 # meaning of the 'assert' below.
110 self.nonlarge_max = large_object - 1
111 self.nonlarge_gcptrs_max = large_object_gcptrs - 1
112 assert self.nonlarge_gcptrs_max <= self.lb_young_var_basesize
113 assert self.nonlarge_max <= self.nonlarge_gcptrs_max
114
115 def setup(self):
116 self.large_objects_collect_trigger = self.param_space_size
117 self._initial_trigger = self.large_objects_collect_trigger
118 self.rawmalloced_objects_to_trace = self.AddressStack()
119 self.count_semispaceonly_collects = 0
120
121 self.gen2_rawmalloced_objects = self.AddressStack()
122 self.gen3_rawmalloced_objects = self.AddressStack()
123 GenerationGC.setup(self)
124
125 def set_max_heap_size(self, size):
126 raise NotImplementedError
127
128 # NB. to simplify the code, only varsized objects can be considered
129 # 'large'.
130
131 def malloc_varsize_clear(self, typeid, length, size, itemsize,
132 offset_to_length):
133 size_gc_header = self.gcheaderbuilder.size_gc_header
134 nonvarsize = size_gc_header + size
135
136 # Compute the maximal length that makes the object still
137 # below 'nonlarge_max'. All the following logic is usually
138 # constant-folded because self.nonlarge_max, size and itemsize
139 # are all constants (the arguments are constant due to
140 # inlining) and self.has_gcptr_in_varsize() is constant-folded.
141 if self.has_gcptr_in_varsize(typeid):
142 nonlarge_max = self.nonlarge_gcptrs_max
143 else:
144 nonlarge_max = self.nonlarge_max
145
146 if not raw_malloc_usage(itemsize):
147 too_many_items = raw_malloc_usage(nonvarsize) > nonlarge_max
148 else:
149 maxlength = nonlarge_max - raw_malloc_usage(nonvarsize)
150 maxlength = maxlength // raw_malloc_usage(itemsize)
151 too_many_items = length > maxlength
152
153 if not too_many_items:
154 # With the above checks we know now that totalsize cannot be more
155 # than 'nonlarge_max'; in particular, the + and * cannot overflow.
156 # Let's try to fit the object in the nursery.
157 totalsize = nonvarsize + itemsize * length
158 result = self.nursery_free
159 if raw_malloc_usage(totalsize) <= self.nursery_top - result:
160 llarena.arena_reserve(result, totalsize)
161 # GCFLAG_NO_YOUNG_PTRS is never set on young objs
162 self.init_gc_object(result, typeid, flags=0)
163 (result + size_gc_header + offset_to_length).signed[0] = length
164 self.nursery_free = result + llarena.round_up_for_allocation(
165 totalsize)
166 return llmemory.cast_adr_to_ptr(result+size_gc_header,
167 llmemory.GCREF)
168 return self.malloc_varsize_slowpath(typeid, length)
169
170 def malloc_varsize_slowpath(self, typeid, length):
171 # For objects that are too large, or when the nursery is exhausted.
172 # In order to keep malloc_varsize_clear() as compact as possible,
173 # we recompute what we need in this slow path instead of passing
174 # it all as function arguments.
175 size_gc_header = self.gcheaderbuilder.size_gc_header
176 nonvarsize = size_gc_header + self.fixed_size(typeid)
177 itemsize = self.varsize_item_sizes(typeid)
178 offset_to_length = self.varsize_offset_to_length(typeid)
179 try:
180 varsize = ovfcheck(itemsize * length)
181 totalsize = ovfcheck(nonvarsize + varsize)
182 except OverflowError:
183 raise MemoryError()
184 if self.has_gcptr_in_varsize(typeid):
185 nonlarge_max = self.nonlarge_gcptrs_max
186 else:
187 nonlarge_max = self.nonlarge_max
188 if raw_malloc_usage(totalsize) > nonlarge_max:
189 result = self.malloc_varsize_marknsweep(totalsize)
190 flags = self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS | GCFLAG_UNVISITED
191 else:
192 result = self.malloc_varsize_collecting_nursery(totalsize)
193 flags = self.GCFLAGS_FOR_NEW_YOUNG_OBJECTS
194 self.init_gc_object(result, typeid, flags)
195 (result + size_gc_header + offset_to_length).signed[0] = length
196 return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
197
198 malloc_varsize_slowpath._dont_inline_ = True
199
200 def can_move(self, addr):
201 tid = self.header(addr).tid
202 return not (tid & GCFLAG_EXTERNAL)
203
204 def malloc_varsize_collecting_nursery(self, totalsize):
205 result = self.collect_nursery()
206 ll_assert(raw_malloc_usage(totalsize) <= self.nursery_top - result,
207 "not enough room in malloc_varsize_collecting_nursery()")
208 llarena.arena_reserve(result, totalsize)
209 self.nursery_free = result + llarena.round_up_for_allocation(
210 totalsize)
211 return result
212
213 def _check_rawsize_alloced(self, size_estimate):
214 self.large_objects_collect_trigger -= size_estimate
215 if self.large_objects_collect_trigger < 0:
216 debug_start("gc-rawsize-collect")
217 debug_print("allocated", (self._initial_trigger -
218 self.large_objects_collect_trigger),
219 "bytes, triggering full collection")
220 self.semispace_collect()
221 debug_stop("gc-rawsize-collect")
222
223 def malloc_varsize_marknsweep(self, totalsize):
224 # In order to free the large objects from time to time, we
225 # arbitrarily force a full collect() if none occurs when we have
226 # allocated self.space_size + rawmalloced bytes of large objects.
227 self._check_rawsize_alloced(raw_malloc_usage(totalsize))
228 result = self.allocate_external_object(totalsize)
229 if not result:
230 raise MemoryError()
231 # The parent classes guarantee zero-filled allocations, so we
232 # need to follow suit.
233 llmemory.raw_memclear(result, totalsize)
234 size_gc_header = self.gcheaderbuilder.size_gc_header
235 self.gen2_rawmalloced_objects.append(result + size_gc_header)
236 return result
237
238 def allocate_external_object(self, totalsize):
239 # XXX maybe we should use arena_malloc() above a certain size?
240 # If so, we'd also use arena_reset() in malloc_varsize_marknsweep().
241 return llmemory.raw_malloc(totalsize)
242
243 def init_gc_object_immortal(self, addr, typeid,
244 flags=(GCFLAG_NO_YOUNG_PTRS |
245 GCFLAG_NO_HEAP_PTRS |
246 GCFLAG_AGE_MAX)):
247 GenerationGC.init_gc_object_immortal(self, addr, typeid, flags)
248
249 # ___________________________________________________________________
250 # collect() and semispace_collect() are not synonyms in this GC: the
251 # former is a complete collect, while the latter is only collecting
252 # the semispaces and not always doing the mark-n-sweep pass over the
253 # external objects of 3rd generation.
254
255 def collect(self, gen=2):
256 if gen > 1:
257 self.count_semispaceonly_collects = self.generation3_collect_threshold
258 GenerationGC.collect(self, gen)
259
260 def is_collecting_gen3(self):
261 count = self.count_semispaceonly_collects
262 return count >= self.generation3_collect_threshold
263
264 # ___________________________________________________________________
265 # the following methods are hook into SemiSpaceGC.semispace_collect()
266
267 def starting_full_collect(self):
268 # At the start of a collection, the GCFLAG_UNVISITED bit is set
269 # exactly on the objects in gen2_rawmalloced_objects. Only
270 # raw_malloc'ed objects can ever have this bit set.
271 self.count_semispaceonly_collects += 1
272 if self.is_collecting_gen3():
273 # set the GCFLAG_UNVISITED on all rawmalloced generation-3 objects
274 # as well, to let them be recorded by visit_external_object()
275 self.gen3_rawmalloced_objects.foreach(self._set_gcflag_unvisited,
276 None)
277 ll_assert(not self.rawmalloced_objects_to_trace.non_empty(),
278 "rawmalloced_objects_to_trace should be empty at start")
279 self._nonmoving_copy_count = 0
280 self._nonmoving_copy_size = 0
281
282 def _set_gcflag_unvisited(self, obj, ignored):
283 ll_assert(not (self.header(obj).tid & GCFLAG_UNVISITED),
284 "bogus GCFLAG_UNVISITED on gen3 obj")
285 self.header(obj).tid |= GCFLAG_UNVISITED
286
287 def collect_roots(self):
288 if not self.is_collecting_gen3():
289 GenerationGC.collect_roots(self)
290 else:
291 # as we don't record which prebuilt gc objects point to
292 # rawmalloced generation 3 objects, we have to trace all
293 # the prebuilt gc objects.
294 self.root_walker.walk_roots(
295 SemiSpaceGC._collect_root, # stack roots
296 SemiSpaceGC._collect_root, # static in prebuilt non-gc structs
297 SemiSpaceGC._collect_root) # static in prebuilt gc objects
298
299 def surviving(self, obj):
300 # To use during a collection. The objects that survive are the
301 # ones with GCFLAG_FORWARDED set and GCFLAG_UNVISITED not set.
302 # This is equivalent to self.is_forwarded() for all objects except
303 # the ones obtained by raw_malloc.
304 flags = self.header(obj).tid & (GCFLAG_FORWARDED|GCFLAG_UNVISITED)
305 return flags == GCFLAG_FORWARDED
306
307 def is_last_generation(self, obj):
308 return ((self.header(obj).tid & (GCFLAG_EXTERNAL|GCFLAG_AGE_MASK)) ==
309 (GCFLAG_EXTERNAL|GCFLAG_AGE_MAX))
310
311 def visit_external_object(self, obj):
312 hdr = self.header(obj)
313 if hdr.tid & GCFLAG_UNVISITED:
314 # This is a not-visited-yet raw_malloced object.
315 hdr.tid &= ~GCFLAG_UNVISITED
316 self.rawmalloced_objects_to_trace.append(obj)
317
318 def make_a_copy(self, obj, objsize):
319 # During a full collect, all copied objects might implicitly come
320 # from the nursery. If they do, we must add the GCFLAG_NO_YOUNG_PTRS.
321 # If they don't, we count how many times they are copied and when
322 # some threshold is reached we make the copy a non-movable "external"
323 # object. The threshold is MAX_SEMISPACE_AGE.
324 tid = self.header(obj).tid
325 # XXX the following logic is not doing exactly what is explained
326 # above: any object without GCFLAG_NO_YOUNG_PTRS has its age not
327 # incremented. This is accidental: it means that objects that
328 # are very often modified to point to young objects don't reach
329 # the 3rd generation. For now I'll leave it this way because
330 # I'm not sure that it's a bad thing.
331 if not (tid & GCFLAG_NO_YOUNG_PTRS):
332 tid |= GCFLAG_NO_YOUNG_PTRS # object comes from the nursery
333 elif (tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX:
334 tid += GCFLAG_AGE_ONE
335 else:
336 newobj = self.make_a_nonmoving_copy(obj, objsize)
337 if newobj:
338 return newobj
339 tid &= ~GCFLAG_AGE_MASK
340 # skip GenerationGC.make_a_copy() as we already did the right
341 # thing about GCFLAG_NO_YOUNG_PTRS
342 return self._make_a_copy_with_tid(obj, objsize, tid)
343
344 def make_a_nonmoving_copy(self, obj, objsize):
345 # NB. the object can have a finalizer or be a weakref, but
346 # it's not an issue.
347 totalsize = self.size_gc_header() + objsize
348 tid = self.header(obj).tid
349 if tid & GCFLAG_HASHMASK:
350 totalsize_incl_hash = totalsize + llmemory.sizeof(lltype.Signed)
351 else:
352 totalsize_incl_hash = totalsize
353 newaddr = self.allocate_external_object(totalsize_incl_hash)
354 if not newaddr:
355 return llmemory.NULL # can't raise MemoryError during a collect()
356 self._nonmoving_copy_count += 1
357 self._nonmoving_copy_size += raw_malloc_usage(totalsize)
358
359 llmemory.raw_memcopy(obj - self.size_gc_header(), newaddr, totalsize)
360 if tid & GCFLAG_HASHMASK:
361 hash = self._get_object_hash(obj, objsize, tid)
362 (newaddr + totalsize).signed[0] = hash
363 tid |= GC_HASH_HASFIELD
364 #
365 # GCFLAG_UNVISITED is not set
366 # GCFLAG_NO_HEAP_PTRS is not set either, conservatively. It may be
367 # set by the next collection's collect_last_generation_roots().
368 # This old object is immediately put at generation 3.
369 newobj = newaddr + self.size_gc_header()
370 hdr = self.header(newobj)
371 hdr.tid = tid | self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS
372 ll_assert(self.is_last_generation(newobj),
373 "make_a_nonmoving_copy: object too young")
374 self.gen3_rawmalloced_objects.append(newobj)
375 self.last_generation_root_objects.append(newobj)
376 self.rawmalloced_objects_to_trace.append(newobj) # visit me
377 return newobj
378
379 def scan_copied(self, scan):
380 # Alternate between scanning the regular objects we just moved
381 # and scanning the raw_malloc'ed object we just visited.
382 progress = True
383 while progress:
384 newscan = GenerationGC.scan_copied(self, scan)
385 progress = newscan != scan
386 scan = newscan
387 while self.rawmalloced_objects_to_trace.non_empty():
388 obj = self.rawmalloced_objects_to_trace.pop()
389 self.trace_and_copy(obj)
390 progress = True
391 return scan
392
393 def finished_full_collect(self):
394 ll_assert(not self.rawmalloced_objects_to_trace.non_empty(),
395 "rawmalloced_objects_to_trace should be empty at end")
396 debug_print("| [hybrid] made nonmoving: ",
397 self._nonmoving_copy_size, "bytes in",
398 self._nonmoving_copy_count, "objs")
399 rawmalloced_trigger = 0
400 # sweep the nonmarked rawmalloced objects
401 if self.is_collecting_gen3():
402 rawmalloced_trigger += self.sweep_rawmalloced_objects(generation=3)
403 rawmalloced_trigger += self.sweep_rawmalloced_objects(generation=2)
404 self.large_objects_collect_trigger = (rawmalloced_trigger +
405 self.space_size)
406 if self.is_collecting_gen3():
407 self.count_semispaceonly_collects = 0
408 self._initial_trigger = self.large_objects_collect_trigger
409
410 def sweep_rawmalloced_objects(self, generation):
411 # free all the rawmalloced objects of the specified generation
412 # that have not been marked
413 if generation == 2:
414 objects = self.gen2_rawmalloced_objects
415 # generation 2 sweep: if A points to an object object B that
416 # moves from gen2 to gen3, it's possible that A no longer points
417 # to any gen2 object. In this case, A remains a bit too long in
418 # last_generation_root_objects, but this will be fixed by the
419 # next collect_last_generation_roots().
420 elif generation == 3:
421 objects = self.gen3_rawmalloced_objects
422 # generation 3 sweep: remove from last_generation_root_objects
423 # all the objects that we are about to free
424 gen3roots = self.last_generation_root_objects
425 newgen3roots = self.AddressStack()
426 while gen3roots.non_empty():
427 obj = gen3roots.pop()
428 if not (self.header(obj).tid & GCFLAG_UNVISITED):
429 newgen3roots.append(obj)
430 gen3roots.delete()
431 self.last_generation_root_objects = newgen3roots
432 else:
433 ll_assert(False, "bogus 'generation'")
434 return 0 # to please the flowspace
435
436 surviving_objects = self.AddressStack()
437 # Help the flow space
438 alive_count = alive_size = dead_count = dead_size = 0
439 debug = have_debug_prints()
440 while objects.non_empty():
441 obj = objects.pop()
442 tid = self.header(obj).tid
443 if tid & GCFLAG_UNVISITED:
444 if debug:
445 dead_count+=1
446 dead_size+=raw_malloc_usage(self.get_size_incl_hash(obj))
447 addr = obj - self.gcheaderbuilder.size_gc_header
448 llmemory.raw_free(addr)
449 else:
450 if debug:
451 alive_count+=1
452 alive_size+=raw_malloc_usage(self.get_size_incl_hash(obj))
453 if generation == 3:
454 surviving_objects.append(obj)
455 elif generation == 2:
456 ll_assert((tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
457 "wrong age for generation 2 object")
458 tid += GCFLAG_AGE_ONE
459 if (tid & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX:
460 # the object becomes part of generation 3
461 self.gen3_rawmalloced_objects.append(obj)
462 # GCFLAG_NO_HEAP_PTRS not set yet, conservatively
463 self.last_generation_root_objects.append(obj)
464 else:
465 # the object stays in generation 2
466 tid |= GCFLAG_UNVISITED
467 surviving_objects.append(obj)
468 self.header(obj).tid = tid
469 objects.delete()
470 if generation == 2:
471 self.gen2_rawmalloced_objects = surviving_objects
472 elif generation == 3:
473 self.gen3_rawmalloced_objects = surviving_objects
474 debug_print("| [hyb] gen", generation,
475 "nonmoving now alive: ",
476 alive_size, "bytes in",
477 alive_count, "objs")
478 debug_print("| [hyb] gen", generation,
479 "nonmoving freed: ",
480 dead_size, "bytes in",
481 dead_count, "objs")
482 return alive_size
483
484 def id(self, ptr):
485 obj = llmemory.cast_ptr_to_adr(ptr)
486
487 # is it a tagged pointer?
488 if not self.is_valid_gc_object(obj):
489 return llmemory.cast_adr_to_int(obj)
490
491 if self._is_external(obj):
492 # a prebuilt or rawmalloced object
493 if self.is_last_generation(obj):
494 # a generation 3 object may be one that used to live in
495 # the semispace. So we still need to check if the object had
496 # its id taken before. If not, we can use its address as its
497 # id as it is not going to move any more.
498 result = self.objects_with_id.get(obj, obj)
499 else:
500 # a generation 2 external object was never non-external in
501 # the past, so it cannot be listed in self.objects_with_id.
502 result = obj
503 else:
504 result = self._compute_id(obj) # common case
505 return llmemory.cast_adr_to_int(result) * 2 # see comment in base.py
506 # XXX a possible optimization would be to use three dicts, one
507 # for each generation, instead of mixing gen2 and gen3 objects.
508
509 def debug_check_object(self, obj):
510 """Check the invariants about 'obj' that should be true
511 between collections."""
512 GenerationGC.debug_check_object(self, obj)
513 tid = self.header(obj).tid
514 if tid & GCFLAG_UNVISITED:
515 ll_assert(self._d_gen2ro.contains(obj),
516 "GCFLAG_UNVISITED on non-gen2 object")
517
518 def debug_check_consistency(self):
519 if self.DEBUG:
520 self._d_gen2ro = self.gen2_rawmalloced_objects.stack2dict()
521 GenerationGC.debug_check_consistency(self)
522 self._d_gen2ro.delete()
523 self.gen2_rawmalloced_objects.foreach(self._debug_check_gen2, None)
524 self.gen3_rawmalloced_objects.foreach(self._debug_check_gen3, None)
525
526 def _debug_check_gen2(self, obj, ignored):
527 tid = self.header(obj).tid
528 ll_assert(bool(tid & GCFLAG_EXTERNAL),
529 "gen2: missing GCFLAG_EXTERNAL")
530 ll_assert(bool(tid & GC_HASH_TAKEN_ADDR),
531 "gen2: missing GC_HASH_TAKEN_ADDR")
532 ll_assert(bool(tid & GCFLAG_UNVISITED),
533 "gen2: missing GCFLAG_UNVISITED")
534 ll_assert((tid & GCFLAG_AGE_MASK) < GCFLAG_AGE_MAX,
535 "gen2: age field too large")
536 def _debug_check_gen3(self, obj, ignored):
537 tid = self.header(obj).tid
538 ll_assert(bool(tid & GCFLAG_EXTERNAL),
539 "gen3: missing GCFLAG_EXTERNAL")
540 ll_assert(bool(tid & GC_HASH_TAKEN_ADDR),
541 "gen3: missing GC_HASH_TAKEN_ADDR")
542 ll_assert(not (tid & GCFLAG_UNVISITED),
543 "gen3: unexpected GCFLAG_UNVISITED")
544 ll_assert((tid & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX,
545 "gen3: wrong age field")