summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--ext/objspace/objspace.c27
-rw-r--r--internal.h1
3 files changed, 35 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 93d56cc3e1..1e0d3071f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Thu Jun 30 17:33:25 2011 Koichi Sasada <ko1@atdot.net>
+
+ * ext/objspace/objspace.c (ObjectSpace.count_tdata_objects):
+ Fix rdoc.
+
+ * ext/objspace/objspace.c (ObjectSpace.count_tdata_objects):
+ Change key type if the klass of a object is zero (internal object).
+ Read rdoc for details.
+
+ * internal.h: export rb_objspace_data_type_name().
+
Thu Jun 30 17:25:08 2011 Koichi Sasada <ko1@atdot.net>
* thread_pthread.c (ping_signal_thread_list, thread_timer):
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 3434a0ae07..a0859a7325 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -547,14 +547,24 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
for (; v != (VALUE)vend; v += stride) {
if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_DATA) {
- VALUE counter = rb_hash_aref(hash, RBASIC(v)->klass);
+ VALUE counter;
+ VALUE key = RBASIC(v)->klass;
+
+ if (key == 0) {
+ const char *name = rb_objspace_data_type_name(v);
+ if (name == 0) name = "unknown";
+ key = ID2SYM(rb_intern(name));
+ }
+
+ counter = rb_hash_aref(hash, key);
if (NIL_P(counter)) {
counter = INT2FIX(1);
}
else {
counter = INT2FIX(FIX2INT(counter) + 1);
}
- rb_hash_aset(hash, RBASIC(v)->klass, counter);
+
+ rb_hash_aset(hash, key, counter);
}
}
@@ -565,13 +575,17 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
* call-seq:
* ObjectSpace.count_tdata_objects([result_hash]) -> hash
*
- * Counts nodes for each node type.
+ * Counts objects for each T_DATA type.
*
* This method is not for ordinary Ruby programmers, but for MRI developers
* who interest on MRI performance.
*
* It returns a hash as:
- * {:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
+ * {RubyVM::InstructionSequence=>504, :parser=>5, :barrier=>6,
+ * :mutex=>6, Proc=>60, RubyVM::Env=>57, Mutex=>1, Encoding=>99,
+ * ThreadGroup=>1, Binding=>1, Thread=>1, RubyVM=>1, :iseq=>1,
+ * Random=>1, ARGF.class=>1, Data=>1, :autoload=>3, Time=>2}
+ * # T_DATA objects existing at startup on r32276.
*
* If the optional argument, result_hash, is given,
* it is overwritten and returned.
@@ -580,6 +594,11 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
* The contents of the returned hash is implementation defined.
* It may be changed in future.
*
+ * In this version, keys are Class object or Symbol object.
+ * If object is kind of normal (accessible) object, the key is Class object.
+ * If object is not a kind of normal (internal) object, the key is symbol
+ * name, registered by rb_data_type_struct.
+ *
* This method is not expected to work except C Ruby.
*
*/
diff --git a/internal.h b/internal.h
index ec61b32ae7..71c8ab6ca6 100644
--- a/internal.h
+++ b/internal.h
@@ -192,6 +192,7 @@ void Init_prelude(void);
#pragma GCC visibility push(default)
#endif
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
+const char *rb_objspace_data_type_name(VALUE obj);
#if defined __GNUC__ && __GNUC__ >= 4
#pragma GCC visibility pop
#endif