Skip to content

Commit 9f8505f

Browse files
peterzhu2118matzbot
authored andcommitted
[ruby/mmtk] Implement object movement support for finalizer table
ruby/mmtk@e5e2c1c347
1 parent 6f38d3d commit 9f8505f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

gc/mmtk/mmtk.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ RB_THREAD_LOCAL_SPECIFIER VALUE marking_parent_object;
9191

9292
#include <pthread.h>
9393

94+
static inline VALUE rb_mmtk_call_object_closure(VALUE obj, bool pin);
95+
9496
static void
9597
rb_mmtk_init_gc_worker_thread(MMTk_VMWorkerThread gc_thread_tls)
9698
{
@@ -361,15 +363,22 @@ make_final_job(struct objspace *objspace, VALUE obj, VALUE table)
361363
}
362364

363365
static int
364-
rb_mmtk_update_finalizer_table_i(st_data_t key, st_data_t value, st_data_t data)
366+
rb_mmtk_update_finalizer_table_i(st_data_t key, st_data_t value, st_data_t data, int error)
365367
{
366368
RUBY_ASSERT(RB_FL_TEST(key, RUBY_FL_FINALIZE));
367369
RUBY_ASSERT(mmtk_is_reachable((MMTk_ObjectReference)value));
368370
RUBY_ASSERT(RB_BUILTIN_TYPE(value) == T_ARRAY);
369371

370372
struct objspace *objspace = (struct objspace *)data;
371373

372-
if (!mmtk_is_reachable((MMTk_ObjectReference)key)) {
374+
if (mmtk_is_reachable((MMTk_ObjectReference)key)) {
375+
VALUE new_key_location = rb_mmtk_call_object_closure((VALUE)key, false);
376+
377+
if (new_key_location != key) {
378+
return ST_REPLACE;
379+
}
380+
}
381+
else {
373382
make_final_job(objspace, (VALUE)key, (VALUE)value);
374383

375384
rb_postponed_job_trigger(objspace->finalizer_postponed_job);
@@ -380,13 +389,25 @@ rb_mmtk_update_finalizer_table_i(st_data_t key, st_data_t value, st_data_t data)
380389
return ST_CONTINUE;
381390
}
382391

392+
static int
393+
rb_mmtk_update_finalizer_table_replace_i(st_data_t *key, st_data_t *value, st_data_t data, int existing)
394+
{
395+
*key = rb_mmtk_call_object_closure((VALUE)*key, false);
396+
397+
return ST_CONTINUE;
398+
}
399+
383400
static void
384401
rb_mmtk_update_finalizer_table(void)
385402
{
386403
struct objspace *objspace = rb_gc_get_objspace();
387404

388-
// TODO: replace with st_foreach_with_replace when GC is moving
389-
st_foreach(objspace->finalizer_table, rb_mmtk_update_finalizer_table_i, (st_data_t)objspace);
405+
st_foreach_with_replace(
406+
objspace->finalizer_table,
407+
rb_mmtk_update_finalizer_table_i,
408+
rb_mmtk_update_finalizer_table_replace_i,
409+
(st_data_t)objspace
410+
);
390411
}
391412

392413
static int

0 commit comments

Comments
 (0)