Skip to content

Commit

Permalink
Ask from binding if GC is disabled (#126)
Browse files Browse the repository at this point in the history
Upstream PR: mmtk/mmtk-core#1075
Julia PR: mmtk/julia#35

---------

Co-authored-by: mmtkgc-bot <[email protected]>
  • Loading branch information
udesou and mmtkgc-bot authored Feb 7, 2024
1 parent 6f38359 commit eac7e88
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
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.

4 changes: 2 additions & 2 deletions mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
[package.metadata.julia]
# Our CI matches the following line and extract mmtk/julia. If this line is updated, please check ci yaml files and make sure it works.
julia_repo = "https://github.com/mmtk/julia.git"
julia_version = "5c406d9bb20d76e2298a6101f171cfac491f651c"
julia_version = "22524a81f9920a8ecc70f195d53b145761de2fa0"

[lib]
crate-type = ["cdylib"]
Expand All @@ -31,7 +31,7 @@ lazy_static = "1.1"
# - change branch
# - 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="ef2bd6d043d8675badaa415db89be7b52439725f" }
mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev="7cafe560139211c0e3a74815d2e288278506099d" }
# Uncomment the following to build locally
# mmtk = { path = "../repos/mmtk-core" }
log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"] }
Expand Down
2 changes: 0 additions & 2 deletions mmtk/api/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ extern bool mmtk_process(char* name, char* value);
extern void mmtk_scan_region(void);
extern void mmtk_handle_user_collection_request(void *tls, uint8_t collection);
extern void mmtk_initialize_collection(void* tls);
extern void mmtk_enable_collection(void);
extern void mmtk_disable_collection(void);
extern void mmtk_start_control_collector(void *tls);
extern void mmtk_start_worker(void *tls, void* worker, void* mmtk);
extern void mmtk_process_julia_obj(void* addr);
Expand Down
25 changes: 0 additions & 25 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use crate::JuliaVM;
use crate::Julia_Upcalls;
use crate::BLOCK_FOR_GC;
use crate::JULIA_HEADER_SIZE;
use crate::SINGLETON;
use crate::UPCALLS;
Expand Down Expand Up @@ -240,30 +239,6 @@ pub extern "C" fn mmtk_initialize_collection(tls: VMThread) {
memory_manager::initialize_collection(&SINGLETON, tls);
}

#[no_mangle]
pub extern "C" fn mmtk_enable_collection() {
if AtomicBool::load(&DISABLED_GC, Ordering::SeqCst) {
memory_manager::enable_collection(&SINGLETON);
AtomicBool::store(&DISABLED_GC, false, Ordering::SeqCst);
}
}

#[no_mangle]
pub extern "C" fn mmtk_disable_collection() {
if AtomicBool::load(&DISABLED_GC, Ordering::SeqCst) == false {
AtomicBool::store(&DISABLED_GC, true, Ordering::SeqCst);
memory_manager::disable_collection(&SINGLETON);
}

// if user has triggered GC, wait until GC is finished
while AtomicIsize::load(&USER_TRIGGERED_GC, Ordering::SeqCst) != 0
|| AtomicBool::load(&BLOCK_FOR_GC, Ordering::SeqCst)
{
info!("Waiting for a triggered gc to finish...");
unsafe { ((*UPCALLS).wait_in_a_safepoint)() };
}
}

#[no_mangle]
pub extern "C" fn mmtk_used_bytes() -> usize {
memory_manager::used_bytes(&SINGLETON)
Expand Down
10 changes: 9 additions & 1 deletion mmtk/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ use mmtk::util::alloc::AllocationError;
use mmtk::util::opaque_pointer::*;
use mmtk::vm::{Collection, GCThreadContext};
use mmtk::Mutator;
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicU64, Ordering};
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicU32, AtomicU64, Ordering};

use crate::{BLOCK_FOR_GC, STW_COND, WORLD_HAS_STOPPED};

static GC_START: AtomicU64 = AtomicU64::new(0);

extern "C" {
pub static jl_gc_disable_counter: AtomicU32;
}

pub struct VMCollection {}

impl Collection<JuliaVM> for VMCollection {
Expand Down Expand Up @@ -100,6 +104,10 @@ impl Collection<JuliaVM> for VMCollection {
fn vm_live_bytes() -> usize {
crate::api::JULIA_MALLOC_BYTES.load(Ordering::SeqCst)
}

fn is_collection_enabled() -> bool {
unsafe { AtomicU32::load(&jl_gc_disable_counter, Ordering::SeqCst) <= 0 }
}
}

pub fn is_current_gc_nursery() -> bool {
Expand Down

0 comments on commit eac7e88

Please sign in to comment.