summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorLourens Naudé <lourens@bearmetal.eu>2019-04-22 23:24:52 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-23 16:22:34 +0900
commit90c4bd2d2bd10b19c2b09834396553742bc7e8a4 (patch)
treeb28ee0776163ca2fede687cee82547a202c3e494 /gc.c
parentab087ecb4dd21ea5f7d1cbadd8298f2f1a3c9ce9 (diff)
Let memory sizes of the various IMEMO object types be reflected correctly
[Feature #15805] Closes: https://github.com/ruby/ruby/pull/2140
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index d61db0448a..a978887ae9 100644
--- a/gc.c
+++ b/gc.c
@@ -842,6 +842,7 @@ int ruby_disable_gc = 0;
void rb_iseq_mark(const rb_iseq_t *iseq);
void rb_iseq_update_references(rb_iseq_t *iseq);
void rb_iseq_free(const rb_iseq_t *iseq);
+size_t rb_iseq_memsize(const rb_iseq_t *iseq);
void rb_vm_update_references(void *ptr);
void rb_gcdebug_print_obj_condition(VALUE obj);
@@ -2159,6 +2160,40 @@ rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt)
return (rb_imemo_tmpbuf_t *)rb_imemo_tmpbuf_new((VALUE)buf, (VALUE)old_heap, (VALUE)cnt, 0);
}
+static size_t
+imemo_memsize(VALUE obj)
+{
+ size_t size = 0;
+ switch (imemo_type(obj)) {
+ case imemo_ment:
+ size += sizeof(RANY(obj)->as.imemo.ment.def);
+ break;
+ case imemo_iseq:
+ size += rb_iseq_memsize((rb_iseq_t *)obj);
+ break;
+ case imemo_env:
+ size += RANY(obj)->as.imemo.env.env_size * sizeof(VALUE);
+ break;
+ case imemo_tmpbuf:
+ size += RANY(obj)->as.imemo.alloc.cnt * sizeof(VALUE);
+ break;
+ case imemo_ast:
+ size += rb_ast_memsize(&RANY(obj)->as.imemo.ast);
+ break;
+ case imemo_cref:
+ case imemo_svar:
+ case imemo_throw_data:
+ case imemo_ifunc:
+ case imemo_memo:
+ case imemo_parser_strterm:
+ break;
+ default:
+ /* unreachable */
+ break;
+ }
+ return size;
+}
+
#if IMEMO_DEBUG
VALUE
rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line)
@@ -3628,9 +3663,7 @@ obj_memsize_of(VALUE obj, int use_all_types)
case T_COMPLEX:
break;
case T_IMEMO:
- if (imemo_type_p(obj, imemo_tmpbuf)) {
- size += RANY(obj)->as.imemo.alloc.cnt * sizeof(VALUE);
- }
+ size += imemo_memsize(obj);
break;
case T_FLOAT: