From cb1ea54bbf6cdf49c53f42720fec1a151069810c Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 21 Apr 2025 10:21:55 +0900 Subject: [PATCH] objspace_dump: Include `shareable` flag Given that the currently planned ractor local GC implementation performance will heavilly be influenced by the number of shareable objects it would be valuable to be able to know how many of them are in the heap. --- gc/default/default.c | 4 +++- test/objspace/test_objspace.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gc/default/default.c b/gc/default/default.c index ec905ac361..124c5de3eb 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -6199,7 +6199,7 @@ rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj) { rb_objspace_t *objspace = objspace_ptr; size_t n = 0; - static ID ID_wb_protected, ID_age, ID_old, ID_uncollectible, ID_marking, ID_marked, ID_pinned, ID_object_id; + static ID ID_wb_protected, ID_age, ID_old, ID_uncollectible, ID_marking, ID_marked, ID_pinned, ID_object_id, ID_shareable; if (!ID_marked) { #define I(s) ID_##s = rb_intern(#s); @@ -6211,6 +6211,7 @@ rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj) I(marked); I(pinned); I(object_id); + I(shareable); #undef I } @@ -6229,6 +6230,7 @@ rb_gc_impl_object_metadata(void *objspace_ptr, VALUE obj) if (RVALUE_MARKED(objspace, obj)) SET_ENTRY(marked, Qtrue); if (RVALUE_PINNED(objspace, obj)) SET_ENTRY(pinned, Qtrue); if (FL_TEST(obj, FL_SEEN_OBJ_ID)) SET_ENTRY(object_id, rb_obj_id(obj)); + if (FL_TEST(obj, FL_SHAREABLE)) SET_ENTRY(shareable, Qtrue); object_metadata_entries[n].name = 0; object_metadata_entries[n].val = 0; diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index c25882a580..e1aa57e46e 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -977,6 +977,13 @@ class TestObjSpace < Test::Unit::TestCase assert_equal class_name, JSON.parse(json)["name"] end + def test_dump_include_shareable + omit 'Not provided by mmtk' if RUBY_DESCRIPTION.include?("+GC[mmtk]") + + assert_include(ObjectSpace.dump(ENV), '"shareable":true') + assert_not_include(ObjectSpace.dump([]), '"shareable":true') + end + def test_utf8_method_names name = "utf8_❨╯°□°❩╯︵┻━┻" obj = ObjectSpace.trace_object_allocations do