mmtk/util/analysis/
gc_count.rs1use crate::util::analysis::RtAnalysis;
2use crate::util::statistics::counter::EventCounter;
3use crate::vm::VMBinding;
4use crate::MMTK;
5use std::sync::{Arc, Mutex};
6
7pub struct GcCounter {
11 running: bool,
12 counter: Arc<Mutex<EventCounter>>,
13}
14
15impl GcCounter {
16 pub fn new(running: bool, counter: Arc<Mutex<EventCounter>>) -> Self {
17 Self { running, counter }
18 }
19}
20
21impl<VM: VMBinding> RtAnalysis<VM> for GcCounter {
22 fn gc_hook(&mut self, _mmtk: &'static MMTK<VM>) {
23 if self.running {
24 self.counter.lock().unwrap().inc();
26 }
27 }
28
29 fn set_running(&mut self, running: bool) {
30 self.running = running;
31 }
32}