Skip to content

Commit 2520fd6

Browse files
authored
Move inside_harness to GlobalState (#1321)
This can be useful in case we want to be able to measure timing in parts of the code where we don't have access to the `MMTK` struct.
1 parent 1ef94b6 commit 2520fd6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/global_state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct GlobalState {
4242
pub(crate) stacks_prepared: AtomicBool,
4343
/// A counter that keeps tracks of the number of bytes allocated since last stress test
4444
pub(crate) allocation_bytes: AtomicUsize,
45+
/// Are we inside the benchmark harness?
46+
pub(crate) inside_harness: AtomicBool,
4547
/// A counteer that keeps tracks of the number of bytes allocated by malloc
4648
#[cfg(feature = "malloc_counted_size")]
4749
pub(crate) malloc_bytes: AtomicUsize,
@@ -200,6 +202,7 @@ impl Default for GlobalState {
200202
cur_collection_attempts: AtomicUsize::new(0),
201203
scanned_stacks: AtomicUsize::new(0),
202204
allocation_bytes: AtomicUsize::new(0),
205+
inside_harness: AtomicBool::new(false),
203206
#[cfg(feature = "malloc_counted_size")]
204207
malloc_bytes: AtomicUsize::new(0),
205208
live_bytes_in_last_gc: AtomicRefCell::new(HashMap::new()),

src/mmtk.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::vm::VMBinding;
2929
use std::cell::UnsafeCell;
3030
use std::collections::HashMap;
3131
use std::default::Default;
32-
use std::sync::atomic::{AtomicBool, Ordering};
32+
#[cfg(feature = "sanity")]
33+
use std::sync::atomic::AtomicBool;
34+
use std::sync::atomic::Ordering;
3335
use std::sync::Arc;
3436
use std::sync::Mutex;
3537

@@ -123,7 +125,6 @@ pub struct MMTK<VM: VMBinding> {
123125
pub(crate) gc_trigger: Arc<GCTrigger<VM>>,
124126
pub(crate) gc_requester: Arc<GCRequester<VM>>,
125127
pub(crate) stats: Arc<Stats>,
126-
inside_harness: AtomicBool,
127128
#[cfg(feature = "sanity")]
128129
inside_sanity: AtomicBool,
129130
/// Analysis counters. The feature analysis allows us to periodically stop the world and collect some statistics.
@@ -220,7 +221,6 @@ impl<VM: VMBinding> MMTK<VM> {
220221
sanity_checker: Mutex::new(SanityChecker::new()),
221222
#[cfg(feature = "sanity")]
222223
inside_sanity: AtomicBool::new(false),
223-
inside_harness: AtomicBool::new(false),
224224
#[cfg(feature = "extreme_assertions")]
225225
slot_logger: SlotLogger::new(),
226226
#[cfg(feature = "analysis")]
@@ -324,7 +324,7 @@ impl<VM: VMBinding> MMTK<VM> {
324324
pub fn harness_begin(&self, tls: VMMutatorThread) {
325325
probe!(mmtk, harness_begin);
326326
self.handle_user_collection_request(tls, true, true);
327-
self.inside_harness.store(true, Ordering::SeqCst);
327+
self.state.inside_harness.store(true, Ordering::SeqCst);
328328
self.stats.start_all();
329329
self.scheduler.enable_stat();
330330
}
@@ -334,7 +334,7 @@ impl<VM: VMBinding> MMTK<VM> {
334334
/// This is usually called by the benchmark harness right after the actual benchmark.
335335
pub fn harness_end(&'static self) {
336336
self.stats.stop_all(self);
337-
self.inside_harness.store(false, Ordering::SeqCst);
337+
self.state.inside_harness.store(false, Ordering::SeqCst);
338338
probe!(mmtk, harness_end);
339339
}
340340

0 commit comments

Comments
 (0)