Skip to content

Skip conservative stack scanning if the current GC won't move objects #184

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

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,30 +539,30 @@ fn assert_is_object(object: ObjectReference) {
#[no_mangle]
pub extern "C" fn mmtk_pin_object(object: ObjectReference) -> bool {
assert_is_object(object);
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

memory_manager::pin_object(object)
}

#[no_mangle]
pub extern "C" fn mmtk_unpin_object(object: ObjectReference) -> bool {
assert_is_object(object);
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

memory_manager::unpin_object(object)
}

#[no_mangle]
pub extern "C" fn mmtk_is_object_pinned(object: ObjectReference) -> bool {
assert_is_object(object);
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

memory_manager::is_pinned(object)
}

#[no_mangle]
pub extern "C" fn mmtk_pin_pointer(addr: Address) -> bool {
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

if mmtk_object_is_managed_by_mmtk(addr.as_usize()) {
if !crate::object_model::is_addr_in_immixspace(addr) {
Expand Down Expand Up @@ -600,7 +600,7 @@ pub extern "C" fn mmtk_pin_pointer(addr: Address) -> bool {

#[no_mangle]
pub extern "C" fn mmtk_unpin_pointer(addr: Address) -> bool {
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

if mmtk_object_is_managed_by_mmtk(addr.as_usize()) {
if !crate::object_model::is_addr_in_immixspace(addr) {
Expand Down Expand Up @@ -637,7 +637,7 @@ pub extern "C" fn mmtk_unpin_pointer(addr: Address) -> bool {

#[no_mangle]
pub extern "C" fn mmtk_is_pointer_pinned(addr: Address) -> bool {
crate::early_return_for_non_moving!(false);
crate::early_return_for_non_moving_build!(false);

if mmtk_object_is_managed_by_mmtk(addr.as_usize()) {
if !crate::object_model::is_addr_in_immixspace(addr) {
Expand Down
12 changes: 12 additions & 0 deletions mmtk/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, Ordering};
use crate::{BLOCK_FOR_GC, STW_COND, WORLD_HAS_STOPPED};

static GC_START: AtomicU64 = AtomicU64::new(0);
static CURRENT_GC_MAY_MOVE: AtomicBool = AtomicBool::new(true);

extern "C" {
pub static jl_gc_disable_counter: AtomicU32;
Expand All @@ -32,6 +33,13 @@ impl Collection<JuliaVM> for VMCollection {

trace!("Stopped the world!");

// Store if the current GC may move objects -- we will use it when the current GC finishes.
// We cache the value here just in case MMTk may clear it before we use the value.
CURRENT_GC_MAY_MOVE.store(
crate::SINGLETON.get_plan().current_gc_may_move_object(),
Ordering::SeqCst,
);

// Tell MMTk the stacks are ready.
{
for mutator in crate::active_plan::VMActivePlan::mutators() {
Expand Down Expand Up @@ -141,6 +149,10 @@ pub fn is_current_gc_nursery() -> bool {
}
}

pub fn is_current_gc_moving() -> bool {
CURRENT_GC_MAY_MOVE.load(Ordering::SeqCst)
}

#[no_mangle]
pub extern "C" fn mmtk_block_thread_for_gc(gc_n_threads: u16) {
AtomicBool::store(&BLOCK_FOR_GC, true, Ordering::SeqCst);
Expand Down
18 changes: 12 additions & 6 deletions mmtk/src/conservative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ lazy_static! {
}

pub fn pin_conservative_roots() {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let mut roots = CONSERVATIVE_ROOTS.lock().unwrap();
let n_roots = roots.len();
Expand All @@ -23,7 +24,8 @@ pub fn pin_conservative_roots() {
}

pub fn unpin_conservative_roots() {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let mut roots = CONSERVATIVE_ROOTS.lock().unwrap();
let n_pinned = roots.len();
Expand All @@ -49,7 +51,8 @@ pub fn mmtk_conservative_scan_task_stack(
ta: *const mmtk_jl_task_t,
buffer: &mut Vec<ObjectReference>,
) {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let mut size: u64 = 0;
let mut ptid: i32 = 0;
Expand Down Expand Up @@ -79,7 +82,8 @@ pub fn mmtk_conservative_scan_ptls_stack(
ptls: &mut mmtk_jl_tls_states_t,
buffer: &mut Vec<ObjectReference>,
) {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let stackbase: Address = Address::from_ptr(ptls.stackbase);
let stacksize = ptls.stacksize;
Expand All @@ -98,7 +102,8 @@ pub fn mmtk_conservative_scan_task_registers(
ta: *const mmtk_jl_task_t,
buffer: &mut Vec<ObjectReference>,
) {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let (lo, hi) = get_range(&unsafe { &*ta }.ctx);
conservative_scan_range(lo, hi, buffer);
Expand All @@ -108,7 +113,8 @@ pub fn mmtk_conservative_scan_ptls_registers(
ptls: &mut mmtk_jl_tls_states_t,
buffer: &mut Vec<ObjectReference>,
) {
crate::early_return_for_non_moving!(());
crate::early_return_for_non_moving_build!(());
crate::early_return_for_current_gc!();

let (lo, hi) = get_range(&ptls.ctx_at_the_time_gc_started);
conservative_scan_range(lo, hi, buffer);
Expand Down
13 changes: 12 additions & 1 deletion mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,22 @@ pub struct Julia_Upcalls {

pub static mut UPCALLS: *const Julia_Upcalls = null_mut();

/// Skip some methods for a non moving build.
#[macro_export]
macro_rules! early_return_for_non_moving {
macro_rules! early_return_for_non_moving_build {
($ret_val:expr) => {
if cfg!(feature = "non_moving") {
return $ret_val;
}
};
}

/// Skip some methods if the current GC does not move objects
#[macro_export]
macro_rules! early_return_for_current_gc {
() => {
if !crate::collection::is_current_gc_moving() {
return;
}
};
}
Loading