diff options
author | tmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-04 10:05:40 +0000 |
---|---|---|
committer | tmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-04 10:05:40 +0000 |
commit | 907a03fee52b06760cec2d6fbd0dd2e693bef970 (patch) | |
tree | b2c85e80be1bc9b481422d37ca69d351b73d3a43 | |
parent | a24705cfa52d14470354600832d129c5b8af64a1 (diff) | |
download | ruby-907a03fee52b06760cec2d6fbd0dd2e693bef970.tar.gz |
gc.c: add objspace_free_num and make GC.stat[:heap_free_num] use it
* gc.c (objspace_free_num): new method for available/free slots on
heap. [ruby-core:57633] [Bug #8983]
* gc.c (gc_stat): change heap_free_num definition to use new method.
* test/ruby/test_gc.rb: test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | gc.c | 8 | ||||
-rw-r--r-- | test/ruby/test_gc.rb | 7 |
3 files changed, 21 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Fri Oct 4 19:02:01 2013 Aman Gupta <ruby@tmm1.net> + + * gc.c (objspace_free_num): new method for available/free slots on + heap. [ruby-core:57633] [Bug #8983] + * gc.c (gc_stat): change heap_free_num definition to use new method. + * test/ruby/test_gc.rb: test for above. + Fri Oct 4 18:53:42 2013 Aman Gupta <ruby@tmm1.net> * gc.c: add rb_objspace.limit to keep accurate count of total heap @@ -2259,6 +2259,12 @@ objspace_live_num(rb_objspace_t *objspace) return objspace->total_allocated_object_num - objspace->total_freed_object_num; } +static size_t +objspace_free_num(rb_objspace_t *objspace) +{ + return objspace->heap.limit - (objspace_live_num(objspace) - objspace->heap.final_num); +} + static void gc_setup_mark_bits(struct heap_slot *slot) { @@ -4506,7 +4512,7 @@ gc_stat(int argc, VALUE *argv, VALUE self) rb_hash_aset(hash, sym_heap_length, SIZET2NUM(objspace->heap.length)); rb_hash_aset(hash, sym_heap_increment, SIZET2NUM(objspace->heap.increment)); rb_hash_aset(hash, sym_heap_live_num, SIZET2NUM(objspace_live_num(objspace))); - rb_hash_aset(hash, sym_heap_free_num, SIZET2NUM(objspace->heap.free_num)); + rb_hash_aset(hash, sym_heap_free_num, SIZET2NUM(objspace_free_num(objspace))); rb_hash_aset(hash, sym_heap_final_num, SIZET2NUM(objspace->heap.final_num)); rb_hash_aset(hash, sym_total_allocated_object, SIZET2NUM(objspace->total_allocated_object_num)); rb_hash_aset(hash, sym_total_freed_object, SIZET2NUM(objspace->total_freed_object_num)); diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 53fd107747..30baebb67a 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -70,6 +70,13 @@ class TestGc < Test::Unit::TestCase GC.stat(stat) ObjectSpace.count_objects(count) assert_equal(count[:TOTAL]-count[:FREE], stat[:heap_live_num]) + assert_equal(count[:FREE], stat[:heap_free_num]) + + # measure again without GC.start + 1000.times{ "a" + "b" } + GC.stat(stat) + ObjectSpace.count_objects(count) + assert_equal(count[:FREE], stat[:heap_free_num]) end def test_singleton_method |