ruby-changes:32026
From: tmm1 <ko1@a...>
Date: Tue, 10 Dec 2013 11:26:18 +0900 (JST)
Subject: [ruby-changes:32026] tmm1:r44105 (trunk): objspace_dump.c: include object's gc flags in dump
tmm1 2013-12-10 11:26:09 +0900 (Tue, 10 Dec 2013) New Revision: 44105 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44105 Log: objspace_dump.c: include object's gc flags in dump * ext/objspace/objspace_dump.c (dump_object): include fstring flag on strings. include gc flags (old, remembered, wb_protected) on all objects. * ext/objspace/objspace_dump.c (Init_objspace_dump): initialize lazy IDs before first use. * gc.c (rb_obj_gc_flags): new function to retrieve object flags * internal.h (RB_OBJ_GC_FLAGS_MAX): maximum flags allowed for one obj * test/objspace/test_objspace.rb (test_dump_flags): test for above * test/objspace/test_objspace.rb (test_trace_object_allocations): resolve name before dump (for rb_class_path_cached) Modified files: trunk/ChangeLog trunk/ext/objspace/objspace_dump.c trunk/gc.c trunk/internal.h trunk/test/objspace/test_objspace.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44104) +++ ChangeLog (revision 44105) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 10 11:20:56 2013 Aman Gupta <ruby@t...> + + * ext/objspace/objspace_dump.c (dump_object): include fstring flag on + strings. include gc flags (old, remembered, wb_protected) on all objects. + * ext/objspace/objspace_dump.c (Init_objspace_dump): initialize lazy + IDs before first use. + * gc.c (rb_obj_gc_flags): new function to retrieve object flags + * internal.h (RB_OBJ_GC_FLAGS_MAX): maximum flags allowed for one obj + * test/objspace/test_objspace.rb (test_dump_flags): test for above + * test/objspace/test_objspace.rb (test_trace_object_allocations): + resolve name before dump (for rb_class_path_cached) + Tue Dec 10 07:48:29 2013 Aman Gupta <ruby@t...> * vm_method.c (rb_clear_method_cache_by_class): fire Index: gc.c =================================================================== --- gc.c (revision 44104) +++ gc.c (revision 44105) @@ -4749,6 +4749,53 @@ rb_obj_rgengc_promoted_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L4749 return OBJ_PROMOTED(obj) ? Qtrue : Qfalse; } +size_t +rb_obj_gc_flags(VALUE obj, ID* flags, size_t max) +{ + size_t n = 0; + static ID ID_marked; +#if USE_RGENGC + static ID ID_wb_protected, ID_old, ID_remembered; +#if RGENGC_THREEGEN + static ID ID_young, ID_infant; +#endif +#endif + + if (!ID_marked) { +#define I(s) ID_##s = rb_intern(#s); + I(marked); +#if USE_RGENGC + I(wb_protected); + I(old); + I(remembered); +#if RGENGC_THREEGEN + I(young); + I(infant); +#endif +#endif +#undef I + } + +#if USE_RGENGC + if (OBJ_WB_PROTECTED(obj) && n<max) + flags[n++] = ID_wb_protected; + if (RVALUE_OLD_P(obj) && n<max) + flags[n++] = ID_old; +#if RGENGC_THREEGEN + if (RVALUE_YOUNG_P(obj) && n<max) + flags[n++] = ID_young; + if (RVALUE_INFANT_P(obj) && n<max) + flags[n++] = ID_infant; +#endif + if (MARKED_IN_BITMAP(GET_HEAP_REMEMBERSET_BITS(obj), obj) && n<max) + flags[n++] = ID_remembered; +#endif + if (MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(obj), obj) && n<max) + flags[n++] = ID_marked; + + return n; +} + /* GC */ void Index: ext/objspace/objspace_dump.c =================================================================== --- ext/objspace/objspace_dump.c (revision 44104) +++ ext/objspace/objspace_dump.c (revision 44105) @@ -20,6 +20,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L20 #include "node.h" #include "vm_core.h" #include "objspace.h" +#include "internal.h" static VALUE sym_output, sym_stdout, sym_string, sym_file; @@ -148,6 +149,8 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L149 size_t memsize; struct allocation_info *ainfo; rb_io_t *fptr; + ID flags[RB_OBJ_GC_FLAGS_MAX]; + size_t n, i; dc->cur_obj = obj; dc->cur_obj_references = 0; @@ -175,6 +178,8 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L178 dump_append(dc, ", \"associated\":true"); if (is_broken_string(obj)) dump_append(dc, ", \"broken\":true"); + if (FL_TEST(obj, RSTRING_FSTR)) + dump_append(dc, ", \"fstring\":true"); if (STR_SHARED_P(obj)) dump_append(dc, ", \"shared\":true"); else { @@ -249,6 +254,15 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L254 if ((memsize = rb_obj_memsize_of(obj)) > 0) dump_append(dc, ", \"memsize\":%"PRIuSIZE, memsize); + if ((n = rb_obj_gc_flags(obj, flags, sizeof(flags))) > 0) { + dump_append(dc, ", \"flags\":{"); + for (i=0; i<n; i++) { + dump_append(dc, "\"%s\":true", rb_id2name(flags[i])); + if (i != n-1) dump_append(dc, ", "); + } + dump_append(dc, "}"); + } + dump_append(dc, "}\n"); } @@ -411,4 +425,7 @@ Init_objspace_dump(VALUE rb_mObjSpace) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L425 sym_stdout = ID2SYM(rb_intern("stdout")); sym_string = ID2SYM(rb_intern("string")); sym_file = ID2SYM(rb_intern("file")); + + /* force create static IDs */ + rb_obj_gc_flags(rb_mObjSpace, 0, 0); } Index: internal.h =================================================================== --- internal.h (revision 44104) +++ internal.h (revision 44105) @@ -871,6 +871,8 @@ st_table *rb_st_copy(VALUE obj, struct s https://github.com/ruby/ruby/blob/trunk/internal.h#L871 /* gc.c */ size_t rb_obj_memsize_of(VALUE); +#define RB_OBJ_GC_FLAGS_MAX 5 +size_t rb_obj_gc_flags(VALUE, ID[], size_t); RUBY_SYMBOL_EXPORT_END Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 44104) +++ test/objspace/test_objspace.rb (revision 44105) @@ -130,6 +130,7 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L130 end def test_trace_object_allocations + Class.name o0 = Object.new ObjectSpace.trace_object_allocations{ o1 = Object.new; line1 = __LINE__; c1 = GC.count @@ -193,6 +194,12 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L194 assert_equal(nil, ObjectSpace.allocation_sourcefile(obj3)) end + def test_dump_flags + info = ObjectSpace.dump("foo".freeze) + assert_match /"wb_protected":true, "old":true, "marked":true/, info + assert_match /"fstring":true/, info + end + def test_dump_to_default line = nil info = nil -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/