Skip to content

Commit 5381f0f

Browse files
Replace sweeping_heaps map with a counter
We implemented some bit twiddling logic with an unsigned int to have a neat way of tracking which heaps were currently sweeping, but we actually don't need to care which heap is sweeping right now, just whether some are or not, so we can replace this with a counter.
1 parent 2fd891f commit 5381f0f

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

gc/default/default.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ typedef struct rb_objspace {
680680

681681
unsigned long live_ractor_cache_count;
682682

683-
unsigned int sweeping_heaps; /* bitfield: bit i set while heap i is sweeping */
683+
int sweeping_heap_count;
684684

685685
int fork_vm_lock_lev;
686686
} rb_objspace_t;
@@ -1018,7 +1018,7 @@ gc_mode_verify(enum gc_mode mode)
10181018
static inline bool
10191019
has_sweeping_pages(rb_objspace_t *objspace)
10201020
{
1021-
return objspace->sweeping_heaps != 0;
1021+
return objspace->sweeping_heap_count != 0;
10221022
}
10231023

10241024
static inline size_t
@@ -3017,7 +3017,7 @@ gc_abort(void *objspace_ptr)
30173017
}
30183018

30193019
if (is_lazy_sweeping(objspace)) {
3020-
objspace->sweeping_heaps = 0;
3020+
objspace->sweeping_heap_count = 0;
30213021
for (int i = 0; i < HEAP_COUNT; i++) {
30223022
rb_heap_t *heap = &heaps[i];
30233023

@@ -3753,7 +3753,7 @@ gc_sweep_start_heap(rb_objspace_t *objspace, rb_heap_t *heap)
37533753
{
37543754
heap->sweeping_page = ccan_list_top(&heap->pages, struct heap_page, page_node);
37553755
if (heap->sweeping_page) {
3756-
objspace->sweeping_heaps |= (1u << (heap - heaps));
3756+
objspace->sweeping_heap_count++;
37573757
}
37583758
heap->free_pages = NULL;
37593759
heap->pooled_pages = NULL;
@@ -3982,7 +3982,8 @@ gc_sweep_step(rb_objspace_t *objspace, rb_heap_t *heap)
39823982
} while ((sweep_page = heap->sweeping_page));
39833983

39843984
if (!heap->sweeping_page) {
3985-
objspace->sweeping_heaps &= ~(1u << (heap - heaps));
3985+
objspace->sweeping_heap_count--;
3986+
GC_ASSERT(objspace->sweeping_heap_count >= 0);
39863987
gc_sweep_finish_heap(objspace, heap);
39873988

39883989
if (!has_sweeping_pages(objspace)) {

0 commit comments

Comments
 (0)