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

* gc.c (gc_count): add a GC.count method. This method returns

a GC invoking count.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2008-04-27 06:28:08 +00:00
parent 80b1f7b50e
commit 3de80833a2
3 changed files with 26 additions and 1 deletions

View file

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

View file

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

19
gc.c
View file

@ -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;
@ -2351,6 +2353,22 @@ count_objects(int argc, VALUE *argv, VALUE os)
return hash;
}
/*
* 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
@ -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");