[前][次][番号順一覧][スレッド一覧]

ruby-changes:55686

From: Aaron <ko1@a...>
Date: Thu, 9 May 2019 07:56:29 +0900 (JST)
Subject: [ruby-changes:55686] Aaron Patterson: dc405eb737 (trunk): Pin finalizer table

https://git.ruby-lang.org/ruby.git/commit/?id=dc405eb737

From dc405eb737c178016167c8e64bdf32d27c5455f0 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Wed, 8 May 2019 15:55:35 -0700
Subject: 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).

diff --git a/gc.c b/gc.c
index da64ebb..ea4f54c 100644
--- a/gc.c
+++ b/gc.c
@@ -4424,7 +4424,7 @@ rb_gc_mark_stack_values(long n, const VALUE *values) https://github.com/ruby/ruby/blob/trunk/gc.c#L4424
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/gc.c#L4432
 }
 
 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 https://github.com/ruby/ruby/blob/trunk/gc.c#L4443
 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) https://github.com/ruby/ruby/blob/trunk/gc.c#L4461
     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) https://github.com/ruby/ruby/blob/trunk/gc.c#L4477
     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) https://github.com/ruby/ruby/blob/trunk/gc.c#L5302
     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);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]