Skip to content

Commit 5feef6f

Browse files
authored
Update to MMTk core PR #817 (#141)
Update for mmtk/mmtk-core#817.
1 parent 6415db7 commit 5feef6f

File tree

3 files changed

+105
-43
lines changed

3 files changed

+105
-43
lines changed

mmtk/Cargo.lock

Lines changed: 55 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mmtk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"]
2828
# - change branch/rev
2929
# - change repo name
3030
# But other changes including adding/removing whitespaces in commented lines may break the CI.
31-
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "e309f9351dff9cd0c8f3f590002c6edafd158c82" }
31+
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "de8bbfe623eee5e915f32870de8f81128df8ad41" }
3232
# Uncomment the following to build locally - if you change the path locally, do not commit the change in a PR
3333
# mmtk = { path = "../repos/mmtk-core" }
3434

mmtk/src/active_plan.rs

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,62 @@ use mmtk::vm::ActivePlan;
66
use mmtk::Mutator;
77
use mmtk::Plan;
88
use std::mem;
9-
use std::sync::atomic::{AtomicUsize, Ordering};
109
use JikesRVM;
1110
use JTOC_BASE;
1211
use SINGLETON;
1312

14-
static MUTATOR_COUNTER: AtomicUsize = AtomicUsize::new(0);
13+
use std::sync::{Mutex, MutexGuard};
14+
15+
lazy_static! {
16+
static ref MUTATOR_LOCK: Mutex<()> = Mutex::new(());
17+
}
18+
19+
struct JikesRVMMutatorIterator<'a> {
20+
_guard: MutexGuard<'a, ()>,
21+
counter: usize,
22+
}
23+
24+
impl<'a> JikesRVMMutatorIterator<'a> {
25+
fn new(guard: MutexGuard<'a, ()>) -> Self {
26+
Self {
27+
_guard: guard,
28+
counter: 0,
29+
}
30+
}
31+
}
32+
33+
impl<'a> Iterator for JikesRVMMutatorIterator<'a> {
34+
type Item = &'a mut Mutator<JikesRVM>;
35+
36+
fn next(&mut self) -> Option<Self::Item> {
37+
// We don't need this in the loop for STW-GC
38+
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
39+
loop {
40+
let idx = self.counter;
41+
self.counter += 1;
42+
if idx >= num_threads {
43+
return None;
44+
} else {
45+
let t = unsafe { VMCollection::thread_from_index(idx) };
46+
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
47+
if is_mutator {
48+
unsafe {
49+
let mutator = (t + MMTK_HANDLE_FIELD_OFFSET).load::<usize>();
50+
let ret = &mut *(mutator as *mut Mutator<JikesRVM>);
51+
return Some(ret);
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
1558

1659
#[derive(Default)]
1760
pub struct VMActivePlan {}
1861

1962
impl ActivePlan<JikesRVM> for VMActivePlan {
2063
fn number_of_mutators() -> usize {
21-
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
22-
let mut num_mutators = 0usize;
23-
for idx in 0..num_threads {
24-
let t = unsafe { VMCollection::thread_from_index(idx) };
25-
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
26-
if is_mutator {
27-
num_mutators += 1;
28-
}
29-
}
30-
num_mutators
64+
Self::mutators().count()
3165
}
3266

3367
fn global() -> &'static dyn Plan<VM = JikesRVM> {
@@ -48,28 +82,8 @@ impl ActivePlan<JikesRVM> for VMActivePlan {
4882
}
4983
}
5084

51-
fn reset_mutator_iterator() {
52-
MUTATOR_COUNTER.store(0, Ordering::Relaxed);
53-
}
54-
55-
fn get_next_mutator() -> Option<&'static mut Mutator<JikesRVM>> {
56-
// We don't need this in the loop for STW-GC
57-
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
58-
loop {
59-
let idx = MUTATOR_COUNTER.fetch_add(1, Ordering::Relaxed);
60-
if idx >= num_threads {
61-
return None;
62-
} else {
63-
let t = unsafe { VMCollection::thread_from_index(idx) };
64-
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
65-
if is_mutator {
66-
unsafe {
67-
let mutator = (t + MMTK_HANDLE_FIELD_OFFSET).load::<usize>();
68-
let ret = &mut *(mutator as *mut Mutator<JikesRVM>);
69-
return Some(ret);
70-
}
71-
}
72-
}
73-
}
85+
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<JikesRVM>> + 'a> {
86+
let guard = MUTATOR_LOCK.lock().unwrap();
87+
Box::new(JikesRVMMutatorIterator::new(guard))
7488
}
7589
}

0 commit comments

Comments
 (0)