[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.
This commit is contained in:
Peter Zhu 2021-11-05 09:51:53 -04:00
parent aa5bccfc65
commit aeae6e2842
Notes: git 2021-11-09 04:06:17 +09:00
11 changed files with 12 additions and 28 deletions

View File

@ -514,13 +514,9 @@ rb_ary_decrement_share(VALUE shared_root)
{ {
if (shared_root) { if (shared_root) {
long num = ARY_SHARED_ROOT_REFCNT(shared_root) - 1; long num = ARY_SHARED_ROOT_REFCNT(shared_root) - 1;
if (num == 0) { if (num > 0) {
rb_ary_free(shared_root);
rb_gc_force_recycle(shared_root);
}
else if (num > 0) {
ARY_SET_SHARED_ROOT_REFCNT(shared_root, num); ARY_SET_SHARED_ROOT_REFCNT(shared_root, num);
} }
} }
} }

View File

@ -6934,8 +6934,6 @@ rb_big_isqrt(VALUE n)
bary_small_rshift(xds, xds, xn, 1, carry); bary_small_rshift(xds, xds, xn, 1, carry);
tn = BIGNUM_LEN(t); tn = BIGNUM_LEN(t);
} }
rb_big_realloc(t, 0);
rb_gc_force_recycle(t);
} }
RBASIC_SET_CLASS_RAW(x, rb_cInteger); RBASIC_SET_CLASS_RAW(x, rb_cInteger);
return x; return x;

View File

@ -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); VALUE str = rb_enc_str_new_static(ptr, end-ptr, enc);
OBJ_FREEZE(str); OBJ_FREEZE(str);
ptr = rb_str_subpos(str, beg, sublen); ptr = rb_str_subpos(str, beg, sublen);
rb_gc_force_recycle(str);
return ptr; return ptr;
} }

View File

@ -894,7 +894,6 @@ zstream_discard_input(struct zstream *z, long len)
} }
rb_str_resize(z->input, newlen); rb_str_resize(z->input, newlen);
if (newlen == 0) { if (newlen == 0) {
rb_gc_force_recycle(z->input);
z->input = Qnil; z->input = Qnil;
} }
else { else {
@ -1137,7 +1136,6 @@ loop:
} }
if (!NIL_P(old_input)) { if (!NIL_P(old_input)) {
rb_str_resize(old_input, 0); rb_str_resize(old_input, 0);
rb_gc_force_recycle(old_input);
} }
if (args.jump_state) if (args.jump_state)
@ -2906,8 +2904,6 @@ gzfile_readpartial(struct gzfile *gz, long len, VALUE outbuf)
if (!NIL_P(outbuf)) { if (!NIL_P(outbuf)) {
rb_str_resize(outbuf, RSTRING_LEN(dst)); rb_str_resize(outbuf, RSTRING_LEN(dst));
memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), 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; dst = outbuf;
} }
return dst; return dst;

2
hash.c
View File

@ -1267,7 +1267,6 @@ rb_hash_transient_heap_evacuate(VALUE hash, int promote)
ar_table *old_tab = RHASH_AR_TABLE(hash); ar_table *old_tab = RHASH_AR_TABLE(hash);
if (UNLIKELY(old_tab == NULL)) { if (UNLIKELY(old_tab == NULL)) {
rb_gc_force_recycle(hash);
return; return;
} }
HASH_ASSERT(old_tab != NULL); HASH_ASSERT(old_tab != NULL);
@ -4397,7 +4396,6 @@ rb_hash_compare_by_id(VALUE hash)
st_free_table(RHASH_ST_TABLE(hash)); st_free_table(RHASH_ST_TABLE(hash));
RHASH_ST_TABLE_SET(hash, identtable); RHASH_ST_TABLE_SET(hash, identtable);
RHASH_ST_CLEAR(tmp); RHASH_ST_CLEAR(tmp);
rb_gc_force_recycle(tmp);
return hash; return hash;
} }

2
io.c
View File

@ -9399,7 +9399,7 @@ rb_f_backquote(VALUE obj, VALUE str)
rb_io_close(port); rb_io_close(port);
RFILE(port)->fptr = NULL; RFILE(port)->fptr = NULL;
rb_io_fptr_finalize(fptr); rb_io_fptr_finalize(fptr);
rb_gc_force_recycle(port); /* also guards from premature GC */ RB_GC_GUARD(port);
return result; return result;
} }

View File

@ -13401,12 +13401,10 @@ rb_parser_free(struct parser_params *p, void *ptr)
while ((n = *prev) != NULL) { while ((n = *prev) != NULL) {
if (n->ptr == ptr) { if (n->ptr == ptr) {
*prev = n->next; *prev = n->next;
rb_gc_force_recycle((VALUE)n);
break; break;
} }
prev = &n->next; prev = &n->next;
} }
xfree(ptr);
} }
#endif #endif

View File

@ -1164,7 +1164,6 @@ str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len,
} }
DATA_PTR(econv_wrapper) = 0; DATA_PTR(econv_wrapper) = 0;
rb_econv_close(ec); rb_econv_close(ec);
rb_gc_force_recycle(econv_wrapper);
switch (ret) { switch (ret) {
case econv_finished: case econv_finished:
len = dp - (unsigned char*)RSTRING_PTR(newstr); 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)) { if (STR_EMBED_P(tmp)) {
assert(OBJ_FROZEN_RAW(tmp)); assert(OBJ_FROZEN_RAW(tmp));
rb_gc_force_recycle(tmp);
} }
else if (FL_TEST_RAW(orig, STR_SHARED) && else if (FL_TEST_RAW(orig, STR_SHARED) &&
!FL_TEST_RAW(orig, STR_TMPLOCK|RUBY_FL_FREEZE)) { !FL_TEST_RAW(orig, STR_TMPLOCK|RUBY_FL_FREEZE)) {
VALUE shared = RSTRING(orig)->as.heap.aux.shared; VALUE shared = RSTRING(orig)->as.heap.aux.shared;
if (shared == tmp && !FL_TEST_RAW(tmp, STR_BORROWED)) { 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); 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; RSTRING(orig)->as.heap.aux.capa = RSTRING(tmp)->as.heap.aux.capa;
RBASIC(orig)->flags |= RBASIC(tmp)->flags & STR_NOFREE; RBASIC(orig)->flags |= RBASIC(tmp)->flags & STR_NOFREE;
assert(OBJ_FROZEN_RAW(tmp)); 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);
} }
} }
} }

View File

@ -270,9 +270,6 @@ Init_<%=init_name%><%=%>(void)
% next if sub % next if sub
prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%>); prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), <%=start_line%>);
% end % end
% if @have_sublib
rb_gc_force_recycle(prelude);
% end
#if 0 #if 0
% preludes.length.times {|i| % preludes.length.times {|i|

View File

@ -3459,7 +3459,6 @@ rb_thread_to_s(VALUE thread)
if ((loc = threadptr_invoke_proc_location(target_th)) != Qnil) { if ((loc = threadptr_invoke_proc_location(target_th)) != Qnil) {
rb_str_catf(str, " %"PRIsVALUE":%"PRIsVALUE, rb_str_catf(str, " %"PRIsVALUE":%"PRIsVALUE,
RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1)); RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1));
rb_gc_force_recycle(loc);
} }
rb_str_catf(str, " %s>", status); rb_str_catf(str, " %s>", status);

View File

@ -1684,7 +1684,7 @@ native_set_thread_name(rb_thread_t *th)
name = p + 1; name = p + 1;
n = snprintf(buf, sizeof(buf), "%s:%d", name, NUM2INT(RARRAY_AREF(loc, 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; len = (size_t)n;
if (len >= sizeof(buf)) { if (len >= sizeof(buf)) {