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

ruby-changes:34572

From: ko1 <ko1@a...>
Date: Wed, 2 Jul 2014 15:47:15 +0900 (JST)
Subject: [ruby-changes:34572] ko1:r46653 (trunk): * gc.c (gc_heap_lazy_sweep): simplify logic.

ko1	2014-07-02 15:47:10 +0900 (Wed, 02 Jul 2014)

  New Revision: 46653

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

  Log:
    * gc.c (gc_heap_lazy_sweep): simplify logic.
    * gc.c (gc_page_sweep): return TRUE if empty slots are available.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46652)
+++ ChangeLog	(revision 46653)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul  2 15:45:49 2014  Koichi Sasada  <ko1@a...>
+
+	* gc.c (gc_heap_lazy_sweep): simplify logic.
+
+	* gc.c (gc_page_sweep): return TRUE if empty slots are available.
+
 Wed Jul  2 09:48:42 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* logger.rb: removed unmaintain code.
Index: gc.c
===================================================================
--- gc.c	(revision 46652)
+++ gc.c	(revision 46653)
@@ -2788,7 +2788,9 @@ gc_setup_mark_bits(struct heap_page *pag https://github.com/ruby/ruby/blob/trunk/gc.c#L2788
 #endif
 }
 
-static inline void
+/* TRUE : has empty slots                                             */
+/* FALSE: no empty slots (or move to tomb heap because no live slots) */
+static inline int
 gc_page_sweep(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_page)
 {
     int i;
@@ -2858,20 +2860,6 @@ gc_page_sweep(rb_objspace_t *objspace, r https://github.com/ruby/ruby/blob/trunk/gc.c#L2860
     }
 #endif
 
-    if (final_slots + freed_slots + empty_slots == sweep_page->limit) {
-	/* there are no living objects -> move this page to tomb heap */
-	heap_unlink_page(objspace, heap, sweep_page);
-	heap_add_page(objspace, heap_tomb, sweep_page);
-    }
-    else {
-	if (freed_slots + empty_slots > 0) {
-	    heap_add_freepage(objspace, heap, sweep_page);
-	}
-	else {
-	    sweep_page->free_next = NULL;
-	}
-    }
-
     heap_pages_swept_slots += freed_slots + empty_slots;
     objspace->profile.total_freed_object_num += freed_slots;
     heap_pages_final_slots += final_slots;
@@ -2890,6 +2878,22 @@ gc_page_sweep(rb_objspace_t *objspace, r https://github.com/ruby/ruby/blob/trunk/gc.c#L2878
     }
 
     rgengc_report(1, objspace, "page_sweep: end.\n");
+
+    if (final_slots + freed_slots + empty_slots == sweep_page->limit) {
+	/* there are no living objects -> move this page to tomb heap */
+	heap_unlink_page(objspace, heap, sweep_page);
+	heap_add_page(objspace, heap_tomb, sweep_page);
+    }
+    else {
+	if (freed_slots + empty_slots > 0) {
+	    return TRUE; /* has empty slots */
+	}
+	else {
+	    sweep_page->free_next = NULL;
+	}
+    }
+
+    return FALSE;
 }
 
 /* allocate additional minimum page to work */
@@ -3089,7 +3093,6 @@ static int https://github.com/ruby/ruby/blob/trunk/gc.c#L3093
 gc_heap_lazy_sweep(rb_objspace_t *objspace, rb_heap_t *heap)
 {
     struct heap_page *page = heap->sweep_pages, *next;
-    int result = FALSE;
 
     if (page == NULL) return FALSE;
 
@@ -3100,23 +3103,23 @@ gc_heap_lazy_sweep(rb_objspace_t *objspa https://github.com/ruby/ruby/blob/trunk/gc.c#L3103
     while (page) {
 	heap->sweep_pages = next = page->next;
 
-	gc_page_sweep(objspace, heap, page);
-
-	if (!next) gc_after_sweep(objspace);
-
-	if (heap->free_pages) {
-            result = TRUE;
+	if (gc_page_sweep(objspace, heap, page)) {
+	    heap_add_freepage(objspace, heap, page);
 	    break;
-        }
+	}
 
 	page = next;
     }
 
+    if (heap->sweep_pages == NULL) {
+	gc_after_sweep(objspace);
+    }
+
 #if GC_ENABLE_LAZY_SWEEP
     gc_prof_sweep_timer_stop(objspace);
 #endif
 
-    return result;
+    return heap->free_pages != NULL;
 }
 
 static void

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

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