diff options
| -rw-r--r-- | gc.c | 2 | ||||
| -rw-r--r-- | gc/default/default.c | 35 |
2 files changed, 23 insertions, 14 deletions
@@ -180,13 +180,13 @@ rb_gc_vm_barrier(void) rb_vm_barrier(); } -#if USE_MODULAR_GC void * rb_gc_get_ractor_newobj_cache(void) { return GET_RACTOR()->newobj_cache; } +#if USE_MODULAR_GC void rb_gc_initialize_vm_context(struct rb_gc_vm_context *context) { diff --git a/gc/default/default.c b/gc/default/default.c index 42561543d1..3d40b3dddf 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -2216,6 +2216,17 @@ rb_gc_impl_size_allocatable_p(size_t size) } static const size_t ALLOCATED_COUNT_STEP = 1024; +static void +ractor_cache_flush_count(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache) +{ + for (int heap_idx = 0; heap_idx < HEAP_COUNT; heap_idx++) { + rb_ractor_newobj_heap_cache_t *heap_cache = &cache->heap_caches[heap_idx]; + + rb_heap_t *heap = &heaps[heap_idx]; + RUBY_ATOMIC_SIZE_ADD(heap->total_allocated_objects, heap_cache->allocated_objects_count); + heap_cache->allocated_objects_count = 0; + } +} static inline VALUE ractor_cache_allocate_slot(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache, @@ -2240,19 +2251,11 @@ ractor_cache_allocate_slot(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *ca rb_asan_unpoison_object(obj, true); heap_cache->freelist = p->next; - if (rb_gc_multi_ractor_p()) { - heap_cache->allocated_objects_count++; - rb_heap_t *heap = &heaps[heap_idx]; - if (heap_cache->allocated_objects_count >= ALLOCATED_COUNT_STEP) { - RUBY_ATOMIC_SIZE_ADD(heap->total_allocated_objects, heap_cache->allocated_objects_count); - heap_cache->allocated_objects_count = 0; - } - } - else { - rb_heap_t *heap = &heaps[heap_idx]; - heap->total_allocated_objects++; - GC_ASSERT(heap->total_slots >= - (heap->total_allocated_objects - heap->total_freed_objects - heap->final_slots_count)); + heap_cache->allocated_objects_count++; + rb_heap_t *heap = &heaps[heap_idx]; + if (heap_cache->allocated_objects_count >= ALLOCATED_COUNT_STEP) { + RUBY_ATOMIC_SIZE_ADD(heap->total_allocated_objects, heap_cache->allocated_objects_count); + heap_cache->allocated_objects_count = 0; } #if RGENGC_CHECK_MODE @@ -5172,6 +5175,8 @@ gc_verify_internal_consistency_(rb_objspace_t *objspace) /* check counters */ + ractor_cache_flush_count(objspace, rb_gc_get_ractor_newobj_cache()); + if (!is_lazy_sweeping(objspace) && !finalizing && !rb_gc_multi_ractor_p()) { @@ -7510,6 +7515,8 @@ rb_gc_impl_stat(void *objspace_ptr, VALUE hash_or_sym) setup_gc_stat_symbols(); + ractor_cache_flush_count(objspace, rb_gc_get_ractor_newobj_cache()); + if (RB_TYPE_P(hash_or_sym, T_HASH)) { hash = hash_or_sym; } @@ -7662,6 +7669,8 @@ rb_gc_impl_stat_heap(void *objspace_ptr, VALUE heap_name, VALUE hash_or_sym) { rb_objspace_t *objspace = objspace_ptr; + ractor_cache_flush_count(objspace, rb_gc_get_ractor_newobj_cache()); + setup_gc_stat_heap_symbols(); if (NIL_P(heap_name)) { |
