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

ruby-changes:37603

From: ko1 <ko1@a...>
Date: Sun, 22 Feb 2015 11:00:49 +0900 (JST)
Subject: [ruby-changes:37603] ko1:r49684 (trunk): * gc.c (rb_objspace_call_finalizer): control GC execution during

ko1	2015-02-22 11:00:40 +0900 (Sun, 22 Feb 2015)

  New Revision: 49684

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

  Log:
    * gc.c (rb_objspace_call_finalizer): control GC execution during
      force firnalizations at the end of interpreter process.
      [Bug #10768]
      1) Prohibit incremental GC while running Ruby-level finalizers
         to avoid any danger.
      2) Prohibit GC while invoking T_DATA/T_FILE data structure
         because these operations break object relations consistency.
      This patch can introduce another memory consuming issue because
      Ruby-level finalizers can run after (2), GC is disabled.
      However, basically object consistency was broken at (2) as I
      described above. So that running Ruby-level finalizers contains
      danger originally. Because of this point, I need to suggest to
      remove these 3 lines (invoking remaining finalizers). And add a
      rule to add that finalizers should not add new finalizers, or
      say there is no guarantee to invoke finalizers that added by
      another finalizer.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49683)
+++ ChangeLog	(revision 49684)
@@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Feb 22 10:43:37 2015  Koichi Sasada  <ko1@a...>
+
+	* gc.c (rb_objspace_call_finalizer): control GC execution during
+	  force firnalizations at the end of interpreter process.
+	  [Bug #10768]
+
+	  1) Prohibit incremental GC while running Ruby-level finalizers
+	     to avoid any danger.
+	  2) Prohibit GC while invoking T_DATA/T_FILE data structure
+	     because these operations break object relations consistency.
+
+	  This patch can introduce another memory consuming issue because
+	  Ruby-level finalizers can run after (2), GC is disabled.
+	  However, basically object consistency was broken at (2) as I
+	  described above. So that running Ruby-level finalizers contains
+	  danger originally. Because of this point, I need to suggest to
+	  remove these 3 lines (invoking remaining finalizers). And add a
+	  rule to add that finalizers should not add new finalizers, or
+	  say there is no guarantee to invoke finalizers that added by
+	  another finalizer.
+
 Sun Feb 22 04:07:05 2015  Zachary Scott  <e@z...>
 
         * ext/openssl/ossl_asn1.c: [DOC] RDoc formatting fixes for
Index: gc.c
===================================================================
--- gc.c	(revision 49683)
+++ gc.c	(revision 49684)
@@ -1209,10 +1209,8 @@ static void heap_page_free(rb_objspace_t https://github.com/ruby/ruby/blob/trunk/gc.c#L1209
 void
 rb_objspace_free(rb_objspace_t *objspace)
 {
-#if 0
     if (is_lazy_sweeping(heap_eden))
 	rb_bug("lazy sweeping underway when freeing object space");
-#endif
 
     if (objspace->profile.records) {
 	free(objspace->profile.records);
@@ -2568,6 +2566,10 @@ rb_objspace_call_finalizer(rb_objspace_t https://github.com/ruby/ruby/blob/trunk/gc.c#L2566
     finalize_deferred(objspace);
     assert(heap_pages_deferred_final == 0);
 
+    gc_rest(objspace);
+    /* prohibit incremental GC */
+    objspace->flags.dont_incremental = 1;
+
     /* force to run finalizer */
     while (finalizer_table->num_entries) {
 	struct force_finalize_list *list = 0;
@@ -2582,10 +2584,13 @@ rb_objspace_call_finalizer(rb_objspace_t https://github.com/ruby/ruby/blob/trunk/gc.c#L2584
 	}
     }
 
-    /* finalizers are part of garbage collection */
+    /* prohibit GC because force T_DATA finalizers can break an object graph consistency */
+    dont_gc = 1;
+
+    /* running data/file finalizers are part of garbage collection */
     gc_enter(objspace, "rb_objspace_call_finalizer");
 
-    /* run data object's finalizers */
+    /* run data/file object's finalizers */
     for (i = 0; i < heap_allocated_pages; i++) {
 	p = heap_pages_sorted[i]->start; pend = p + heap_pages_sorted[i]->total_slots;
 	while (p < pend) {
@@ -2625,14 +2630,6 @@ rb_objspace_call_finalizer(rb_objspace_t https://github.com/ruby/ruby/blob/trunk/gc.c#L2630
     st_free_table(finalizer_table);
     finalizer_table = 0;
     ATOMIC_SET(finalizing, 0);
-
-#if 0
-    /*
-     * finish any lazy sweeps that may have been started
-     * when finalizing the objects in the heap
-     */
-    gc_rest(objspace);
-#endif
 }
 
 static inline int

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

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