summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/objspace/objspace_dump.c23
-rw-r--r--test/objspace/test_objspace.rb17
2 files changed, 40 insertions, 0 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 9c2055d..e235c58 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -192,6 +192,25 @@ dump_append_string_content(struct dump_config *dc, VALUE obj)
}
}
+static const char *
+imemo_name(int imemo)
+{
+ switch(imemo) {
+#define TYPE_STR(t) case(imemo_##t): return #t; break;
+ TYPE_STR(env)
+ TYPE_STR(cref)
+ TYPE_STR(svar)
+ TYPE_STR(throw_data)
+ TYPE_STR(ifunc)
+ TYPE_STR(memo)
+ TYPE_STR(ment)
+ TYPE_STR(iseq)
+ default:
+ return "unknown";
+#undef TYPE_STR
+ }
+}
+
static void
dump_object(VALUE obj, struct dump_config *dc)
{
@@ -229,6 +248,10 @@ dump_object(VALUE obj, struct dump_config *dc)
dump_append(dc, ", \"node_type\":\"%s\"", ruby_node_name(nd_type(obj)));
break;
+ case T_IMEMO:
+ dump_append(dc, ", \"imemo_type\":\"%s\"", imemo_name(imemo_type(obj)));
+ break;
+
case T_SYMBOL:
dump_append_string_content(dc, rb_sym2str(obj));
break;
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 7f8f247..74e0ef9 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -277,6 +277,23 @@ class TestObjSpace < Test::Unit::TestCase
assert_match /"value":"foobar\h+"/, dump
end
+ def test_dump_includes_imemo_type
+ assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
+ begin;
+ def dump_my_heap_please
+ ObjectSpace.dump_all(output: :stdout)
+ end
+
+ dump_my_heap_please
+ end;
+ heap = output.find_all { |l|
+ obj = JSON.parse(l)
+ obj['type'] == "IMEMO" && obj['imemo_type']
+ }
+ assert_operator heap.length, :>, 0
+ end
+ end
+
def test_dump_all_full
assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
begin;