use super::*; impl VirtualMachine { pub(super) fn handle_safepoint(&mut self) -> Result<(), ResourceFailure> { if self.gc_alloc_threshold > 0 && self.heap.len().saturating_sub(self.last_gc_live_count) >= self.gc_alloc_threshold { #[cfg(feature = "resource-diagnostics")] let (started, before) = (std::time::Instant::now(), self.heap.len()); let roots = self .operand_stack .iter() .chain(self.globals.iter()) .filter_map(crate::roots::value_heap_ref) .chain(self.call_stack.iter().filter_map(|frame| frame.closure)); self.heap.mark_session_roots(roots)?; #[cfg(feature = "resource-diagnostics")] let sweep_started = { self.gc_diagnostics.mark.record(started.elapsed()); std::time::Instant::now() }; self.heap.sweep(); self.last_gc_live_count = self.heap.len(); #[cfg(feature = "resource-diagnostics")] { self.gc_diagnostics.collections += 1; self.gc_diagnostics.reclaimed += (before - self.last_gc_live_count) as u64; self.gc_diagnostics.sweep.record(sweep_started.elapsed()); self.gc_diagnostics.total.record(started.elapsed()); } } if let Some(strings) = &self.strings { #[cfg(feature = "resource-diagnostics")] let started = std::time::Instant::now(); strings.reconcile(); #[cfg(feature = "resource-diagnostics")] self.gc_diagnostics.string_reconciliation.record(started.elapsed()); } Ok(()) } pub fn visit_roots(&self, visitor: &mut V) { for value in self.operand_stack.iter().chain(self.globals.iter()) { visit_value_for_roots(value, visitor); } for frame in &self.call_stack { if let Some(closure) = frame.closure { visitor.visit_heap_ref(closure); } } } }