[#42369] [BUG: trunk] Lazy sweep and ObjectSpace.each_object — SASADA Koichi <ko1@...>

 ささだです。

14 messages 2010/10/13

[#42375] [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Yui NARUSE <redmine@...>

Feature #3946: Array#packのqQ指定子に機種依存サイズフラグ!を追加

19 messages 2010/10/14
[#42380] Re: [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Tanaka Akira <akr@...> 2010/10/14

2010年10月14日15:36 Yui NARUSE <redmine@ruby-lang.org>:

[#42381] Re: [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — "NARUSE, Yui" <naruse@...> 2010/10/14

(2010/10/14 21:07), Tanaka Akira wrote:

[#42619] [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Usaku NAKAMURA <redmine@...> 2010/11/25

チケット #3946 が更新されました。 (by Usaku NAKAMURA)

[#42376] [Ruby 1.9-Feature#3947][Open] Array#packのにエンディアン指定修飾子</>を追加 — Yui NARUSE <redmine@...>

Feature #3947: Array#packのにエンディアン指定修飾子</>を追加

9 messages 2010/10/14

[#42464] [Ruby 1.9-Bug#3990][Assigned] tests of rexml/rss reports many errors and failures without iconv — Usaku NAKAMURA <redmine@...>

Bug #3990: tests of rexml/rss reports many errors and failures without iconv

40 messages 2010/10/27
[#42500] [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <redmine@...> 2010/10/30

チケット #3990 が更新されました。 (by Kouhei Sutou)

[#42510] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/01

成瀬です。

[#42514] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42515] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/02

(2010/11/02 21:50), Kouhei Sutou wrote:

[#42516] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42517] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/02

成瀬です。

[#42518] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42519] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/03

成瀬です。

[#42543] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/06

須藤です。

[#42548] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/07

(2010/11/06 12:10), Kouhei Sutou wrote:

[#42549] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/07

須藤です。

[#42572] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/13

成瀬です。

[#42592] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/18

須藤です。

[#42593] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/18

成瀬です。

[#42607] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/20

須藤です。

[#42608] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/20

成瀬です。

[#42610] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/20

須藤です。

[#42611] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/20

成瀬です。

[#42613] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/21

須藤です。

[#42614] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/21

成瀬です。

[ruby-dev:42430] Re: [BUG: trunk] Lazy sweep and ObjectSpace.each_object

From: Narihiro Nakamura <authornari@...>
Date: 2010-10-19 05:54:51 UTC
List: ruby-dev #42430
nariです。

>  これだと、例えば例外が出た場合、dont_lazy_sweep が TRUE のままになって
> しまうような気がします。ensure で囲まないと。
>

ぉぉ、そうですね…。ご指摘ありがとうございます。
そのようなパッチを作ってみました。本メールの一番最後に貼り付けておきます。

> # 余談
>
> ちょっと関係ないですが、gc_lazy_sweep() という関数は、下記の挙動だと思
> うのですが;
>
> ・もし、遅延した slot があれば、sweep をする
> これで、freelist が NULL でなければ、ここで終わり
> ・GC を開始(mark)
> ・遅延 sweep をして、結果を返す
>
> sweep という関数で mark までしちゃうのはいいでしょうか。
>

なるほど。
関数名にgc_というプレフィクスが付いているので、マークしてもいいのかなと
か、そういう言い訳を思いついたのですがやっぱりダメですね。

> あまり、対案はないのですが、なんとなく、garbage_collect() を 今の
> gc_lazy_sweep() として、今の garbage_collect() を、
> garbage_collect_eager() みたいにしてしまうのはどうだろう、と思いました。

garbage_collect_eager() よりも garbage_collect_full() の方が馴染み
があるのかなと思いました。こちらの方も暇を見つけて直しておきます。

パッチ:
diff --git a/gc.c b/gc.c
index b011f4a..ad49fd5 100644
--- a/gc.c
+++ b/gc.c
@@ -332,6 +332,7 @@ typedef struct rb_objspace {
     } heap;
     struct {
 	int dont_gc;
+	int dont_lazy_sweep;
 	int during_gc;
     } flags;
     struct {
@@ -2040,6 +2041,17 @@ lazy_sweep(rb_objspace_t *objspace)
     return FALSE;
 }

+static void
+rest_sweep(rb_objspace_t *objspace)
+{
+    if (objspace->heap.sweep_slots) {
+       while (objspace->heap.sweep_slots) {
+           lazy_sweep(objspace);
+       }
+       after_gc_sweep(objspace);
+    }
+}
+
 static void gc_marks(rb_objspace_t *objspace);

 static int
@@ -2047,6 +2059,9 @@ gc_lazy_sweep(rb_objspace_t *objspace)
 {
     int res;

+    if (objspace->flags.dont_lazy_sweep)
+        return garbage_collect(objspace);
+
     INIT_GC_PROF_PARAMS;

     if (!ready_to_gc(objspace)) return TRUE;
@@ -2489,6 +2504,55 @@ Init_heap(void)
     init_heap(&rb_objspace);
 }

+
+static VALUE
+lazy_sweep_enable(void)
+{
+    rb_objspace_t *objspace = &rb_objspace;
+
+    objspace->flags.dont_lazy_sweep = FALSE;
+    return Qnil;
+}
+
+static VALUE
+objspace_each_objects(VALUE arg)
+{
+    size_t i;
+    RVALUE *membase = 0;
+    RVALUE *pstart, *pend;
+    rb_objspace_t *objspace = &rb_objspace;
+    VALUE *args = (VALUE *)arg;
+    volatile VALUE v;
+
+    i = 0;
+    while (i < heaps_used) {
+	while (0 < i && (uintptr_t)membase <
(uintptr_t)objspace->heap.sorted[i-1].slot->membase)
+	    i--;
+	while (i < heaps_used &&
(uintptr_t)objspace->heap.sorted[i].slot->membase <=
(uintptr_t)membase )
+	    i++;
+	if (heaps_used <= i)
+	  break;
+	membase = objspace->heap.sorted[i].slot->membase;
+
+	pstart = objspace->heap.sorted[i].slot->slot;
+	pend = pstart + objspace->heap.sorted[i].slot->limit;
+
+	for (; pstart != pend; pstart++) {
+	    if (pstart->as.basic.flags) {
+		v = (VALUE)pstart; /* acquire to save this object */
+		break;
+	    }
+	}
+	if (pstart != pend) {
+	    if ((*(int (*)(void *, void *, size_t, void *))args[0])(pstart,
pend, sizeof(RVALUE), (void *)args[1])) {
+		return;
+	    }
+	}
+    }
+
+    return Qnil;
+}
+
 /*
  * rb_objspace_each_objects() is special C API to walk through
  * Ruby object space.  This C API is too difficult to use it.
@@ -2530,39 +2594,15 @@ rb_objspace_each_objects(int (*callback)(void
*vstart, void *vend,
 					 size_t stride, void *d),
 			 void *data)
 {
-    size_t i;
-    RVALUE *membase = 0;
-    RVALUE *pstart, *pend;
+    VALUE args[2];
     rb_objspace_t *objspace = &rb_objspace;
-    volatile VALUE v;
-
-    i = 0;
-    while (i < heaps_used) {
-	while (0 < i && (uintptr_t)membase <
(uintptr_t)objspace->heap.sorted[i-1].slot->membase)
-	    i--;
-	while (i < heaps_used &&
(uintptr_t)objspace->heap.sorted[i].slot->membase <=
(uintptr_t)membase )
-	    i++;
-	if (heaps_used <= i)
-	  break;
-	membase = objspace->heap.sorted[i].slot->membase;

-	pstart = objspace->heap.sorted[i].slot->slot;
-	pend = pstart + objspace->heap.sorted[i].slot->limit;
-
-	for (; pstart != pend; pstart++) {
-	    if (pstart->as.basic.flags) {
-		v = (VALUE)pstart; /* acquire to save this object */
-		break;
-	    }
-	}
-	if (pstart != pend) {
-	    if ((*callback)(pstart, pend, sizeof(RVALUE), data)) {
-		return;
-	    }
-	}
-    }
+    rest_sweep(objspace);
+    objspace->flags.dont_lazy_sweep = TRUE;

-    return;
+    args[0] = (VALUE)callback;
+    args[1] = (VALUE)data;
+    rb_ensure(objspace_each_objects, (VALUE)args, lazy_sweep_enable, Qnil);
 }

 struct os_each_struct {


-- 
Narihiro Nakamura (nari)

In This Thread