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

ruby-changes:29986

From: ko1 <ko1@a...>
Date: Thu, 18 Jul 2013 16:18:34 +0900 (JST)
Subject: [ruby-changes:29986] ko1:r42038 (trunk): * array.c: add logging feature for RGenGC's write barrier unprotect

ko1	2013-07-18 16:18:22 +0900 (Thu, 18 Jul 2013)

  New Revision: 42038

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42038

  Log:
    * array.c: add logging feature for RGenGC's write barrier unprotect
      event.

  Modified files:
    trunk/ChangeLog
    trunk/array.c

Index: array.c
===================================================================
--- array.c	(revision 42037)
+++ array.c	(revision 42038)
@@ -11,6 +11,12 @@ https://github.com/ruby/ruby/blob/trunk/array.c#L11
 
 **********************************************************************/
 
+#define RGENGC_UNPROTECT_LOGGING 0
+#if RGENGC_UNPROTECT_LOGGING
+static void ary_unprotect_logging(unsigned long x, const char *filename, int line);
+#define RGENGC_LOGGING_WB_UNPROTECT ary_unprotect_logging
+#endif
+
 #include "ruby/ruby.h"
 #include "ruby/util.h"
 #include "ruby/st.h"
@@ -31,6 +37,45 @@ static ID id_cmp, id_div, id_power; https://github.com/ruby/ruby/blob/trunk/array.c#L37
 #define ARY_DEFAULT_SIZE 16
 #define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE))
 
+#if RGENGC_UNPROTECT_LOGGING
+static void ary_unprotect_logging(VALUE x, const char *filename, int line);
+static st_table *ary_unprotect_logging_table;
+
+static void
+ary_unprotect_logging(VALUE x, const char *filename, int line)
+{
+    if (OBJ_WB_PROTECTED(x)) {
+	char buff[0x100];
+	st_data_t cnt = 1;
+	char *ptr = buff;
+
+	snprintf(ptr, 0x100 - 1, "%s:%d", filename, line);
+
+	if (st_lookup(ary_unprotect_logging_table, (st_data_t)ptr, &cnt)) {
+	    cnt++;
+	}
+	else {
+	    ptr = (char *)malloc(strlen(buff) + 1);
+	    strcpy(ptr, buff);
+	}
+	st_insert(ary_unprotect_logging_table, (st_data_t)ptr, cnt);
+    }
+}
+
+static int
+ary_unprotect_logging_exit_func_i(st_data_t key, st_data_t val)
+{
+    fprintf(stderr, "%s\t%d\n", (char *)key, (int)val);
+    return ST_CONTINUE;
+}
+
+static void
+ary_unprotect_logging_exit_func(void)
+{
+    st_foreach(ary_unprotect_logging_table, ary_unprotect_logging_exit_func_i, 0);
+}
+#endif
+
 void
 rb_mem_clear(register VALUE *mem, register long size)
 {
@@ -5462,6 +5507,11 @@ Init_Array(void) https://github.com/ruby/ruby/blob/trunk/array.c#L5507
     rb_cArray  = rb_define_class("Array", rb_cObject);
     rb_include_module(rb_cArray, rb_mEnumerable);
 
+#if RGENGC_UNPROTECT_LOGGING
+    ary_unprotect_logging_table = st_init_strtable();
+    atexit(ary_unprotect_logging_exit_func);
+#endif
+
     rb_define_alloc_func(rb_cArray, empty_ary_alloc);
     rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
     rb_define_singleton_method(rb_cArray, "try_convert", rb_ary_s_try_convert, 1);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42037)
+++ ChangeLog	(revision 42038)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jul 18 16:16:17 2013  Koichi Sasada  <ko1@a...>
+
+	* array.c: add logging feature for RGenGC's write barrier unprotect
+	  event.
+
 Thu Jul 18 15:45:47 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (RUBY_SAFE_LEVEL_CHECK): make only

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

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