diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-01-08 16:14:01 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-02-22 09:58:59 +0900 |
commit | b9007b6c548f91e88fd3f2ffa23de740431fa969 (patch) | |
tree | 1746393d1c5f704e8dc7e0a458198264062273bf /internal | |
parent | f2286925f08406bc857f7b03ad6779a5d61443ae (diff) |
Introduce disposable call-cache.
This patch contains several ideas:
(1) Disposable inline method cache (IMC) for race-free inline method cache
* Making call-cache (CC) as a RVALUE (GC target object) and allocate new
CC on cache miss.
* This technique allows race-free access from parallel processing
elements like RCU.
(2) Introduce per-Class method cache (pCMC)
* Instead of fixed-size global method cache (GMC), pCMC allows flexible
cache size.
* Caching CCs reduces CC allocation and allow sharing CC's fast-path
between same call-info (CI) call-sites.
(3) Invalidate an inline method cache by invalidating corresponding method
entries (MEs)
* Instead of using class serials, we set "invalidated" flag for method
entry itself to represent cache invalidation.
* Compare with using class serials, the impact of method modification
(add/overwrite/delete) is small.
* Updating class serials invalidate all method caches of the class and
sub-classes.
* Proposed approach only invalidate the method cache of only one ME.
See [Feature #16614] for more details.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2888
Diffstat (limited to 'internal')
-rw-r--r-- | internal/class.h | 2 | ||||
-rw-r--r-- | internal/imemo.h | 4 | ||||
-rw-r--r-- | internal/vm.h | 41 |
3 files changed, 8 insertions, 39 deletions
diff --git a/internal/class.h b/internal/class.h index 72d3b9ea54..67ea6e2a83 100644 --- a/internal/class.h +++ b/internal/class.h @@ -41,6 +41,7 @@ struct rb_classext_struct { #endif struct rb_id_table *const_tbl; struct rb_id_table *callable_m_tbl; + struct rb_id_table *cc_tbl; /* ID -> [[ci, cc1], cc2, ...] */ struct rb_subclass_entry *subclasses; struct rb_subclass_entry **parent_subclasses; /** @@ -83,6 +84,7 @@ typedef struct rb_classext_struct rb_classext_t; # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl) #endif #define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl) +#define RCLASS_CC_TBL(c) (RCLASS_EXT(c)->cc_tbl) #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl) #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_) #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class) diff --git a/internal/imemo.h b/internal/imemo.h index 967dc82f01..f09a195e7b 100644 --- a/internal/imemo.h +++ b/internal/imemo.h @@ -29,6 +29,7 @@ #define IMEMO_FL_USER2 FL_USER6 #define IMEMO_FL_USER3 FL_USER7 #define IMEMO_FL_USER4 FL_USER8 +#define IMEMO_FL_USER5 FL_USER9 enum imemo_type { imemo_env = 0, @@ -43,6 +44,7 @@ enum imemo_type { imemo_ast = 9, imemo_parser_strterm = 10, imemo_callinfo = 11, + imemo_callcache = 12, }; /* CREF (Class REFerence) is defined in method.h */ @@ -171,6 +173,8 @@ imemo_type_p(VALUE imemo, enum imemo_type imemo_type) } } +#define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t) + static inline bool imemo_throw_data_p(VALUE imemo) { diff --git a/internal/vm.h b/internal/vm.h index 4bd2bfb1e3..26dde33975 100644 --- a/internal/vm.h +++ b/internal/vm.h @@ -52,44 +52,6 @@ enum method_missing_reason { MISSING_NONE = 0x40 }; -struct rb_call_cache { - /* inline cache: keys */ - rb_serial_t method_state; - rb_serial_t class_serial[ - (CACHELINE - - sizeof(rb_serial_t) /* method_state */ - - sizeof(struct rb_callable_method_entry_struct *) /* me */ - - sizeof(uintptr_t) /* method_serial */ - - sizeof(enum method_missing_reason) /* aux */ - - sizeof(VALUE (*)( /* call */ - struct rb_execution_context_struct *e, - struct rb_control_frame_struct *, - struct rb_calling_info *, - const struct rb_call_data *))) - / sizeof(rb_serial_t) - ]; - - /* inline cache: values */ - const struct rb_callable_method_entry_struct *me; - uintptr_t method_serial; /* me->def->method_serial */ - - VALUE (*call)(struct rb_execution_context_struct *ec, - struct rb_control_frame_struct *cfp, - struct rb_calling_info *calling, - struct rb_call_data *cd); - - union { - unsigned int index; /* used by ivar */ - enum method_missing_reason method_missing_reason; /* used by method_missing */ - } aux; -}; -STATIC_ASSERT(cachelined, sizeof(struct rb_call_cache) <= CACHELINE); - -struct rb_call_data { - const struct rb_callinfo *ci; - struct rb_call_cache cc; -}; - /* vm_insnhelper.h */ rb_serial_t rb_next_class_serial(void); @@ -139,8 +101,9 @@ MJIT_SYMBOL_EXPORT_END VALUE rb_equal_opt(VALUE obj1, VALUE obj2); VALUE rb_eql_opt(VALUE obj1, VALUE obj2); +struct rb_iseq_struct; MJIT_SYMBOL_EXPORT_BEGIN -void rb_vm_search_method_slowpath(struct rb_call_data *cd, VALUE klass); +void rb_vm_search_method_slowpath(VALUE cd_owner, struct rb_call_data *cd, VALUE klass); MJIT_SYMBOL_EXPORT_END /* vm_dump.c */ |