summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-07 13:34:53 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-07 13:34:53 +0000
commit28221e3584c62482359aa9294d4b690d26cfb852 (patch)
tree9d52ccaf1d79c495496e983044dd48714a4fc3ab
parent6c0822f0f5e934f6197f5a1be577764a74b30c7f (diff)
merge revision(s) 39811: [Backport #8146]
* gc.c: Avoid unnecessary heap growth. patched by tmm1(Aman Gupta). [Bug #8093] [ruby-core:53393] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--gc.c7
-rw-r--r--test/ruby/test_gc.rb14
-rw-r--r--version.h2
4 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e605a5537e..5e7345511f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Apr 7 22:27:12 2013 Narihiro Nakamura <authornari@gmail.com>
+
+ * 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@ruby-lang.org>
* parse.y (simple_re_meta): escape all closing characters, not only
diff --git a/gc.c b/gc.c
index 4831669dc7..acd9af95b0 100644
--- a/gc.c
+++ b/gc.c
@@ -225,6 +225,7 @@ typedef struct rb_objspace {
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)
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 *objspace)
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, VALUE ptr)
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)
objspace->mark_func_data = 0;
gc_prof_mark_timer_start(objspace);
+ objspace->heap.marked_num = 0;
objspace->count++;
SET_STACK_END;
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 62ae7ae5be..e3186c9a44 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -146,4 +146,18 @@ class TestGc < Test::Unit::TestCase
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
diff --git a/version.h b/version.h
index 6dec968eca..6a853706b3 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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