From b41270842aae73bf59e17fb1d175a4ff557f0e87 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 13 Oct 2023 10:31:56 -0700 Subject: Record more info from CALLCACHE in heap dumps This records the called_id and klass from imemo_callcache objects in heap dumps. --- ext/objspace/objspace_dump.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'ext/objspace/objspace_dump.c') diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index c80c38eba4..8fd3d9d0f3 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -168,10 +168,8 @@ dump_append_c(struct dump_config *dc, unsigned char c) } static void -dump_append_ref(struct dump_config *dc, VALUE ref) +dump_append_ptr(struct dump_config *dc, VALUE ref) { - RUBY_ASSERT(ref > 0); - char buffer[roomof(sizeof(VALUE) * CHAR_BIT, 4) + rb_strlen_lit("\"0x\"")]; char *buffer_start, *buffer_end; @@ -187,6 +185,14 @@ dump_append_ref(struct dump_config *dc, VALUE ref) buffer_append(dc, buffer_start, buffer_end - buffer_start); } +static void +dump_append_ref(struct dump_config *dc, VALUE ref) +{ + RUBY_ASSERT(ref > 0); + dump_append_ptr(dc, ref); +} + + static void dump_append_string_value(struct dump_config *dc, VALUE obj) { @@ -441,6 +447,20 @@ dump_object(VALUE obj, struct dump_config *dc) } break; + case imemo_callcache: + mid = vm_cc_cme((const struct rb_callcache *)obj)->called_id; + if (mid != 0) { + dump_append(dc, ", \"called_id\":"); + dump_append_string_value(dc, rb_id2str(mid)); + + VALUE klass = ((const struct rb_callcache *)obj)->klass; + if (klass != 0) { + dump_append(dc, ", \"receiver_class\":"); + dump_append_ref(dc, klass); + } + } + break; + default: break; } -- cgit v1.2.3