Move final_slots_count to per size pool

This commit is contained in:
Peter Zhu 2024-08-23 15:53:46 -04:00
Родитель 2b0b68fa46
Коммит c3dc1322ba
1 изменённых файлов: 22 добавлений и 12 удалений

Просмотреть файл

@ -443,6 +443,7 @@ typedef struct rb_size_pool_struct {
size_t force_incremental_marking_finish_count;
size_t total_allocated_objects;
size_t total_freed_objects;
size_t final_slots_count;
/* Sweeping statistics */
size_t freed_slots;
@ -516,7 +517,6 @@ typedef struct rb_objspace {
size_t freeable_pages;
/* final */
size_t final_slots;
VALUE deferred_final;
} heap_pages;
@ -841,7 +841,6 @@ RVALUE_AGE_SET(VALUE obj, int age)
#define heap_pages_lomem objspace->heap_pages.range[0]
#define heap_pages_himem objspace->heap_pages.range[1]
#define heap_pages_freeable_pages objspace->heap_pages.freeable_pages
#define heap_pages_final_slots objspace->heap_pages.final_slots
#define heap_pages_deferred_final objspace->heap_pages.deferred_final
#define size_pools objspace->size_pools
#define during_gc objspace->flags.during_gc
@ -1008,6 +1007,17 @@ total_freed_objects(rb_objspace_t *objspace)
return count;
}
static inline size_t
total_final_slots_count(rb_objspace_t *objspace)
{
size_t count = 0;
for (int i = 0; i < SIZE_POOL_COUNT; i++) {
rb_size_pool_t *size_pool = &size_pools[i];
count += size_pool->final_slots_count;
}
return count;
}
#define gc_mode(objspace) gc_mode_verify((enum gc_mode)(objspace)->flags.mode)
#define gc_mode_set(objspace, m) ((objspace)->flags.mode = (unsigned int)gc_mode_verify(m))
#define gc_needs_major_flags objspace->rgengc.need_major_gc
@ -2810,7 +2820,7 @@ rb_gc_impl_make_zombie(void *objspace_ptr, VALUE obj, void (*dfree)(void *), voi
struct heap_page *page = GET_HEAP_PAGE(obj);
page->final_slots++;
heap_pages_final_slots++;
page->size_pool->final_slots_count++;
}
static void
@ -3112,10 +3122,10 @@ finalize_list(rb_objspace_t *objspace, VALUE zombie)
obj_free_object_id(objspace, zombie);
}
GC_ASSERT(heap_pages_final_slots > 0);
GC_ASSERT(page->size_pool->final_slots_count > 0);
GC_ASSERT(page->final_slots > 0);
heap_pages_final_slots--;
page->size_pool->final_slots_count--;
page->final_slots--;
page->free_slots++;
heap_page_add_freeobj(objspace, page, zombie);
@ -3353,13 +3363,13 @@ objspace_available_slots(rb_objspace_t *objspace)
static size_t
objspace_live_slots(rb_objspace_t *objspace)
{
return total_allocated_objects(objspace) - total_freed_objects(objspace) - heap_pages_final_slots;
return total_allocated_objects(objspace) - total_freed_objects(objspace) - total_final_slots_count(objspace);
}
static size_t
objspace_free_slots(rb_objspace_t *objspace)
{
return objspace_available_slots(objspace) - objspace_live_slots(objspace) - heap_pages_final_slots;
return objspace_available_slots(objspace) - objspace_live_slots(objspace) - total_final_slots_count(objspace);
}
static void
@ -5436,7 +5446,7 @@ gc_verify_internal_consistency_(rb_objspace_t *objspace)
!objspace->multi_ractor_p) {
if (objspace_live_slots(objspace) != data.live_object_count) {
fprintf(stderr, "heap_pages_final_slots: %"PRIdSIZE", total_freed_objects: %"PRIdSIZE"\n",
heap_pages_final_slots, total_freed_objects(objspace));
total_final_slots_count(objspace), total_freed_objects(objspace));
rb_bug("inconsistent live slot number: expect %"PRIuSIZE", but %"PRIuSIZE".",
objspace_live_slots(objspace), data.live_object_count);
}
@ -5464,14 +5474,14 @@ gc_verify_internal_consistency_(rb_objspace_t *objspace)
}
}
if (heap_pages_final_slots != data.zombie_object_count ||
heap_pages_final_slots != list_count) {
if (total_final_slots_count(objspace) != data.zombie_object_count ||
total_final_slots_count(objspace) != list_count) {
rb_bug("inconsistent finalizing object count:\n"
" expect %"PRIuSIZE"\n"
" but %"PRIuSIZE" zombies\n"
" heap_pages_deferred_final list has %"PRIuSIZE" items.",
heap_pages_final_slots,
total_final_slots_count(objspace),
data.zombie_object_count,
list_count);
}
@ -7840,7 +7850,7 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym)
SET(heap_available_slots, objspace_available_slots(objspace));
SET(heap_live_slots, objspace_live_slots(objspace));
SET(heap_free_slots, objspace_free_slots(objspace));
SET(heap_final_slots, heap_pages_final_slots);
SET(heap_final_slots, total_final_slots_count(objspace));
SET(heap_marked_slots, objspace->marked_slots);
SET(heap_eden_pages, heap_eden_total_pages(objspace));
SET(heap_tomb_pages, heap_tomb_total_pages(objspace));