aboutsummaryrefslogtreecommitdiffstats
path: root/vm_core.h
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-08-10 10:35:48 -0700
committerJohn Hawthorn <john@hawthorn.email>2022-09-01 15:20:49 -0700
commit679ef34586e7a43151865cb7f33a3253d815f7cf (patch)
tree1f46e901c2c77438e050585e9e9708492cc985a6 /vm_core.h
parent7064d259bc20050d467874e5622082c29529a2d3 (diff)
downloadruby-679ef34586e7a43151865cb7f33a3253d815f7cf.tar.gz
New constant caching insn: opt_getconstant_path
Previously YARV bytecode implemented constant caching by having a pair of instructions, opt_getinlinecache and opt_setinlinecache, wrapping a series of getconstant calls (with putobject providing supporting arguments). This commit replaces that pattern with a new instruction, opt_getconstant_path, handling both getting/setting the inline cache and fetching the constant on a cache miss. This is implemented by storing the full constant path as a null-terminated array of IDs inside of the IC structure. idNULL is used to signal an absolute constant reference. $ ./miniruby --dump=insns -e '::Foo::Bar::Baz' == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE) 0000 opt_getconstant_path <ic:0 ::Foo::Bar::Baz> ( 1)[Li] 0002 leave The motivation for this is that we had increasingly found the need to disassemble the instructions between the opt_getinlinecache and opt_setinlinecache in order to determine the constant we are fetching, or otherwise store metadata. This disassembly was done: * In opt_setinlinecache, to register the IC against the constant names it is using for granular invalidation. * In rb_iseq_free, to unregister the IC from the invalidation table. * In YJIT to find the position of a opt_getinlinecache instruction to invalidate it when the cache is populated * In YJIT to register the constant names being used for invalidation. With this change we no longe need disassemly for these (in fact rb_iseq_each is now unused), as the list of constant names being referenced is held in the IC. This should also make it possible to make more optimizations in the future. This may also reduce the size of iseqs, as previously each segment required 32 bytes (on 64-bit platforms) for each constant segment. This implementation only stores one ID per-segment. There should be no significant performance change between this and the previous implementation. Previously opt_getinlinecache was a "leaf" instruction, but it included a jump (almost always to a separate cache line). Now opt_getconstant_path is a non-leaf (it may raise/autoload/call const_missing) but it does not jump. These seem to even out.
Diffstat (limited to 'vm_core.h')
-rw-r--r--vm_core.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/vm_core.h b/vm_core.h
index eee25161f5..350f3fdd58 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -256,9 +256,19 @@ STATIC_ASSERT(sizeof_iseq_inline_constant_cache_entry,
struct iseq_inline_constant_cache {
struct iseq_inline_constant_cache_entry *entry;
- // For YJIT: the index to the opt_getinlinecache instruction in the same iseq.
- // It's set during compile time and constant once set.
- unsigned get_insn_idx;
+
+ /**
+ * A null-terminated list of ids, used to represent a constant's path
+ * idNULL is used to represent the :: prefix, and 0 is used to donate the end
+ * of the list.
+ *
+ * For example
+ * FOO {rb_intern("FOO"), 0}
+ * FOO::BAR {rb_intern("FOO"), rb_intern("BAR"), 0}
+ * ::FOO {idNULL, rb_intern("FOO"), 0}
+ * ::FOO::BAR {idNULL, rb_intern("FOO"), rb_intern("BAR"), 0}
+ */
+ const ID *segments;
};
struct iseq_inline_iv_cache_entry {
@@ -339,6 +349,9 @@ typedef uintptr_t iseq_bits_t;
#define ISEQ_IS_SIZE(body) (body->ic_size + body->ivc_size + body->ise_size + body->icvarc_size)
+/* [ TS_IVC | TS_ICVARC | TS_ISE | TS_IC ] */
+#define ISEQ_IS_IC_ENTRY(body, idx) (body->is_entries[(idx) + body->ise_size + body->icvarc_size + body->ivc_size].ic_cache);
+
/* instruction sequence type */
enum rb_iseq_type {
ISEQ_TYPE_TOP,