Forum: Ruby-core [Open] [RFC] README.EXT: document rb_gc_register_mark_object

18813f71506ebad74179bf8c5a136696?d=identicon&s=25 unknown (Guest)
on 2014-06-02 07:38
(Received via mailing list)
Issue #9894 has been reported by Eric Wong.

----------------------------------------
Feature #9894: [RFC] README.EXT: document rb_gc_register_mark_object
https://bugs.ruby-lang.org/issues/9894

* Author: Eric Wong
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
 Any comment on officially supporting this as part of the C API?

 diff --git a/README.EXT b/README.EXT
 index d66d6c5..dded850 100644
 --- a/README.EXT
 +++ b/README.EXT
 @@ -1176,6 +1176,12 @@ void rb_global_variable(VALUE *var)

    Tells GC to protect these variables.

 +void rb_gc_register_mark_object(VALUE val)
 +
 +  Tells GC to protect the object referenced by val.  This requires
less
 +  memory to track than rb_global_variable, but may only be used if the
C
 +  variable never changes.
 +
  == Constant Definition

  void rb_define_const(VALUE klass, const char *name, VALUE val) ::
 --
 Eric Wong
18813f71506ebad74179bf8c5a136696?d=identicon&s=25 Eric Wong (Guest)
on 2014-08-04 00:49
(Received via mailing list)
I tried making rb_gc_register_address work transparently but wasn't able
to measure any difference with unicorn.  unicorn uses a few global
const strings for common HTTP headers, but maybe not enough to matter
for this patch.

This patch is probably pointless, but in case somebody else wants to try
and show it makes a difference, it is here:

--- a/gc.c
+++ b/gc.c
@@ -5154,13 +5154,15 @@ rb_gc_register_mark_object(VALUE obj)
 void
 rb_gc_register_address(VALUE *addr)
 {
-    rb_objspace_t *objspace = &rb_objspace;
-    struct gc_list *tmp;
-
-    tmp = ALLOC(struct gc_list);
-    tmp->next = global_list;
-    tmp->varptr = addr;
-    global_list = tmp;
+    if (OBJ_FROZEN(*addr)) {
+  rb_gc_register_mark_object(*addr);
+    } else {
+  rb_objspace_t *objspace = &rb_objspace;
+  struct gc_list *tmp = ALLOC(struct gc_list);
+  tmp->next = global_list;
+  tmp->varptr = addr;
+  global_list = tmp;
+    }
 }

 void
308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 SASADA Koichi (Guest)
on 2014-08-04 02:50
(Received via mailing list)
(2014/08/04 7:48), Eric Wong wrote:
> -    tmp = ALLOC(struct gc_list);
> +  global_list = tmp;
> +    }
>  }
>
>  void

This patch does not work. You should not use
rb_gc_register_mark_object() because *addr is mutable.
This topic is locked and can not be replied to.