ruby-changes:62335
From: Alan <ko1@a...>
Date: Tue, 21 Jul 2020 09:20:28 +0900 (JST)
Subject: [ruby-changes:62335] 73ee1295a3 (master): Add memsize support for the call cache table
https://git.ruby-lang.org/ruby.git/commit/?id=73ee1295a3 From 73ee1295a33c51f24e774b273fdeca5910ce5ba8 Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Mon, 20 Jul 2020 15:38:07 -0400 Subject: Add memsize support for the call cache table Each class/module/iclass can potentially have their own cc table. Count their malloc usage. diff --git a/gc.c b/gc.c index 9baddb9..d2d7b06 100644 --- a/gc.c +++ b/gc.c @@ -3898,6 +3898,24 @@ rb_obj_id(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3898 return rb_find_object_id(obj, cached_object_id); } +static enum rb_id_table_iterator_result +cc_table_memsize_i(VALUE ccs_ptr, void *data_ptr) +{ + size_t *total_size = data_ptr; + struct rb_class_cc_entries *ccs = (struct rb_class_cc_entries *)ccs_ptr; + *total_size += sizeof(*ccs); + *total_size += sizeof(ccs->entries[0]) * ccs->capa; + return ID_TABLE_CONTINUE; +} + +static size_t +cc_table_memsize(struct rb_id_table *cc_table) +{ + size_t total = rb_id_table_memsize(cc_table); + rb_id_table_foreach_values(cc_table, cc_table_memsize_i, &total); + return total; +} + static size_t obj_memsize_of(VALUE obj, int use_all_types) { @@ -3936,6 +3954,9 @@ obj_memsize_of(VALUE obj, int use_all_types) https://github.com/ruby/ruby/blob/trunk/gc.c#L3954 if (RCLASS(obj)->ptr->const_tbl) { size += rb_id_table_memsize(RCLASS(obj)->ptr->const_tbl); } + if (RCLASS_CC_TBL(obj)) { + size += cc_table_memsize(RCLASS_CC_TBL(obj)); + } size += sizeof(rb_classext_t); } break; @@ -3946,6 +3967,9 @@ obj_memsize_of(VALUE obj, int use_all_types) https://github.com/ruby/ruby/blob/trunk/gc.c#L3967 size += rb_id_table_memsize(RCLASS_M_TBL(obj)); } } + if (RCLASS_EXT(obj) && RCLASS_CC_TBL(obj)) { + size += cc_table_memsize(RCLASS_CC_TBL(obj)); + } break; case T_STRING: size += rb_str_memsize(obj); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/