ruby-changes:27760
From: nari <ko1@a...>
Date: Tue, 19 Mar 2013 00:30:15 +0900 (JST)
Subject: [ruby-changes:27760] nari:r39812 (trunk): * gc.c: Improve accuracy of objspace_live_num() and
nari 2013-03-19 00:30:02 +0900 (Tue, 19 Mar 2013) New Revision: 39812 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39812 Log: * gc.c: Improve accuracy of objspace_live_num() and allocated/freed counters. patched by tmm1(Aman Gupta). [Bug #8092] [ruby-core:53392] Modified files: trunk/ChangeLog trunk/gc.c trunk/test/ruby/test_gc.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39811) +++ ChangeLog (revision 39812) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Mar 19 00:26:22 2013 Narihiro Nakamura <authornari@g...> + + * gc.c: Improve accuracy of objspace_live_num() and + allocated/freed counters. patched by tmm1(Aman Gupta). + [Bug #8092] [ruby-core:53392] + Mon Mar 18 21:42:48 2013 Narihiro Nakamura <authornari@g...> * gc.c: Avoid unnecessary heap growth. patched by tmm1(Aman Gupta). Index: gc.c =================================================================== --- gc.c (revision 39811) +++ gc.c (revision 39812) @@ -1431,12 +1431,10 @@ finalize_list(rb_objspace_t *objspace, R https://github.com/ruby/ruby/blob/trunk/gc.c#L1431 while (p) { RVALUE *tmp = p->as.free.next; run_final(objspace, (VALUE)p); + objspace->total_freed_object_num++; if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */ add_slot_local_freelist(objspace, p); - if (!is_lazy_sweeping(objspace)) { - objspace->total_freed_object_num++; - objspace->heap.free_num++; - } + objspace->heap.free_num++; } else { struct heaps_slot *slot = (struct heaps_slot *)(VALUE)RDATA(p)->dmark; @@ -1940,9 +1938,9 @@ slot_sweep(rb_objspace_t *objspace, stru https://github.com/ruby/ruby/blob/trunk/gc.c#L1938 else { sweep_slot->free_next = NULL; } - objspace->total_freed_object_num += freed_num; objspace->heap.free_num += freed_num + empty_num; } + objspace->total_freed_object_num += freed_num; objspace->heap.final_num += final_num; if (deferred_final_list && !finalizing) { @@ -2969,11 +2967,11 @@ rb_gc_force_recycle(VALUE p) https://github.com/ruby/ruby/blob/trunk/gc.c#L2967 rb_objspace_t *objspace = &rb_objspace; struct heaps_slot *slot; + objspace->total_freed_object_num++; if (MARKED_IN_BITMAP(GET_HEAP_BITMAP(p), p)) { add_slot_local_freelist(objspace, (RVALUE *)p); } else { - objspace->total_freed_object_num++; objspace->heap.free_num++; slot = add_slot_local_freelist(objspace, (RVALUE *)p); if (slot->free_next == NULL) { Index: test/ruby/test_gc.rb =================================================================== --- test/ruby/test_gc.rb (revision 39811) +++ test/ruby/test_gc.rb (revision 39812) @@ -64,6 +64,12 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L64 assert_equal(arg, res) assert_equal(false, res.empty?) assert_kind_of(Integer, res[:count]) + + stat, count = {}, {} + GC.start + GC.stat(stat) + ObjectSpace.count_objects(count) + assert_equal(count[:TOTAL]-count[:FREE], stat[:heap_live_num]) end def test_singleton_method -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/