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

ruby-changes:65142

From: Aaron <ko1@a...>
Date: Fri, 5 Feb 2021 02:49:23 +0900 (JST)
Subject: [ruby-changes:65142] 75b96c3a05 (master): Don't register non-heap allocated objects

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

From 75b96c3a056d9e50bdabd87fa4676e6aaffbcff0 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Wed, 3 Feb 2021 16:17:28 -0800
Subject: Don't register non-heap allocated objects

`rb_define_const` can add objects as "mark objects".  This is to make
code like this work:

  https://github.com/ruby/ruby/blob/33d6e92e0c6eaf1308ce7108e653c53bb5fb106c/ext/etc/etc.c#L1201

```
    rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
```

sPasswd is a heap allocated object that is also a C global, so we can't
move it (it needs to be pinned).  However, we have many calls to
`rb_define_const` that just pass in an integer like this:

```
rb_define_const(rb_cDBM, "WRITER",  INT2FIX(O_RDWR|RUBY_DBM_RW_BIT));
```

Non heap allocated objects like integers will never move, so there is no
reason to waste time in the GC marking / pinning them.
---
 gc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gc.c b/gc.c
index 2d76b54..30badf9 100644
--- a/gc.c
+++ b/gc.c
@@ -8051,6 +8051,9 @@ rb_gc_force_recycle(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8051
 void
 rb_gc_register_mark_object(VALUE obj)
 {
+    if (!is_pointer_to_heap(&rb_objspace, (void *)obj))
+        return;
+
     RB_VM_LOCK_ENTER();
     {
         VALUE ary_ary = GET_VM()->mark_object_ary;
-- 
cgit v1.1


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

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