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

ruby-changes:31915

From: nobu <ko1@a...>
Date: Thu, 5 Dec 2013 10:47:19 +0900 (JST)
Subject: [ruby-changes:31915] nobu:r43994 (trunk): gc.c: flush all deferred finalizers

nobu	2013-12-05 10:47:12 +0900 (Thu, 05 Dec 2013)

  New Revision: 43994

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

  Log:
    gc.c: flush all deferred finalizers
    
    * gc.c (finalize_deferred): flush all deferred finalizers while other
      finalizers can get ready to run newly by lazy sweep.
      [ruby-core:58833] [Bug #9205]

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/test/ruby/test_gc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43993)
+++ ChangeLog	(revision 43994)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec  5 10:47:09 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* gc.c (finalize_deferred): flush all deferred finalizers while other
+	  finalizers can get ready to run newly by lazy sweep.
+	  [ruby-core:58833] [Bug #9205]
+
 Thu Dec  5 09:07:59 2013  Aman Gupta <ruby@t...>
 
 	* gc.c (ruby_gc_set_params): Accept safe_level argument so GC tuning
Index: gc.c
===================================================================
--- gc.c	(revision 43993)
+++ gc.c	(revision 43994)
@@ -2055,10 +2055,9 @@ finalize_list(rb_objspace_t *objspace, R https://github.com/ruby/ruby/blob/trunk/gc.c#L2055
 static void
 finalize_deferred(rb_objspace_t *objspace)
 {
-    RVALUE *p = heap_pages_deferred_final;
-    heap_pages_deferred_final = 0;
+    RVALUE *p;
 
-    if (p) {
+    while ((p = ATOMIC_PTR_EXCHANGE(heap_pages_deferred_final, 0)) != 0) {
 	finalize_list(objspace, p);
     }
 }
Index: test/ruby/test_gc.rb
===================================================================
--- test/ruby/test_gc.rb	(revision 43993)
+++ test/ruby/test_gc.rb	(revision 43994)
@@ -238,4 +238,18 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L238
     assert_not_nil GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT]
     assert_not_nil GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
   end
+
+  def test_sweep_in_finalizer
+    bug9205 = '[ruby-core:58833] [Bug #9205]'
+    100.times do
+      assert_ruby_status([], <<-'end;', bug9205)
+        raise_proc = proc do |id|
+          GC.start
+        end
+        1000.times do
+          ObjectSpace.define_finalizer(Object.new, raise_proc)
+        end
+      end;
+    end
+  end
 end

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

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