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

ruby-changes:19960

From: nari <ko1@a...>
Date: Sat, 11 Jun 2011 19:52:03 +0900 (JST)
Subject: [ruby-changes:19960] nari:r32007 (trunk): * gc.c: expand heap if initial_heap_min_slots is bigger than

nari	2011-06-11 19:51:51 +0900 (Sat, 11 Jun 2011)

  New Revision: 32007

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

  Log:
    * gc.c: expand heap if initial_heap_min_slots is bigger than
      HEAP_MIN_SLOTS.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32006)
+++ ChangeLog	(revision 32007)
@@ -1,3 +1,8 @@
+Sat Jun 11 19:40:45 2011  Narihiro Nakamura  <authornari@g...>
+
+	* gc.c: expand heap if initial_heap_min_slots is bigger than
+	  HEAP_MIN_SLOTS.
+
 Sat Jun 11 19:42:50 2011  WATANABE Hirofumi  <eban@r...>
 
 	* ChangeLog (vim): set shiftwidth to 2.
Index: gc.c
===================================================================
--- gc.c	(revision 32006)
+++ gc.c	(revision 32007)
@@ -86,41 +86,6 @@
 static unsigned int initial_heap_min_slots = HEAP_MIN_SLOTS;
 static unsigned int initial_free_min       = FREE_MIN;
 
-void
-rb_gc_set_params(void)
-{
-    char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr;
-
-    if (rb_safe_level() > 0) return;
-
-    malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
-    if (malloc_limit_ptr != NULL) {
-	int malloc_limit_i = atoi(malloc_limit_ptr);
-	printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit);
-	if (malloc_limit_i > 0) {
-	    initial_malloc_limit = malloc_limit_i;
-	}
-    }
-
-    heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
-    if (heap_min_slots_ptr != NULL) {
-	int heap_min_slots_i = atoi(heap_min_slots_ptr);
-	printf("heap_min_slots=%d (%d)\n", heap_min_slots_i, initial_heap_min_slots);
-	if (heap_min_slots_i > 0) {
-	    initial_heap_min_slots = heap_min_slots_i;
-	}
-    }
-
-    free_min_ptr = getenv("RUBY_FREE_MIN");
-    if (free_min_ptr != NULL) {
-	int free_min_i = atoi(free_min_ptr);
-	printf("free_min=%d (%d)\n", free_min_i, initial_free_min);
-	if (free_min_i > 0) {
-	    initial_free_min = free_min_i;
-	}
-    }
-}
-
 #define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
 
 #define MARK_STACK_MAX 1024
@@ -439,6 +404,44 @@
     return objspace;
 }
 
+static void initial_expand_heap(rb_objspace_t *objspace);
+
+void
+rb_gc_set_params(void)
+{
+    char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr;
+
+    if (rb_safe_level() > 0) return;
+
+    malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
+    if (malloc_limit_ptr != NULL) {
+	int malloc_limit_i = atoi(malloc_limit_ptr);
+	printf("malloc_limit=%d (%d)\n", malloc_limit_i, initial_malloc_limit);
+	if (malloc_limit_i > 0) {
+	    initial_malloc_limit = malloc_limit_i;
+	}
+    }
+
+    heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
+    if (heap_min_slots_ptr != NULL) {
+	int heap_min_slots_i = atoi(heap_min_slots_ptr);
+	printf("heap_min_slots=%d (%d)\n", heap_min_slots_i, initial_heap_min_slots);
+	if (heap_min_slots_i > 0) {
+	    initial_heap_min_slots = heap_min_slots_i;
+	}
+    }
+
+    free_min_ptr = getenv("RUBY_FREE_MIN");
+    if (free_min_ptr != NULL) {
+	int free_min_i = atoi(free_min_ptr);
+	printf("free_min=%d (%d)\n", free_min_i, initial_free_min);
+	if (free_min_i > 0) {
+	    initial_free_min = free_min_i;
+	}
+    }
+    initial_expand_heap(&rb_objspace);
+}
+
 static void gc_sweep(rb_objspace_t *);
 static void slot_sweep(rb_objspace_t *, struct heaps_slot *);
 static void gc_clear_mark_on_sweep_slots(rb_objspace_t *);
@@ -1058,13 +1061,11 @@
 }
 
 static void
-init_heap(rb_objspace_t *objspace)
+add_heap_slots(rb_objspace_t *objspace, int add)
 {
-    size_t add, i;
+    int i;
 
-    add = initial_heap_min_slots / HEAP_OBJ_LIMIT;
-
-    if (!add) {
+    if (add < 1) {
         add = 1;
     }
 
@@ -1075,12 +1076,33 @@
     for (i = 0; i < add; i++) {
         assign_heap_slot(objspace);
     }
+}
+
+static void
+init_heap(rb_objspace_t *objspace)
+{
+    int add;
+
+    add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
+    add_heap_slots(objspace, add);
+
     heaps_inc = 0;
     objspace->profile.invoke_time = getrusage_time();
     finalizer_table = st_init_numtable();
 }
 
 static void
+initial_expand_heap(rb_objspace_t *objspace)
+{
+    int add;
+
+    add = ((initial_heap_min_slots / HEAP_OBJ_LIMIT) - heaps_used);
+    if (add > 0) {
+        add_heap_slots(objspace, add);
+    }
+}
+
+static void
 set_heaps_increment(rb_objspace_t *objspace)
 {
     size_t next_heaps_length = (size_t)(heaps_used * 1.8);
@@ -2563,7 +2585,6 @@
     init_heap(&rb_objspace);
 }
 
-
 static VALUE
 lazy_sweep_enable(void)
 {

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

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