Skip to content

Commit 4ef4eab

Browse files
committed
Merge branch 'iseq-segment-memsize' into shared-icc-size
2 parents 35faefe + 21451a1 commit 4ef4eab

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

ext/objspace/objspace_dump.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,18 @@ dump_object(VALUE obj, struct dump_config *dc)
461461
}
462462
break;
463463

464+
case imemo_iseq: {
465+
size_t segment_size = rb_iseq_ic_segments_size((const rb_iseq_t *)obj);
466+
if (segment_size) {
467+
dump_append(dc, ", \"segments_memsize\":");
468+
dump_append_sizet(dc, segment_size);
469+
}
470+
471+
dump_append(dc, ", \"is_size\":");
472+
dump_append_sizet(dc, rb_iseq_is_size((const rb_iseq_t *)obj));
473+
474+
break;
475+
}
464476
default:
465477
break;
466478
}

iseq.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,35 @@ rb_iseq_memsize(const rb_iseq_t *iseq)
504504
return size;
505505
}
506506

507+
size_t
508+
rb_iseq_is_size(const rb_iseq_t *iseq)
509+
{
510+
return (size_t)ISEQ_IS_SIZE(ISEQ_BODY(iseq));
511+
}
512+
513+
size_t
514+
rb_iseq_ic_segments_size(const rb_iseq_t *iseq)
515+
{
516+
size_t size = 0;
517+
const struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
518+
519+
if (ISEQ_EXECUTABLE_P(iseq) && body) {
520+
if (ISEQ_BODY(iseq)->is_entries) {
521+
/* IC entries constant segments */
522+
for (unsigned int ic_idx = 0; ic_idx < body->ic_size; ic_idx++) {
523+
IC ic = &ISEQ_IS_IC_ENTRY(body, ic_idx);
524+
const ID *ids = ic->segments;
525+
if (!ids) continue;
526+
while (*ids++) {
527+
size += sizeof(ID);
528+
}
529+
size += sizeof(ID); // null terminator
530+
}
531+
}
532+
}
533+
return size;
534+
}
535+
507536
struct rb_iseq_constant_body *
508537
rb_iseq_constant_body_alloc(void)
509538
{

vm_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static inline const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq) {return 0
584584
#endif
585585
const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq);
586586

587+
587588
static inline const rb_iseq_t *
588589
rb_iseq_check(const rb_iseq_t *iseq)
589590
{
@@ -1207,6 +1208,9 @@ typedef enum {
12071208
/* iseq.c */
12081209
RUBY_SYMBOL_EXPORT_BEGIN
12091210

1211+
size_t rb_iseq_ic_segments_size(const rb_iseq_t *iseq);
1212+
size_t rb_iseq_is_size(const rb_iseq_t *iseq);
1213+
12101214
/* node -> iseq */
12111215
rb_iseq_t *rb_iseq_new (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum rb_iseq_type);
12121216
rb_iseq_t *rb_iseq_new_top (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);

0 commit comments

Comments
 (0)