From a8cb7292c6790d12a72000c1e19e62f05ea63f6a Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Thu, 19 Feb 2026 21:43:32 +0000 Subject: [PATCH] Remove NUM_IN_PAGE macro This is being used to calculate the starting point of the slots in a page in order to make them evenly divisible by a bitmap plane. Since https://github.com/ruby/ruby/pull/16150 we restructured the bitmaps in order to pack them such that 1 bit == 1 slot, and remove the masking, meaning that we no longer need to align against planes. This is the last remining use for the NUM_IN_PAGE macro so we can remove that as well. --- gc/default/default.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/gc/default/default.c b/gc/default/default.c index 57d3f5b0da247c..9cb65da9023857 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -862,8 +862,6 @@ slot_index_for_offset(size_t offset, uint32_t div_magic) #define MARK_IN_BITMAP(bits, p) _MARK_IN_BITMAP(bits, GET_HEAP_PAGE(p), p) #define CLEAR_IN_BITMAP(bits, p) _CLEAR_IN_BITMAP(bits, GET_HEAP_PAGE(p), p) -#define NUM_IN_PAGE(p) (((bits_t)(p) & HEAP_PAGE_ALIGN_MASK) / BASE_SLOT_SIZE) - #define GET_HEAP_MARK_BITS(x) (&GET_HEAP_PAGE(x)->mark_bits[0]) #define GET_HEAP_PINNED_BITS(x) (&GET_HEAP_PAGE(x)->pinned_bits[0]) #define GET_HEAP_UNCOLLECTIBLE_BITS(x) (&GET_HEAP_PAGE(x)->uncollectible_bits[0]) @@ -1979,22 +1977,11 @@ heap_add_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *page) GC_ASSERT(!heap->sweeping_page); GC_ASSERT(heap_page_in_global_empty_pages_pool(objspace, page)); - /* adjust obj_limit (object number available in this page) */ + /* Align start to the first slot_size boundary after the page header */ uintptr_t start = (uintptr_t)page->body + sizeof(struct heap_page_header); - if (start % BASE_SLOT_SIZE != 0) { - int delta = BASE_SLOT_SIZE - (start % BASE_SLOT_SIZE); - start = start + delta; - GC_ASSERT(NUM_IN_PAGE(start) == 0 || NUM_IN_PAGE(start) == 1); - - /* Find a num in page that is evenly divisible by `stride`. - * This is to ensure that objects are aligned with bit planes. - * In other words, ensure there are an even number of objects - * per bit plane. */ - if (NUM_IN_PAGE(start) == 1) { - start += heap->slot_size - BASE_SLOT_SIZE; - } - - GC_ASSERT(NUM_IN_PAGE(start) * BASE_SLOT_SIZE % heap->slot_size == 0); + size_t remainder = start % heap->slot_size; + if (remainder != 0) { + start += heap->slot_size - remainder; } int slot_count = (int)((HEAP_PAGE_SIZE - (start - (uintptr_t)page->body))/heap->slot_size);