ruby-changes:57291
From: Aaron <ko1@a...>
Date: Tue, 27 Aug 2019 03:33:20 +0900 (JST)
Subject: [ruby-changes:57291] Aaron Patterson: 09d8e06b33 (master): Try only updating hash value references
https://git.ruby-lang.org/ruby.git/commit/?id=09d8e06b33 From 09d8e06b335d7647fa5e0385980ba3f1a67a592b Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Mon, 26 Aug 2019 11:31:52 -0700 Subject: Try only updating hash value references I'm afraid the keys to this hash are just integers, and those integers may look like VALUE pointers when they are not. Since we don't mark the keys to this hash, it's probably safe to say that none of them have moved, so we shouldn't try to update the references either. diff --git a/gc.c b/gc.c index f7b770b..4d8ced7 100644 --- a/gc.c +++ b/gc.c @@ -7769,6 +7769,41 @@ hash_foreach_replace(st_data_t key, st_data_t value, st_data_t argp, int error) https://github.com/ruby/ruby/blob/trunk/gc.c#L7769 return ST_CONTINUE; } +static int +hash_replace_ref_value(st_data_t *key, st_data_t *value, st_data_t argp, int existing) +{ + rb_objspace_t *objspace = (rb_objspace_t *)argp; + + if (gc_object_moved_p(objspace, (VALUE)*value)) { + *value = rb_gc_location((VALUE)*value); + } + + return ST_CONTINUE; +} + +static int +hash_foreach_replace_value(st_data_t key, st_data_t value, st_data_t argp, int error) +{ + rb_objspace_t *objspace; + + objspace = (rb_objspace_t *)argp; + + if (gc_object_moved_p(objspace, (VALUE)value)) { + return ST_REPLACE; + } + return ST_CONTINUE; +} + +static void +gc_update_tbl_refs(rb_objspace_t * objspace, st_table *tbl) +{ + if (!tbl || tbl->num_entries == 0) return; + + if (st_foreach_with_replace(tbl, hash_foreach_replace_value, hash_replace_ref_value, (st_data_t)objspace)) { + rb_raise(rb_eRuntimeError, "hash modified during iteration"); + } +} + static void gc_update_table_refs(rb_objspace_t * objspace, st_table *tbl) { @@ -8020,7 +8055,7 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8055 } if (!RCLASS_EXT(obj)) break; if (RCLASS_IV_TBL(obj)) { - gc_update_table_refs(objspace, RCLASS_IV_TBL(obj)); + gc_update_tbl_refs(objspace, RCLASS_IV_TBL(obj)); } update_class_ext(objspace, RCLASS_EXT(obj)); update_const_tbl(objspace, RCLASS_CONST_TBL(obj)); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/