summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--doc/NEWS3
-rw-r--r--gc.c19
3 files changed, 26 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a0b1a3ea0..5fc6355b40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Apr 27 15:23:40 2008 Koichi Sasada <ko1@atdot.net>
+
+ * gc.c (gc_count): add a GC.count method. This method returns
+ a GC invoking count.
+
Sun Apr 27 12:20:33 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_core.h (rb_vm_t), gc.c (rb_objspace, rb_newobj), vm.c
diff --git a/doc/NEWS b/doc/NEWS
index d2a5a23210..551f2c19fb 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -195,7 +195,8 @@ Compatible
o Process.exec
* Misc. new methods
o public_send
- o GC.stress, GC.stress=
+ o GC.stress, GC.stress=, GC.count
+ o ObjectSpace.count_objects
o Method#hash, Proc#hash
o __method__ and __callee__
o Symbol#to_proc
diff --git a/gc.c b/gc.c
index e58269deff..b94e7c6257 100644
--- a/gc.c
+++ b/gc.c
@@ -173,6 +173,7 @@ typedef struct rb_objspace {
int overflow;
} markstack;
struct gc_list *global_list;
+ unsigned int count;
} rb_objspace_t;
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
@@ -1673,6 +1674,7 @@ garbage_collect(rb_objspace_t *objspace)
return Qtrue;
}
during_gc++;
+ objspace->count++;
SET_STACK_END;
@@ -2352,6 +2354,22 @@ count_objects(int argc, VALUE *argv, VALUE os)
}
/*
+ * call-seq:
+ * GC.count -> Integer
+ *
+ * Counts objects for each type.
+ *
+ * It returns a number of GC invoke counts.
+ *
+ */
+
+static VALUE
+gc_count(VALUE self)
+{
+ return UINT2NUM((&rb_objspace)->count);
+}
+
+/*
* The <code>GC</code> module provides an interface to Ruby's mark and
* sweep garbage collection mechanism. Some of the underlying methods
* are also available via the <code>ObjectSpace</code> module.
@@ -2368,6 +2386,7 @@ Init_GC(void)
rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0);
rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1);
+ rb_define_singleton_method(rb_mGC, "count", gc_count, 0);
rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
rb_mObSpace = rb_define_module("ObjectSpace");