Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to MMTk core PR #817 #141

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mmtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"]
# - change branch/rev
# - change repo name
# But other changes including adding/removing whitespaces in commented lines may break the CI.
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "e309f9351dff9cd0c8f3f590002c6edafd158c82" }
mmtk = { git = "https://github.com/ArberSephirotheca/mmtk-core.git", rev = "1bd9b39053f5596204c196746f50a2dd51128c7c" }
# Uncomment the following to build locally - if you change the path locally, do not commit the change in a PR
# mmtk = { path = "../repos/mmtk-core" }

Expand Down
84 changes: 49 additions & 35 deletions mmtk/src/active_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,62 @@ use mmtk::vm::ActivePlan;
use mmtk::Mutator;
use mmtk::Plan;
use std::mem;
use std::sync::atomic::{AtomicUsize, Ordering};
use JikesRVM;
use JTOC_BASE;
use SINGLETON;

static MUTATOR_COUNTER: AtomicUsize = AtomicUsize::new(0);
use std::sync::{Mutex, MutexGuard};

lazy_static! {
static ref MUTATOR_LOCK: Mutex<()> = Mutex::new(());
}

struct JikesRVMMutatorIterator<'a> {
_guard: MutexGuard<'a, ()>,
counter: usize,
}

impl<'a> JikesRVMMutatorIterator<'a> {
fn new(guard: MutexGuard<'a, ()>) -> Self {
Self {
_guard: guard,
counter: 0,
}
}
}

impl<'a> Iterator for JikesRVMMutatorIterator<'a> {
type Item = &'a mut Mutator<JikesRVM>;

fn next(&mut self) -> Option<Self::Item> {
// We don't need this in the loop for STW-GC
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
loop {
let idx = self.counter;
self.counter += 1;
if idx >= num_threads {
return None;
} else {
let t = unsafe { VMCollection::thread_from_index(idx) };
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
if is_mutator {
unsafe {
let mutator = (t + MMTK_HANDLE_FIELD_OFFSET).load::<usize>();
let ret = &mut *(mutator as *mut Mutator<JikesRVM>);
return Some(ret);
}
}
}
}
}
}

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

impl ActivePlan<JikesRVM> for VMActivePlan {
fn number_of_mutators() -> usize {
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
let mut num_mutators = 0usize;
for idx in 0..num_threads {
let t = unsafe { VMCollection::thread_from_index(idx) };
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
if is_mutator {
num_mutators += 1;
}
}
num_mutators
Self::mutators().count()
}

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

fn reset_mutator_iterator() {
MUTATOR_COUNTER.store(0, Ordering::Relaxed);
}

fn get_next_mutator() -> Option<&'static mut Mutator<JikesRVM>> {
// We don't need this in the loop for STW-GC
let num_threads = unsafe { (JTOC_BASE + NUM_THREADS_FIELD_OFFSET).load::<usize>() };
loop {
let idx = MUTATOR_COUNTER.fetch_add(1, Ordering::Relaxed);
if idx >= num_threads {
return None;
} else {
let t = unsafe { VMCollection::thread_from_index(idx) };
let is_mutator = unsafe { !(t + IS_COLLECTOR_FIELD_OFFSET).load::<bool>() };
if is_mutator {
unsafe {
let mutator = (t + MMTK_HANDLE_FIELD_OFFSET).load::<usize>();
let ret = &mut *(mutator as *mut Mutator<JikesRVM>);
return Some(ret);
}
}
}
}
fn mutators<'a>() -> Box<dyn Iterator<Item = &'a mut Mutator<JikesRVM>> + 'a> {
let guard = MUTATOR_LOCK.lock().unwrap();
Box::new(JikesRVMMutatorIterator::new(guard))
}
}