|
2 | 2 |
|
3 | 3 | use std::{collections::{HashMap, HashSet}, mem}; |
4 | 4 |
|
5 | | -use crate::{backend::lir::{asm_comment, Assembler}, cruby::{iseq_name, rb_callable_method_entry_t, rb_gc_location, ruby_basic_operators, src_loc, with_vm_lock, IseqPtr, RedefinitionFlag, ID, VALUE}, gc::IseqPayload, hir::Invariant, options::debug, state::{zjit_enabled_p, ZJITState}, virtualmem::CodePtr}; |
| 5 | +use crate::{backend::lir::{asm_comment, Assembler}, cruby::{iseq_name, rb_callable_method_entry_t, rb_gc_location, ruby_basic_operators, src_loc, with_vm_lock, IseqPtr, RedefinitionFlag, ID}, gc::IseqPayload, hir::Invariant, options::debug, state::{zjit_enabled_p, ZJITState}, virtualmem::CodePtr}; |
6 | 6 | use crate::stats::with_time_stat; |
7 | 7 | use crate::stats::Counter::invalidation_time_ns; |
8 | 8 | use crate::gc::remove_gc_offsets; |
@@ -70,38 +70,23 @@ impl Invariants { |
70 | 70 |
|
71 | 71 | /// Update ISEQ references in Invariants::ep_escape_iseqs |
72 | 72 | fn update_ep_escape_iseqs(&mut self) { |
73 | | - let mut moved: Vec<IseqPtr> = Vec::with_capacity(self.ep_escape_iseqs.len()); |
74 | | - |
75 | | - self.ep_escape_iseqs.retain(|&old_iseq| { |
76 | | - let new_iseq = unsafe { rb_gc_location(VALUE(old_iseq as usize)) }.0 as IseqPtr; |
77 | | - if old_iseq != new_iseq { |
78 | | - moved.push(new_iseq); |
79 | | - } |
80 | | - old_iseq == new_iseq |
81 | | - }); |
82 | | - |
83 | | - for new_iseq in moved { |
84 | | - self.ep_escape_iseqs.insert(new_iseq); |
85 | | - } |
| 73 | + let updated = std::mem::take(&mut self.ep_escape_iseqs) |
| 74 | + .into_iter() |
| 75 | + .map(|iseq| unsafe { rb_gc_location(iseq.into()) }.as_iseq()) |
| 76 | + .collect(); |
| 77 | + self.ep_escape_iseqs = updated; |
86 | 78 | } |
87 | 79 |
|
88 | 80 | /// Update ISEQ references in Invariants::no_ep_escape_iseq_patch_points |
89 | 81 | fn update_no_ep_escape_iseq_patch_points(&mut self) { |
90 | | - let mut moved: Vec<(IseqPtr, HashSet<PatchPoint>)> = Vec::with_capacity(self.no_ep_escape_iseq_patch_points.len()); |
91 | | - let iseqs: Vec<IseqPtr> = self.no_ep_escape_iseq_patch_points.keys().cloned().collect(); |
92 | | - |
93 | | - for old_iseq in iseqs { |
94 | | - let new_iseq = unsafe { rb_gc_location(VALUE(old_iseq as usize)) }.0 as IseqPtr; |
95 | | - if old_iseq != new_iseq { |
96 | | - let patch_points = self.no_ep_escape_iseq_patch_points.remove(&old_iseq).unwrap(); |
97 | | - // Do not insert patch points to no_ep_escape_iseq_patch_points yet to avoid corrupting keys that had a different ISEQ |
98 | | - moved.push((new_iseq, patch_points)); |
99 | | - } |
100 | | - } |
101 | | - |
102 | | - for (new_iseq, patch_points) in moved { |
103 | | - self.no_ep_escape_iseq_patch_points.insert(new_iseq, patch_points); |
104 | | - } |
| 82 | + let updated = std::mem::take(&mut self.no_ep_escape_iseq_patch_points) |
| 83 | + .into_iter() |
| 84 | + .map(|(iseq, patch_points)| { |
| 85 | + let new_iseq = unsafe { rb_gc_location(iseq.into()) }; |
| 86 | + (new_iseq.as_iseq(), patch_points) |
| 87 | + }) |
| 88 | + .collect(); |
| 89 | + self.no_ep_escape_iseq_patch_points = updated; |
105 | 90 | } |
106 | 91 | } |
107 | 92 |
|
|
0 commit comments