1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
tmm1 2013-10-04 10:05:40 +00:00
parent a24705cfa5
commit 907a03fee5
3 changed files with 21 additions and 1 deletions

View file

@ -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

8
gc.c
View file

@ -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));

View file

@ -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