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

Use MMTk builder API #118

Merged
merged 6 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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 = "f0fed5fc01438162115120c7551d4eb96e888bc2" }
mmtk = { git = "https://github.com/qinsoon/mmtk-core.git", rev = "c8f3ce04f123b8c71379be186d6178910ece0164" }
# 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
27 changes: 19 additions & 8 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use mmtk::util::{Address, ObjectReference};
use mmtk::vm::{ReferenceGlue, VMBinding};
use mmtk::AllocationSemantics;
use mmtk::Mutator;
use mmtk::MMTK;
use std::ffi::CStr;
use std::sync::atomic::Ordering;
use JikesRVM;
use BUILDER;
use JTOC_BASE;
use SINGLETON;

Expand All @@ -29,12 +30,22 @@ pub extern "C" fn jikesrvm_gc_init(jtoc: *mut c_void, heap_size: usize) {
JTOC_BASE = Address::from_mut_ptr(jtoc);
BOOT_THREAD = OpaquePointer::from_address(VMCollection::thread_from_id(1));
}
// MMTk should not be used before gc_init, and gc_init is single threaded. It is fine we get a mutable reference from the singleton.
#[allow(clippy::cast_ref_to_mut)]
let singleton_mut =
unsafe { &mut *(&*SINGLETON as *const MMTK<JikesRVM> as *mut MMTK<JikesRVM>) };
memory_manager::gc_init(singleton_mut, heap_size);
debug_assert!(731 == JikesRVM::mm_entrypoint_test(21, 34, 9, 8));

// set heap size
memory_manager::process(&BUILDER, "heap_size", heap_size.to_string().as_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mmtk-core can expose &mut Options directly, we won't need to convert heap_size into a string.


// set plan based on features.
#[cfg(feature = "nogc")]
memory_manager::process(&BUILDER, "plan", "NoGC");
#[cfg(feature = "semispace")]
memory_manager::process(&BUILDER, "plan", "SemiSpace");
#[cfg(feature = "marksweep")]
memory_manager::process(&BUILDER, "plan", "MarkSweep");

// Make sure that we haven't initialized MMTk (by accident) yet
assert!(!crate::MMTK_INITIALIZED.load(Ordering::Relaxed));
// Make sure we initialize MMTk here
lazy_static::initialize(&SINGLETON);
}

#[no_mangle]
Expand Down Expand Up @@ -216,7 +227,7 @@ pub extern "C" fn process(name: *const c_char, value: *const c_char) -> i32 {
let name_str: &CStr = unsafe { CStr::from_ptr(name) };
let value_str: &CStr = unsafe { CStr::from_ptr(value) };
memory_manager::process(
&SINGLETON,
&BUILDER,
name_str.to_str().unwrap(),
value_str.to_str().unwrap(),
) as i32
Expand Down
19 changes: 11 additions & 8 deletions mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate log;
use mmtk::plan::PlanConstraints;
use mmtk::util::address::Address;
use mmtk::vm::VMBinding;
use mmtk::MMTKBuilder;
use mmtk::MMTK;

use collection::BOOT_THREAD;
Expand Down Expand Up @@ -76,15 +77,17 @@ pub const SELECTED_CONSTRAINTS: PlanConstraints = mmtk::plan::SS_CONSTRAINTS;
#[cfg(feature = "marksweep")]
pub const SELECTED_CONSTRAINTS: PlanConstraints = mmtk::plan::MS_CONSTRAINTS;

use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;

pub static MMTK_INITIALIZED: AtomicBool = AtomicBool::new(false);

lazy_static! {
pub static ref BUILDER: MMTKBuilder = MMTKBuilder::new();
pub static ref SINGLETON: MMTK<JikesRVM> = {
#[cfg(feature = "nogc")]
std::env::set_var("MMTK_PLAN", "NoGC");
#[cfg(feature = "semispace")]
std::env::set_var("MMTK_PLAN", "SemiSpace");
#[cfg(feature = "marksweep")]
std::env::set_var("MMTK_PLAN", "MarkSweep");

MMTK::new()
assert!(!MMTK_INITIALIZED.load(Ordering::Relaxed));
let ret = mmtk::memory_manager::gc_init(&BUILDER);
MMTK_INITIALIZED.store(true, std::sync::atomic::Ordering::Relaxed);
*ret
};
}