diff options
author | Jemma Issroff <[email protected]> | 2022-10-03 13:52:40 -0400 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2022-10-11 08:40:56 -0700 |
commit | 913979bede2a1b79109fa2072352882560d55fe0 (patch) | |
tree | b039ef9760ff7b1bf397fd9cac648cc219032cd6 /shape.h | |
parent | ad63b668e22e21c352b852f3119ae98a7acf99f1 (diff) |
Make inline cache reads / writes atomic with object shapes
Prior to this commit, we were reading and writing ivar index and
shape ID in inline caches in two separate instructions when
getting and setting ivars. This meant there was a race condition
with ractors and these caches where one ractor could change
a value in the cache while another was still reading from it.
This commit instead reads and writes shape ID and ivar index to
inline caches atomically so there is no longer a race condition.
Co-Authored-By: Aaron Patterson <[email protected]>
Co-Authored-By: John Hawthorn <[email protected]>
Diffstat (limited to 'shape.h')
-rw-r--r-- | shape.h | 18 |
1 files changed, 2 insertions, 16 deletions
@@ -43,11 +43,11 @@ typedef uint16_t shape_id_t; # define FROZEN_ROOT_SHAPE_ID 0x1 struct rb_shape { - struct rb_shape * parent; // Pointer to the parent struct rb_id_table * edges; // id_table from ID (ivar) to next shape ID edge_name; // ID (ivar) for transition from parent to rb_shape attr_index_t iv_count; uint8_t type; + shape_id_t parent_id; }; typedef struct rb_shape rb_shape_t; @@ -59,21 +59,6 @@ enum shape_type { SHAPE_IVAR_UNDEF, }; -static inline shape_id_t -IMEMO_CACHED_SHAPE_ID(VALUE cc) -{ - RBIMPL_ASSERT_TYPE((VALUE)cc, RUBY_T_IMEMO); - return (shape_id_t)(SHAPE_MASK & (RBASIC(cc)->flags >> SHAPE_FLAG_SHIFT)); -} - -static inline void -IMEMO_SET_CACHED_SHAPE_ID(VALUE cc, shape_id_t shape_id) -{ - RBIMPL_ASSERT_TYPE((VALUE)cc, RUBY_T_IMEMO); - RBASIC(cc)->flags &= SHAPE_FLAG_MASK; - RBASIC(cc)->flags |= ((VALUE)(shape_id) << SHAPE_FLAG_SHIFT); -} - #if SHAPE_IN_BASIC_FLAGS static inline shape_id_t RBASIC_SHAPE_ID(VALUE obj) @@ -141,6 +126,7 @@ shape_id_t rb_shape_id(rb_shape_t * shape); MJIT_SYMBOL_EXPORT_END rb_shape_t * rb_shape_alloc(ID edge_name, rb_shape_t * parent); +rb_shape_t * rb_shape_alloc_with_parent_id(ID edge_name, shape_id_t parent_id); bool rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id); |