|
130 | 130 | #define psweep_debug(...) (void)0 |
131 | 131 | #endif |
132 | 132 |
|
| 133 | +#define MAJOR_GC_DIAG 0 |
133 | 134 | #ifndef MAJOR_GC_DIAG |
134 | 135 | #define MAJOR_GC_DIAG 0 |
135 | 136 | #endif |
@@ -533,6 +534,9 @@ typedef struct rb_heap_struct { |
533 | 534 | uintptr_t compact_cursor_index; |
534 | 535 | struct heap_page *pooled_pages; |
535 | 536 | size_t total_pages; /* total page count in a heap */ |
| 537 | +#if RUBY_DEBUG |
| 538 | + size_t unlinked_pages; |
| 539 | +#endif |
536 | 540 | size_t total_slots; /* total slot count */ |
537 | 541 | #if RUBY_DEBUG |
538 | 542 | rb_atomic_t made_zombies; |
@@ -1531,7 +1535,7 @@ static bool |
1531 | 1535 | heap_is_sweep_done(rb_objspace_t *objspace, rb_heap_t *heap) |
1532 | 1536 | { |
1533 | 1537 | #if USE_PARALLEL_SWEEP |
1534 | | - if (heap->is_finished_sweeping || !heap->sweeping_page) { |
| 1538 | + if (heap->is_finished_sweeping) { |
1535 | 1539 | psweep_debug(2, "[gc] heap_is_sweep_done: %d, heap:%p (%ld), heap->is_finished_sweeping\n", true, heap, heap - heaps); |
1536 | 1540 | return true; |
1537 | 1541 | } |
@@ -2350,6 +2354,9 @@ heap_unlink_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *pag |
2350 | 2354 | GC_ASSERT(heap->total_slots >= page->total_slots); |
2351 | 2355 | GC_ASSERT(page->total_slots > 0); |
2352 | 2356 | heap->total_slots -= page->total_slots; |
| 2357 | +#if RUBY_DEBUG |
| 2358 | + heap->unlinked_pages++; |
| 2359 | +#endif |
2353 | 2360 | } |
2354 | 2361 |
|
2355 | 2362 | static void |
@@ -2604,7 +2611,7 @@ static void |
2604 | 2611 | heap_add_page(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *page) |
2605 | 2612 | { |
2606 | 2613 | /* Adding to eden heap during incremental sweeping is forbidden */ |
2607 | | - GC_ASSERT(!heap->sweeping_page); |
| 2614 | + GC_ASSERT(heap_is_sweep_done(objspace, heap)); |
2608 | 2615 | GC_ASSERT(heap_page_in_global_empty_pages_pool(objspace, page)); |
2609 | 2616 |
|
2610 | 2617 | /* Align start to slot_size boundary */ |
@@ -5248,6 +5255,9 @@ gc_sweep_start_heap(rb_objspace_t *objspace, rb_heap_t *heap) |
5248 | 5255 | } |
5249 | 5256 | heap->free_pages = NULL; |
5250 | 5257 | heap->pooled_pages = NULL; |
| 5258 | +#if RUBY_DEBUG |
| 5259 | + heap->unlinked_pages = 0; |
| 5260 | +#endif |
5251 | 5261 |
|
5252 | 5262 | #if USE_PARALLEL_SWEEP |
5253 | 5263 | heap->background_sweep_steps = heap->foreground_sweep_steps; |
@@ -5467,6 +5477,11 @@ gc_sweep_finish_heap(rb_objspace_t *objspace, rb_heap_t *heap) |
5467 | 5477 | heap->is_finished_sweeping = true; |
5468 | 5478 | heap->sweeping_page = NULL; |
5469 | 5479 | #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 | + } |
5470 | 5485 | for (size_t i = 0; i < rb_darray_size(heap->sweep_pages); i++) { |
5471 | 5486 | struct heap_page *page = rb_darray_get(heap->sweep_pages, i); |
5472 | 5487 | GC_ASSERT(!page->before_sweep); |
@@ -7555,12 +7570,6 @@ gc_marks_finish(rb_objspace_t *objspace) |
7555 | 7570 |
|
7556 | 7571 | if (full_marking) { |
7557 | 7572 | /* 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);*/ |
7564 | 7573 | heap_allocatable_bytes_expand(objspace, NULL, sweep_slots, total_slots, heaps[0].slot_size); |
7565 | 7574 | } |
7566 | 7575 | } |
|
0 commit comments