summaryrefslogtreecommitdiff
path: root/compile.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 /compile.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 'compile.c')
-rw-r--r--compile.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index fb99826413..8f53955e74 100644
--- a/compile.c
+++ b/compile.c
@@ -2461,7 +2461,17 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
case TS_IVC: /* inline ivar cache */
{
unsigned int ic_index = FIX2UINT(operands[j]);
- vm_ic_attr_index_initialize(((IVC)&body->is_entries[ic_index]), INVALID_SHAPE_ID);
+
+ IVC cache = ((IVC)&body->is_entries[ic_index]);
+
+ if (insn == BIN(setinstancevariable)) {
+ cache->iv_set_name = SYM2ID(operands[j - 1]);
+ }
+ else {
+ cache->iv_set_name = 0;
+ }
+
+ vm_ic_attr_index_initialize(cache, INVALID_SHAPE_ID);
}
case TS_ISE: /* inline storage entry: `once` insn */
case TS_ICVARC: /* inline cvar cache */
@@ -11529,7 +11539,17 @@ ibf_load_code(const struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t bytecod
code[code_index] = (VALUE)ic;
if (operand_type == TS_IVC) {
- vm_ic_attr_index_initialize(((IVC)code[code_index]), INVALID_SHAPE_ID);
+ IVC cache = (IVC)ic;
+
+ if (insn == BIN(setinstancevariable)) {
+ ID iv_name = (ID)code[code_index - 1];
+ cache->iv_set_name = iv_name;
+ }
+ else {
+ cache->iv_set_name = 0;
+ }
+
+ vm_ic_attr_index_initialize(cache, INVALID_SHAPE_ID);
}
}