mmtk/util/analysis/
gc_count.rs

1use crate::util::analysis::RtAnalysis;
2use crate::util::statistics::counter::EventCounter;
3use crate::vm::VMBinding;
4use crate::MMTK;
5use std::sync::{Arc, Mutex};
6
7/**
8 * Simple analysis routine that counts the number of collections over course of program execution
9 */
10pub 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            // The analysis routine simply updates the counter when the allocation hook is called
25            self.counter.lock().unwrap().inc();
26        }
27    }
28
29    fn set_running(&mut self, running: bool) {
30        self.running = running;
31    }
32}