diff --git a/array.c b/array.c index cef48d3336..be09151f43 100644 --- a/array.c +++ b/array.c @@ -514,13 +514,9 @@ rb_ary_decrement_share(VALUE shared_root) { 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 c74df3f4da..f83fbe2c14 100644 --- a/bignum.c +++ b/bignum.c @@ -6934,8 +6934,6 @@ rb_big_isqrt(VALUE n) 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 8d635fce89..5ae037dd41 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 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 9937f82740..9bf71ce80e 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -894,7 +894,6 @@ zstream_discard_input(struct zstream *z, long len) } rb_str_resize(z->input, newlen); if (newlen == 0) { - rb_gc_force_recycle(z->input); z->input = Qnil; } else { @@ -1137,7 +1136,6 @@ loop: } 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) 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 d546a2c73a..aee671da34 100644 --- a/hash.c +++ b/hash.c @@ -1267,7 +1267,6 @@ rb_hash_transient_heap_evacuate(VALUE hash, int promote) 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) 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 38f51a3dac..ac7c7593af 100644 --- a/io.c +++ b/io.c @@ -9399,7 +9399,7 @@ rb_f_backquote(VALUE obj, VALUE str) 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 d3eb42e33f..6461b73c73 100644 --- a/parse.y +++ b/parse.y @@ -13401,12 +13401,10 @@ rb_parser_free(struct parser_params *p, void *ptr) 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 154f8e98d9..2746d882f1 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, } 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) 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 a36e572a41..8743d63de7 100644 --- a/template/prelude.c.tmpl +++ b/template/prelude.c.tmpl @@ -270,9 +270,6 @@ Init_<%=init_name%><%=%>(void) % 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 0e3b53ae0b..251dc1b345 100644 --- a/thread.c +++ b/thread.c @@ -3459,7 +3459,6 @@ rb_thread_to_s(VALUE thread) 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 102b15d156..6f0cc3d54c 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1684,7 +1684,7 @@ native_set_thread_name(rb_thread_t *th) 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)) {