Project

General

Profile

Actions

Feature #9894

closed

[RFC] README.EXT: document rb_gc_register_mark_object

Added by normalperson (Eric Wong) almost 10 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:62862]

Description

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


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #9893: [RFC] README.EXT: document rb_gc_register_mark_objectClosedko1 (Koichi Sasada)06/02/2014Actions

Updated by hsbt (Hiroshi SHIBATA) almost 10 years ago

  • Status changed from Open to Closed

duprecated #9893

Updated by ko1 (Koichi Sasada) almost 10 years ago

(2014/05/31 4:56), Eric Wong wrote:

+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.
+

How about that?

Tells GC to protect the object referenced by val.

Another things are implementation details.

And I'm not sure the following sentence is needed.

but may only be used if the C
variable never changes.

I think it may assume global variables. But this API is independent from
C's global variables. I think this comment may be for
rb_global_variable users, but it is different API.

PS.
For our MVM development, we can not support rb_global_variable(). So I
want to make it obsolete.
This is why I introduce rb_gc_register_mark_object(). But not yet.

--
// SASADA Koichi at atdot dot net

Updated by normalperson (Eric Wong) almost 10 years ago

SASADA Koichi wrote:

(2014/05/31 4:56), Eric Wong wrote:

+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.
+

How about that?

Tells GC to protect the object referenced by val.

Another things are implementation details.

And I'm not sure the following sentence is needed.

but may only be used if the C
variable never changes.

I think it may assume global variables. But this API is independent from
C's global variables. I think this comment may be for
rb_global_variable users, but it is different API.

I think it is important to tell users how it is different from
rb_global_variable and when it is OK or not OK to use. So I think
the implementation details/difference from rb_global_variable is
important to prevent misuse.

May we consider this part of the supported C API?

PS.
For our MVM development, we can not support rb_global_variable(). So I
want to make it obsolete.
This is why I introduce rb_gc_register_mark_object(). But not yet.

Is MVM still happening? I haven't heard about it in a long time.

If so, we should move fstring and symbol table into the vm struct.

Updated by nagachika (Tomoyuki Chikanaga) almost 10 years ago

  • Has duplicate Feature #9893: [RFC] README.EXT: document rb_gc_register_mark_object added

Updated by normalperson (Eric Wong) over 9 years ago

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

Updated by ko1 (Koichi Sasada) over 9 years ago

(2014/08/04 7:48), Eric Wong wrote:

--- 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

This patch does not work. You should not use
rb_gc_register_mark_object() because *addr is mutable.

--
// SASADA Koichi at atdot dot net

Actions #7

Updated by naruse (Yui NARUSE) over 5 years ago

  • Status changed from Closed to Open
Actions #8

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Description updated (diff)
Actions #9

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r66534.


Mention rb_gc_register_mark_object [ci skip]

[Feature #9894]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0