ruby-changes:28124
From: nagachika <ko1@a...>
Date: Sun, 7 Apr 2013 22:35:07 +0900 (JST)
Subject: [ruby-changes:28124] nagachika:r40176 (ruby_2_0_0): merge revision(s) 39811: [Backport #8146]
nagachika 2013-04-07 22:34:53 +0900 (Sun, 07 Apr 2013) New Revision: 40176 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40176 Log: merge revision(s) 39811: [Backport #8146] * gc.c: Avoid unnecessary heap growth. patched by tmm1(Aman Gupta). [Bug #8093] [ruby-core:53393] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/gc.c branches/ruby_2_0_0/test/ruby/test_gc.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 40175) +++ ruby_2_0_0/ChangeLog (revision 40176) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sun Apr 7 22:27:12 2013 Narihiro Nakamura <authornari@g...> + + * gc.c: Avoid unnecessary heap growth. patched by tmm1(Aman Gupta). + [Bug #8093] [ruby-core:53393] + Sun Apr 7 03:01:49 2013 Nobuyoshi Nakada <nobu@r...> * parse.y (simple_re_meta): escape all closing characters, not only Index: ruby_2_0_0/gc.c =================================================================== --- ruby_2_0_0/gc.c (revision 40175) +++ ruby_2_0_0/gc.c (revision 40176) @@ -225,6 +225,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/gc.c#L225 struct heaps_free_bitmap *free_bitmap; RVALUE *range[2]; struct heaps_header *freed; + size_t marked_num; size_t free_num; size_t free_min; size_t final_num; @@ -1994,7 +1995,7 @@ after_gc_sweep(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/gc.c#L1995 inc = ATOMIC_SIZE_EXCHANGE(malloc_increase, 0); if (inc > malloc_limit) { malloc_limit += - (size_t)((inc - malloc_limit) * (double)objspace_live_num(objspace) / (heaps_used * HEAP_OBJ_LIMIT)); + (size_t)((inc - malloc_limit) * (double)objspace->heap.marked_num / (heaps_used * HEAP_OBJ_LIMIT)); if (malloc_limit < initial_malloc_limit) malloc_limit = initial_malloc_limit; } @@ -2067,7 +2068,7 @@ gc_prepare_free_objects(rb_objspace_t *o https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/gc.c#L2068 gc_marks(objspace); before_gc_sweep(objspace); - if (objspace->heap.free_min > (heaps_used * HEAP_OBJ_LIMIT - objspace_live_num(objspace))) { + if (objspace->heap.free_min > (heaps_used * HEAP_OBJ_LIMIT - objspace->heap.marked_num)) { set_heaps_increment(objspace); } @@ -2555,6 +2556,7 @@ gc_mark_ptr(rb_objspace_t *objspace, VAL https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/gc.c#L2556 register uintptr_t *bits = GET_HEAP_BITMAP(ptr); if (MARKED_IN_BITMAP(bits, ptr)) return 0; MARK_IN_BITMAP(bits, ptr); + objspace->heap.marked_num++; return 1; } @@ -2915,6 +2917,7 @@ gc_marks(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/gc.c#L2917 objspace->mark_func_data = 0; gc_prof_mark_timer_start(objspace); + objspace->heap.marked_num = 0; objspace->count++; SET_STACK_END; Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 40175) +++ ruby_2_0_0/version.h (revision 40176) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2013-04-07" -#define RUBY_PATCHLEVEL 109 +#define RUBY_PATCHLEVEL 110 #define RUBY_RELEASE_YEAR 2013 #define RUBY_RELEASE_MONTH 4 Index: ruby_2_0_0/test/ruby/test_gc.rb =================================================================== --- ruby_2_0_0/test/ruby/test_gc.rb (revision 40175) +++ ruby_2_0_0/test/ruby/test_gc.rb (revision 40176) @@ -146,4 +146,18 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_gc.rb#L146 ObjectSpace.define_finalizer(Thread.main) { p 'finalize' } EOS end + + def test_expand_heap + assert_separately %w[--disable-gem], __FILE__, __LINE__, <<-'eom' + base_length = GC.stat[:heap_length] + (base_length * 500).times{ 'a' } + GC.start + assert_equal base_length, GC.stat[:heap_length], "invalid heap expanding" + + a = [] + (base_length * 500).times{ a << 'a' } + GC.start + assert base_length < GC.stat[:heap_length] + eom + end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r39811 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/