summaryrefslogtreecommitdiff
path: root/yjit/src/invariants.rs
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2024-04-29 16:08:06 -0400
committerGitHub <noreply@github.com>2024-04-29 16:08:06 -0400
commitde0ad3be8ee0ac3b1f8e97dae934e82951721061 (patch)
tree366f6739b4aec20ebf37089e13658ace84ee3f33 /yjit/src/invariants.rs
parentadae813c5ff34c7a2981f9d700e86a6095c92774 (diff)
YJIT: Take VM lock when invalidating
We need the lock to patch code safely. This might fix some Ractor related crashes seen on CI.
Diffstat (limited to 'yjit/src/invariants.rs')
-rw-r--r--yjit/src/invariants.rs60
1 files changed, 32 insertions, 28 deletions
diff --git a/yjit/src/invariants.rs b/yjit/src/invariants.rs
index f32d51131d..695a37878f 100644
--- a/yjit/src/invariants.rs
+++ b/yjit/src/invariants.rs
@@ -549,21 +549,23 @@ pub extern "C" fn rb_yjit_invalidate_no_singleton_class(klass: VALUE) {
// We apply this optimization only to Array, Hash, and String for now.
if unsafe { [rb_cArray, rb_cHash, rb_cString].contains(&klass) } {
- let no_singleton_classes = &mut Invariants::get_instance().no_singleton_classes;
- match no_singleton_classes.get_mut(&klass) {
- Some(blocks) => {
- // Invalidate existing blocks and let has_singleton_class_of()
- // return true when they are compiled again
- for block in mem::take(blocks) {
- invalidate_block_version(&block);
- incr_counter!(invalidate_no_singleton_class);
+ with_vm_lock(src_loc!(), || {
+ let no_singleton_classes = &mut Invariants::get_instance().no_singleton_classes;
+ match no_singleton_classes.get_mut(&klass) {
+ Some(blocks) => {
+ // Invalidate existing blocks and let has_singleton_class_of()
+ // return true when they are compiled again
+ for block in mem::take(blocks) {
+ invalidate_block_version(&block);
+ incr_counter!(invalidate_no_singleton_class);
+ }
+ }
+ None => {
+ // Let has_singleton_class_of() return true for this class
+ no_singleton_classes.insert(klass, HashSet::new());
}
}
- None => {
- // Let has_singleton_class_of() return true for this class
- no_singleton_classes.insert(klass, HashSet::new());
- }
- }
+ });
}
}
@@ -576,23 +578,25 @@ pub extern "C" fn rb_yjit_invalidate_ep_is_bp(iseq: IseqPtr) {
return;
}
- // If an EP escape for this ISEQ is detected for the first time, invalidate all blocks
- // associated to the ISEQ.
- let no_ep_escape_iseqs = &mut Invariants::get_instance().no_ep_escape_iseqs;
- match no_ep_escape_iseqs.get_mut(&iseq) {
- Some(blocks) => {
- // Invalidate existing blocks and let jit.ep_is_bp()
- // return true when they are compiled again
- for block in mem::take(blocks) {
- invalidate_block_version(&block);
- incr_counter!(invalidate_no_singleton_class);
+ with_vm_lock(src_loc!(), || {
+ // If an EP escape for this ISEQ is detected for the first time, invalidate all blocks
+ // associated to the ISEQ.
+ let no_ep_escape_iseqs = &mut Invariants::get_instance().no_ep_escape_iseqs;
+ match no_ep_escape_iseqs.get_mut(&iseq) {
+ Some(blocks) => {
+ // Invalidate existing blocks and let jit.ep_is_bp()
+ // return true when they are compiled again
+ for block in mem::take(blocks) {
+ invalidate_block_version(&block);
+ incr_counter!(invalidate_no_singleton_class);
+ }
+ }
+ None => {
+ // Let jit.ep_is_bp() return false for this ISEQ
+ no_ep_escape_iseqs.insert(iseq, HashSet::new());
}
}
- None => {
- // Let jit.ep_is_bp() return false for this ISEQ
- no_ep_escape_iseqs.insert(iseq, HashSet::new());
- }
- }
+ });
}
// Invalidate all generated code and patch C method return code to contain