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

ruby-changes:69649

From: Peter <ko1@a...>
Date: Tue, 9 Nov 2021 04:06:12 +0900 (JST)
Subject: [ruby-changes:69649] aeae6e2842 (master): [Feature #18290] Remove all usages of rb_gc_force_recycle

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

From aeae6e2842e1702dfb89b8ae69b48c4f5f64c662 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Fri, 5 Nov 2021 09:51:53 -0400
Subject: [Feature #18290] Remove all usages of rb_gc_force_recycle

This commit removes usages of rb_gc_force_recycle since it is a burden
to maintain and makes changes to the GC difficult.
---
 array.c                 |  8 ++------
 bignum.c                |  2 --
 ext/readline/readline.c |  1 -
 ext/zlib/zlib.c         |  4 ----
 hash.c                  |  2 --
 io.c                    |  2 +-
 parse.y                 |  2 --
 string.c                | 13 ++++++++-----
 template/prelude.c.tmpl |  3 ---
 thread.c                |  1 -
 thread_pthread.c        |  2 +-
 11 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/array.c b/array.c
index cef48d3336a..be09151f435 100644
--- a/array.c
+++ b/array.c
@@ -514,13 +514,9 @@ rb_ary_decrement_share(VALUE shared_root) https://github.com/ruby/ruby/blob/trunk/array.c#L514
 {
     if (shared_root) {
         long num = ARY_SHARED_ROOT_REFCNT(shared_root) - 1;
-	if (num == 0) {
-            rb_ary_free(shared_root);
-            rb_gc_force_recycle(shared_root);
-	}
-	else if (num > 0) {
+        if (num > 0) {
             ARY_SET_SHARED_ROOT_REFCNT(shared_root, num);
-	}
+        }
     }
 }
 
diff --git a/bignum.c b/bignum.c
index c74df3f4da2..f83fbe2c14b 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6934,8 +6934,6 @@ rb_big_isqrt(VALUE n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6934
 	    bary_small_rshift(xds, xds, xn, 1, carry);
 	    tn = BIGNUM_LEN(t);
 	}
-	rb_big_realloc(t, 0);
-	rb_gc_force_recycle(t);
     }
     RBASIC_SET_CLASS_RAW(x, rb_cInteger);
     return x;
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 8d635fce89e..5ae037dd41c 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -696,7 +696,6 @@ str_subpos(const char *ptr, const char *end, long beg, long *sublen, rb_encoding https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L696
     VALUE str = rb_enc_str_new_static(ptr, end-ptr, enc);
     OBJ_FREEZE(str);
     ptr = rb_str_subpos(str, beg, sublen);
-    rb_gc_force_recycle(str);
     return ptr;
 }
 
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 9937f827402..9bf71ce80e7 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -894,7 +894,6 @@ zstream_discard_input(struct zstream *z, long len) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L894
 	}
 	rb_str_resize(z->input, newlen);
 	if (newlen == 0) {
-	    rb_gc_force_recycle(z->input);
 	    z->input = Qnil;
 	}
 	else {
@@ -1137,7 +1136,6 @@ loop: https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1136
     }
     if (!NIL_P(old_input)) {
 	rb_str_resize(old_input, 0);
-	rb_gc_force_recycle(old_input);
     }
 
     if (args.jump_state)
@@ -2906,8 +2904,6 @@ gzfile_readpartial(struct gzfile *gz, long len, VALUE outbuf) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2904
     if (!NIL_P(outbuf)) {
         rb_str_resize(outbuf, RSTRING_LEN(dst));
         memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
-	rb_str_resize(dst, 0);
-	rb_gc_force_recycle(dst);
 	dst = outbuf;
     }
     return dst;
diff --git a/hash.c b/hash.c
index d546a2c73ac..aee671da34b 100644
--- a/hash.c
+++ b/hash.c
@@ -1267,7 +1267,6 @@ rb_hash_transient_heap_evacuate(VALUE hash, int promote) https://github.com/ruby/ruby/blob/trunk/hash.c#L1267
         ar_table *old_tab = RHASH_AR_TABLE(hash);
 
         if (UNLIKELY(old_tab == NULL)) {
-            rb_gc_force_recycle(hash);
             return;
         }
         HASH_ASSERT(old_tab != NULL);
@@ -4397,7 +4396,6 @@ rb_hash_compare_by_id(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L4396
     st_free_table(RHASH_ST_TABLE(hash));
     RHASH_ST_TABLE_SET(hash, identtable);
     RHASH_ST_CLEAR(tmp);
-    rb_gc_force_recycle(tmp);
 
     return hash;
 }
diff --git a/io.c b/io.c
index 38f51a3dac3..ac7c7593af8 100644
--- a/io.c
+++ b/io.c
@@ -9399,7 +9399,7 @@ rb_f_backquote(VALUE obj, VALUE str) https://github.com/ruby/ruby/blob/trunk/io.c#L9399
     rb_io_close(port);
     RFILE(port)->fptr = NULL;
     rb_io_fptr_finalize(fptr);
-    rb_gc_force_recycle(port); /* also guards from premature GC */
+    RB_GC_GUARD(port);
 
     return result;
 }
diff --git a/parse.y b/parse.y
index d3eb42e33f2..6461b73c73d 100644
--- a/parse.y
+++ b/parse.y
@@ -13401,12 +13401,10 @@ rb_parser_free(struct parser_params *p, void *ptr) https://github.com/ruby/ruby/blob/trunk/parse.y#L13401
     while ((n = *prev) != NULL) {
 	if (n->ptr == ptr) {
 	    *prev = n->next;
-	    rb_gc_force_recycle((VALUE)n);
 	    break;
 	}
 	prev = &n->next;
     }
-    xfree(ptr);
 }
 #endif
 
diff --git a/string.c b/string.c
index 154f8e98d9d..2746d882f1a 100644
--- a/string.c
+++ b/string.c
@@ -1164,7 +1164,6 @@ str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, https://github.com/ruby/ruby/blob/trunk/string.c#L1164
     }
     DATA_PTR(econv_wrapper) = 0;
     rb_econv_close(ec);
-    rb_gc_force_recycle(econv_wrapper);
     switch (ret) {
       case econv_finished:
 	len = dp - (unsigned char*)RSTRING_PTR(newstr);
@@ -1380,20 +1379,24 @@ rb_str_tmp_frozen_release(VALUE orig, VALUE tmp) https://github.com/ruby/ruby/blob/trunk/string.c#L1379
 
     if (STR_EMBED_P(tmp)) {
 	assert(OBJ_FROZEN_RAW(tmp));
-	rb_gc_force_recycle(tmp);
     }
     else if (FL_TEST_RAW(orig, STR_SHARED) &&
 	    !FL_TEST_RAW(orig, STR_TMPLOCK|RUBY_FL_FREEZE)) {
 	VALUE shared = RSTRING(orig)->as.heap.aux.shared;
 
 	if (shared == tmp && !FL_TEST_RAW(tmp, STR_BORROWED)) {
+            assert(RSTRING(orig)->as.heap.ptr == RSTRING(tmp)->as.heap.ptr);
+            assert(RSTRING(orig)->as.heap.len == RSTRING(tmp)->as.heap.len);
+
+            /* Unshare orig since the root (tmp) only has this one child. */
 	    FL_UNSET_RAW(orig, STR_SHARED);
-	    assert(RSTRING(orig)->as.heap.ptr == RSTRING(tmp)->as.heap.ptr);
-	    assert(RSTRING(orig)->as.heap.len == RSTRING(tmp)->as.heap.len);
 	    RSTRING(orig)->as.heap.aux.capa = RSTRING(tmp)->as.heap.aux.capa;
 	    RBASIC(orig)->flags |= RBASIC(tmp)->flags & STR_NOFREE;
 	    assert(OBJ_FROZEN_RAW(tmp));
-	    rb_gc_force_recycle(tmp);
+
+            /* Make tmp embedded and empty so it is safe for sweeping. */
+            STR_SET_EMBED(tmp);
+            STR_SET_EMBED_LEN(tmp, 0);
 	}
     }
 }
diff --git a/template/prelude.c.tmpl b/template/prelude.c.tmpl
index a36e572a411..8743d63de77 100644
--- a/template/prelude.c.tmpl
+++ b/template/prelude.c.tmpl
@@ -270,9 +270,6 @@ Init_<%=init_name%><%=%>(void) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L270
 %   next if sub
     prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%>);
 % end
-% if @have_sublib
-    rb_gc_force_recycle(prelude);
-% end
 
 #if 0
 % preludes.length.times {|i|
diff --git a/thread.c b/thread.c
index 0e3b53ae0b6..251dc1b3450 100644
--- a/thread.c
+++ b/thread.c
@@ -3459,7 +3459,6 @@ rb_thread_to_s(VALUE thread) https://github.com/ruby/ruby/blob/trunk/thread.c#L3459
     if ((loc = threadptr_invoke_proc_location(target_th)) != Qnil) {
         rb_str_catf(str, " %"PRIsVALUE":%"PRIsVALUE,
                     RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1));
-        rb_gc_force_recycle(loc);
     }
     rb_str_catf(str, " %s>", status);
 
diff --git a/thread_pthread.c b/thread_pthread.c
index 102b15d156f..6f0cc3d54c5 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1684,7 +1684,7 @@ native_set_thread_name(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1684
             name = p + 1;
 
         n = snprintf(buf, sizeof(buf), "%s:%d", name, NUM2INT(RARRAY_AREF(loc, 1)));
-        rb_gc_force_recycle(loc); /* acts as a GC guard, too */
+        RB_GC_GUARD(loc);
 
         len = (size_t)n;
         if (len >= sizeof(buf)) {
-- 
cgit v1.2.1


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

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