Skip to content

Commit

Permalink
Fix object allocation counters in compaction
Browse files Browse the repository at this point in the history
When we move an object in compaction, we do not decrement the total_freed_objects
of the original size pool or increment the total_allocated_objects of the
new size pool. This means that when this object dies, it will appear as
if the object was never freed from the original size pool and the new
size pool will have one more free than expected. This means that the new
size pool could appear to have a negative number of live objects.
  • Loading branch information
peterzhu2118 committed Aug 26, 2024
1 parent c3dc132 commit 80d457b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gc/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,10 @@ newobj_alloc(rb_objspace_t *objspace, rb_ractor_newobj_cache_t *cache, size_t si
obj = newobj_cache_miss(objspace, cache, size_pool_idx, vm_locked);
}

size_pools[size_pool_idx].total_allocated_objects++;
rb_size_pool_t *size_pool = &size_pools[size_pool_idx];
size_pool->total_allocated_objects++;
GC_ASSERT(SIZE_POOL_EDEN_HEAP(size_pool)->total_slots + SIZE_POOL_TOMB_HEAP(size_pool)->total_slots >=
(size_pool->total_allocated_objects - size_pool->total_freed_objects - size_pool->final_slots_count));

return obj;
}
Expand Down Expand Up @@ -7284,6 +7287,9 @@ gc_move(rb_objspace_t *objspace, VALUE src, VALUE dest, size_t src_slot_size, si
RMOVED(src)->destination = dest;
GC_ASSERT(BUILTIN_TYPE(dest) != T_NONE);

GET_HEAP_PAGE(src)->size_pool->total_freed_objects++;
GET_HEAP_PAGE(dest)->size_pool->total_allocated_objects++;

return src;
}

Expand Down

0 comments on commit 80d457b

Please sign in to comment.