From dc405eb737c178016167c8e64bdf32d27c5455f0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 8 May 2019 15:55:35 -0700 Subject: [PATCH] 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). --- gc.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/gc.c b/gc.c index da64ebb6d4..ea4f54ce0e 100644 --- a/gc.c +++ b/gc.c @@ -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);