[Bug #18014] Add assertion to verify freelist

This commit adds an assertion has been added after `gc_page_sweep` to
verify that the freelist length is equal to the number of free slots in
the page.
This commit is contained in:
Peter Zhu 2021-06-29 14:32:54 -04:00
parent 4a627dbdfd
commit e5fe48646c
Notes: git 2021-07-16 00:49:20 +09:00
1 changed files with 12 additions and 0 deletions

12
gc.c
View File

@ -5483,6 +5483,18 @@ gc_page_sweep(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_
}
}
#if RGENGC_CHECK_MODE
short freelist_len = 0;
RVALUE *ptr = sweep_page->freelist;
while (ptr) {
freelist_len++;
ptr = ptr->as.free.next;
}
if (freelist_len != sweep_page->free_slots) {
rb_bug("inconsistent freelist length: expected %d but was %d", sweep_page->free_slots, freelist_len);
}
#endif
gc_report(2, objspace, "page_sweep: end.\n");
return ctx.freed_slots + ctx.empty_slots;