[前][次][番号順一覧][スレッド一覧]

ruby-changes:31060

From: tmm1 <ko1@a...>
Date: Fri, 4 Oct 2013 19:05:50 +0900 (JST)
Subject: [ruby-changes:31060] tmm1:r43139 (trunk): gc.c: add objspace_free_num and make GC.stat[:heap_free_num] use it

tmm1	2013-10-04 19:05:40 +0900 (Fri, 04 Oct 2013)

  New Revision: 43139

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43139

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/test/ruby/test_gc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43138)
+++ ChangeLog	(revision 43139)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct  4 19:02:01 2013  Aman Gupta <ruby@t...>
+
+	* 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@t...>
 
 	* gc.c: add rb_objspace.limit to keep accurate count of total heap
Index: gc.c
===================================================================
--- gc.c	(revision 43138)
+++ gc.c	(revision 43139)
@@ -2259,6 +2259,12 @@ objspace_live_num(rb_objspace_t *objspac https://github.com/ruby/ruby/blob/trunk/gc.c#L2259
     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 sel https://github.com/ruby/ruby/blob/trunk/gc.c#L4512
     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));
Index: test/ruby/test_gc.rb
===================================================================
--- test/ruby/test_gc.rb	(revision 43138)
+++ test/ruby/test_gc.rb	(revision 43139)
@@ -70,6 +70,13 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L70
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]