[前][次][番号順一覧][スレッド一覧]

ruby-changes:66450

From: Peter <ko1@a...>
Date: Thu, 10 Jun 2021 23:59:53 +0900 (JST)
Subject: [ruby-changes:66450] 929cc615a7 (master): Finish GC before calling gc_set_initial_pages

https://git.ruby-lang.org/ruby.git/commit/?id=929cc615a7

From 929cc615a749f467809a865a3d40adcc0b58c667 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Thu, 10 Jun 2021 09:59:12 -0400
Subject: Finish GC before calling gc_set_initial_pages

If we are during incremental sweeping when calling gc_set_initial_pages
there is an assertion error. The following patch will artificially
produce the bug:

```
diff --git a/gc.c b/gc.c
index c3157dbe2c..d7282cf8f0 100644
--- a/gc.c
+++ b/gc.c
@@ -404,7 +404,7 @@ int ruby_rgengc_debug; https://github.com/ruby/ruby/blob/trunk/gc.c#L404
  * 5: show all references
  */
 #ifndef RGENGC_CHECK_MODE
-#define RGENGC_CHECK_MODE  0
+#define RGENGC_CHECK_MODE  1
 #endif
 // Note: using RUBY_ASSERT_WHEN() extend a macro in expr (info by nobu).
@@ -10821,6 +10821,10 @@ gc_set_initial_pages(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L10821
 void
 ruby_gc_set_params(void)
 {
+    for (int i = 0; i < 10000; i++) {
+        rb_ary_new();
+    }
+
     /* RUBY_GC_HEAP_FREE_SLOTS */
     if (get_envparam_size("RUBY_GC_HEAP_FREE_SLOTS", &gc_params.heap_free_slots, 0)) {
        /* ok */
```

The crash looks like:

```
Assertion Failed: ../gc.c:2038:heap_add_page:!(heap == heap_eden && heap->sweeping_page)
```
---
 gc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gc.c b/gc.c
index f7bbe95..70fb47c 100644
--- a/gc.c
+++ b/gc.c
@@ -10773,6 +10773,8 @@ gc_set_initial_pages(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L10773
     size_t min_pages;
     rb_objspace_t *objspace = &rb_objspace;
 
+    gc_rest(objspace);
+
     min_pages = gc_params.heap_init_slots / HEAP_PAGE_OBJ_LIMIT;
     if (min_pages > heap_eden->total_pages) {
 	heap_add_pages(objspace, heap_eden, min_pages - heap_eden->total_pages);
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]