Skip to content

Commit 18ca368

Browse files
committed
Small changes
1 parent 57dc2fa commit 18ca368

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

gc/default/default.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
#define psweep_debug(...) (void)0
131131
#endif
132132

133+
#define MAJOR_GC_DIAG 0
133134
#ifndef MAJOR_GC_DIAG
134135
#define MAJOR_GC_DIAG 0
135136
#endif
@@ -533,6 +534,9 @@ typedef struct rb_heap_struct {
533534
uintptr_t compact_cursor_index;
534535
struct heap_page *pooled_pages;
535536
size_t total_pages; /* total page count in a heap */
537+
#if RUBY_DEBUG
538+
size_t unlinked_pages;
539+
#endif
536540
size_t total_slots; /* total slot count */
537541
#if RUBY_DEBUG
538542
rb_atomic_t made_zombies;
@@ -1531,7 +1535,7 @@ static bool
15311535
heap_is_sweep_done(rb_objspace_t *objspace, rb_heap_t *heap)
15321536
{
15331537
#if USE_PARALLEL_SWEEP
1534-
if (heap->is_finished_sweeping || !heap->sweeping_page) {
1538+
if (heap->is_finished_sweeping) {
15351539
psweep_debug(2, "[gc] heap_is_sweep_done: %d, heap:%p (%ld), heap->is_finished_sweeping\n", true, heap, heap - heaps);
15361540
return true;
15371541
}
@@ -2350,6 +2354,9 @@ heap_unlink_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *pag
23502354
GC_ASSERT(heap->total_slots >= page->total_slots);
23512355
GC_ASSERT(page->total_slots > 0);
23522356
heap->total_slots -= page->total_slots;
2357+
#if RUBY_DEBUG
2358+
heap->unlinked_pages++;
2359+
#endif
23532360
}
23542361

23552362
static void
@@ -2604,7 +2611,7 @@ static void
26042611
heap_add_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *page)
26052612
{
26062613
/* Adding to eden heap during incremental sweeping is forbidden */
2607-
GC_ASSERT(!heap->sweeping_page);
2614+
GC_ASSERT(heap_is_sweep_done(objspace, heap));
26082615
GC_ASSERT(heap_page_in_global_empty_pages_pool(objspace, page));
26092616

26102617
/* Align start to slot_size boundary */
@@ -5248,6 +5255,9 @@ gc_sweep_start_heap(rb_objspace_t *objspace, rb_heap_t *heap)
52485255
}
52495256
heap->free_pages = NULL;
52505257
heap->pooled_pages = NULL;
5258+
#if RUBY_DEBUG
5259+
heap->unlinked_pages = 0;
5260+
#endif
52515261

52525262
#if USE_PARALLEL_SWEEP
52535263
heap->background_sweep_steps = heap->foreground_sweep_steps;
@@ -5467,6 +5477,11 @@ gc_sweep_finish_heap(rb_objspace_t *objspace, rb_heap_t *heap)
54675477
heap->is_finished_sweeping = true;
54685478
heap->sweeping_page = NULL;
54695479
#if RUBY_DEBUG
5480+
if (!objspace->flags.was_compacting) {
5481+
if (heap->total_pages + heap->unlinked_pages != rb_darray_size(heap->sweep_pages)) {
5482+
rb_bug("sweep_pages:%lu, total_pages:%lu, unlinked pages:%lu\n", rb_darray_size(heap->sweep_pages), heap->total_pages, heap->unlinked_pages);
5483+
}
5484+
}
54705485
for (size_t i = 0; i < rb_darray_size(heap->sweep_pages); i++) {
54715486
struct heap_page *page = rb_darray_get(heap->sweep_pages, i);
54725487
GC_ASSERT(!page->before_sweep);
@@ -7555,12 +7570,6 @@ gc_marks_finish(rb_objspace_t *objspace)
75557570

75567571
if (full_marking) {
75577572
/* Use weighted average slot size since total_slots spans all heaps */
7558-
/*size_t total_heap_bytes = 0;*/
7559-
/*for (int i = 0; i < HEAP_COUNT; i++) {*/
7560-
/*total_heap_bytes += heaps[i].total_slots * heaps[i].slot_size;*/
7561-
/*}*/
7562-
/*size_t avg_slot_size = total_slots > 0 ? total_heap_bytes / total_slots : (size_t)heaps[0].slot_size;*/
7563-
/*heap_allocatable_bytes_expand(objspace, NULL, sweep_slots, total_slots, avg_slot_size);*/
75647573
heap_allocatable_bytes_expand(objspace, NULL, sweep_slots, total_slots, heaps[0].slot_size);
75657574
}
75667575
}

0 commit comments

Comments
 (0)