ruby-changes:45414
From: tenderlove <ko1@a...>
Date: Wed, 1 Feb 2017 02:46:57 +0900 (JST)
Subject: [ruby-changes:45414] tenderlove:r57486 (trunk): Add IMEMO type to heap dump output.
tenderlove 2017-02-01 02:46:51 +0900 (Wed, 01 Feb 2017) New Revision: 57486 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57486 Log: Add IMEMO type to heap dump output. IMEMO objects have many types. Without this change, we cannot see what types of IMEMO objects are being used when dumping the heap. Adding the type to the IMEMO object will allow us to gather statistics about IMEMO objects being used. Modified files: trunk/ext/objspace/objspace_dump.c trunk/test/objspace/test_objspace.rb Index: ext/objspace/objspace_dump.c =================================================================== --- ext/objspace/objspace_dump.c (revision 57485) +++ ext/objspace/objspace_dump.c (revision 57486) @@ -192,6 +192,25 @@ dump_append_string_content(struct dump_c https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L192 } } +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_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L248 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; Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 57485) +++ test/objspace/test_objspace.rb (revision 57486) @@ -277,6 +277,23 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L277 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/