Files
prometeu-runtime/crates/console/prometeu-vm/src/virtual_machine/gc.rs
T
bquarkz 3899b7f12c
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
feat(vm): add resource diagnostics and macOS stability qualification
2026-10-14 08:26:07 +01:00

53 lines
2.1 KiB
Rust

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<V: RootVisitor + ?Sized>(&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);
}
}
}
}