[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
Родитель aa5bccfc65
Коммит aeae6e2842
11 изменённых файлов: 12 добавлений и 28 удалений

Просмотреть файл

@ -514,11 +514,7 @@ 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);
}
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

2
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;
}

2
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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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)) {
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);
/* Unshare orig since the root (tmp) only has this one child. */
FL_UNSET_RAW(orig, STR_SHARED);
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);
}
}
}

Просмотреть файл

@ -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|

Просмотреть файл

@ -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);

Просмотреть файл

@ -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)) {