summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-10-31 14:05:37 -0700
committerGitHub <noreply@github.com>2022-10-31 14:05:37 -0700
commit02f15542245222ee392e68fb244b3b8c4a12ad82 (patch)
treeebf3180364aaba5893a17b932605911072189e3d /vm_insnhelper.c
parent2b39640b0bbf7459b305d8a98bb01f197975b8d9 (diff)
downloadruby-02f15542245222ee392e68fb244b3b8c4a12ad82.tar.gz
Implement object shapes for T_CLASS and T_MODULE (#6637)
* Avoid RCLASS_IV_TBL in marshal.c * Avoid RCLASS_IV_TBL for class names * Avoid RCLASS_IV_TBL for autoload * Avoid RCLASS_IV_TBL for class variables * Avoid copying RCLASS_IV_TBL onto ICLASSes * Use object shapes for Class and Module IVs
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 2434c5c3c6..cff4b9138a 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1169,7 +1169,23 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call
case T_CLASS:
case T_MODULE:
{
- goto general_path;
+ if (UNLIKELY(!rb_ractor_main_p())) {
+ // For two reasons we can only use the fast path on the main
+ // ractor.
+ // First, only the main ractor is allowed to set ivars on classes
+ // and modules. So we can skip locking.
+ // Second, other ractors need to check the shareability of the
+ // values returned from the class ivars.
+ goto general_path;
+ }
+
+ ivar_list = RCLASS_IVPTR(obj);
+
+#if !SHAPE_IN_BASIC_FLAGS
+ shape_id = RCLASS_SHAPE_ID(obj);
+#endif
+
+ break;
}
default:
if (FL_TEST_RAW(obj, FL_EXIVAR)) {
@@ -1507,15 +1523,13 @@ vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *reg_cfp, ID
{
const rb_cref_t *cref;
- if (ic->entry && ic->entry->global_cvar_state == GET_GLOBAL_CVAR_STATE()) {
- VALUE v = Qundef;
+ if (ic->entry && ic->entry->global_cvar_state == GET_GLOBAL_CVAR_STATE() && LIKELY(rb_ractor_main_p())) {
RB_DEBUG_COUNTER_INC(cvar_read_inline_hit);
- if (st_lookup(RCLASS_IV_TBL(ic->entry->class_value), (st_data_t)id, &v) &&
- LIKELY(rb_ractor_main_p())) {
+ VALUE v = rb_ivar_lookup(ic->entry->class_value, id, Qundef);
+ RUBY_ASSERT(v != Qundef);
- return v;
- }
+ return v;
}
cref = vm_get_cref(GET_EP());