Skip to content

Commit

Permalink
[Bug #18014] Add assertion to verify freelist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
peterzhu2118 committed Jul 15, 2021
1 parent 4a627db commit e5fe486
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gc.c
Expand Up @@ -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;
Expand Down

0 comments on commit e5fe486

Please sign in to comment.