summaryrefslogtreecommitdiff
path: root/iseq.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2022-12-06 14:52:11 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2022-12-06 13:43:42 -0800
commit40a9964b893fee5680b455d0e905155be3360685 (patch)
tree69b6fbc7355cbef1cf311d50fbc496773b94bda7 /iseq.c
parent64cdf8bae7cd85bc2911b39074d5710616c7ec73 (diff)
downloadruby-40a9964b893fee5680b455d0e905155be3360685.tar.gz
Set max_iv_count (used for object shapes) based on inline caches
With this change, we're storing the iv name on an inline cache on setinstancevariable instructions. This allows us to check the inline cache to count instance variables set in initialize and give us an estimate of iv capacity for an object. For the purpose of estimating the number of instance variables required for an object, we're assuming that all initialize methods will call `super`. This change allows us to estimate the number of instance variables required without disassembling instruction sequences. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/iseq.c b/iseq.c
index 381bf6ed20..869ed4da6a 100644
--- a/iseq.c
+++ b/iseq.c
@@ -2509,33 +2509,20 @@ rb_iseq_disasm(const rb_iseq_t *iseq)
attr_index_t
rb_estimate_iv_count(VALUE klass, const rb_iseq_t * initialize_iseq)
{
- bool calls_super = false;
-
struct rb_id_table * iv_names = rb_id_table_create(0);
- VALUE * code = ISEQ_BODY(initialize_iseq)->iseq_encoded;
-
- for (unsigned int i = 0; i < ISEQ_BODY(initialize_iseq)->iseq_size; ) {
- VALUE insn = code[i];
- int original_insn = rb_vm_insn_addr2insn((const void *)insn);
+ for (unsigned int i = 0; i < ISEQ_BODY(initialize_iseq)->ivc_size; i++) {
+ IVC cache = (IVC)&ISEQ_BODY(initialize_iseq)->is_entries[i];
- if (BIN(setinstancevariable) == original_insn) {
- ID name = (ID)code[i + 1];
- rb_id_table_insert(iv_names, name, Qtrue);
+ if (cache->iv_set_name) {
+ rb_id_table_insert(iv_names, cache->iv_set_name, Qtrue);
}
- else if (BIN(invokesuper) == original_insn) {
- calls_super = true;
- }
-
- i += insn_len(original_insn);
}
attr_index_t count = (attr_index_t)rb_id_table_size(iv_names);
- if (calls_super) {
- VALUE superclass = rb_class_superclass(klass);
- count += RCLASS_EXT(superclass)->max_iv_count;
- }
+ VALUE superclass = rb_class_superclass(klass);
+ count += RCLASS_EXT(superclass)->max_iv_count;
rb_id_table_free(iv_names);