1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Pin finalizer table

Objects in the finalizer table stay pinned for now.  In some cases, the
key could move which would cause a miss when removing the object from
the table (leading to a T_MOVED reference staying in the table).
This commit is contained in:
Aaron Patterson 2019-05-08 15:55:35 -07:00
parent 4ff0911c79
commit dc405eb737
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6

26
gc.c
View file

@ -4424,7 +4424,7 @@ rb_gc_mark_stack_values(long n, const VALUE *values)
}
static int
mark_entry_no_pin(st_data_t key, st_data_t value, st_data_t data)
mark_value(st_data_t key, st_data_t value, st_data_t data)
{
rb_objspace_t *objspace = (rb_objspace_t *)data;
gc_mark(objspace, (VALUE)value);
@ -4432,7 +4432,7 @@ mark_entry_no_pin(st_data_t key, st_data_t value, st_data_t data)
}
static int
mark_entry(st_data_t key, st_data_t value, st_data_t data)
mark_value_pin(st_data_t key, st_data_t value, st_data_t data)
{
rb_objspace_t *objspace = (rb_objspace_t *)data;
gc_mark_and_pin(objspace, (VALUE)value);
@ -4443,14 +4443,14 @@ static void
mark_tbl_no_pin(rb_objspace_t *objspace, st_table *tbl)
{
if (!tbl || tbl->num_entries == 0) return;
st_foreach(tbl, mark_entry_no_pin, (st_data_t)objspace);
st_foreach(tbl, mark_value, (st_data_t)objspace);
}
static void
mark_tbl(rb_objspace_t *objspace, st_table *tbl)
{
if (!tbl || tbl->num_entries == 0) return;
st_foreach(tbl, mark_entry, (st_data_t)objspace);
st_foreach(tbl, mark_value_pin, (st_data_t)objspace);
}
static int
@ -4461,6 +4461,15 @@ mark_key(st_data_t key, st_data_t value, st_data_t data)
return ST_CONTINUE;
}
static int
mark_and_pin_value_pin_key(st_data_t key, st_data_t value, st_data_t data)
{
rb_objspace_t *objspace = (rb_objspace_t *)data;
gc_pin(objspace, (VALUE)key);
gc_mark_and_pin(objspace, (VALUE)value);
return ST_CONTINUE;
}
static void
mark_set(rb_objspace_t *objspace, st_table *tbl)
{
@ -4468,6 +4477,13 @@ mark_set(rb_objspace_t *objspace, st_table *tbl)
st_foreach(tbl, mark_key, (st_data_t)objspace);
}
static void
mark_finalizer_tbl(rb_objspace_t *objspace, st_table *tbl)
{
if (!tbl) return;
st_foreach(tbl, mark_and_pin_value_pin_key, (st_data_t)objspace);
}
void
rb_mark_set(st_table *tbl)
{
@ -5286,7 +5302,7 @@ gc_mark_roots(rb_objspace_t *objspace, const char **categoryp)
if (vm->self) gc_mark(objspace, vm->self);
MARK_CHECKPOINT("finalizers");
mark_tbl(objspace, finalizer_table);
mark_finalizer_tbl(objspace, finalizer_table);
MARK_CHECKPOINT("machine_context");
mark_current_machine_context(objspace, ec);