From 0d84c89ad3c175834b395da6c0d77d878f564d71 Mon Sep 17 00:00:00 2001 From: Eduardo Souza Date: Wed, 7 Feb 2024 16:54:42 +1100 Subject: [PATCH] Ask from binding if GC is disabled (#126) Upstream PR: https://github.com/mmtk/mmtk-core/pull/1075 Julia PR: https://github.com/mmtk/julia/pull/35 --------- Co-authored-by: mmtkgc-bot (cherry picked from commit eac7e884e313f9b4fa24d70038f4a294e0a71850) # Conflicts: # mmtk/Cargo.lock # mmtk/Cargo.toml # mmtk/api/mmtk.h # mmtk/src/api.rs # mmtk/src/collection.rs --- mmtk/Cargo.lock | 10 ++++++++++ mmtk/Cargo.toml | 9 +++++++++ mmtk/api/mmtk.h | 14 ++++++++++++++ mmtk/src/api.rs | 8 ++++++++ mmtk/src/collection.rs | 24 ++++++++++++++++++++++++ 5 files changed, 65 insertions(+) diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 38f88d13..3fac143b 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -533,8 +533,13 @@ dependencies = [ [[package]] name = "mmtk" +<<<<<<< HEAD version = "0.17.0" source = "git+https://github.com/mmtk/mmtk-core.git?rev=b2968e3903a5730f2ce33654d75dd2e53b26d8b2#b2968e3903a5730f2ce33654d75dd2e53b26d8b2" +======= +version = "0.22.1" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=7cafe560139211c0e3a74815d2e288278506099d#7cafe560139211c0e3a74815d2e288278506099d" +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) dependencies = [ "atomic 0.5.1", "atomic-traits", @@ -577,8 +582,13 @@ dependencies = [ [[package]] name = "mmtk-macros" +<<<<<<< HEAD version = "0.17.0" source = "git+https://github.com/mmtk/mmtk-core.git?rev=b2968e3903a5730f2ce33654d75dd2e53b26d8b2#b2968e3903a5730f2ce33654d75dd2e53b26d8b2" +======= +version = "0.22.1" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=7cafe560139211c0e3a74815d2e288278506099d#7cafe560139211c0e3a74815d2e288278506099d" +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 122c5ce2..1cd8f187 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -10,7 +10,11 @@ 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" +<<<<<<< HEAD julia_version = "2fe85be017c11392f7268fba52699d642944bd3b" +======= +julia_version = "22524a81f9920a8ecc70f195d53b145761de2fa0" +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) [lib] crate-type = ["staticlib", "rlib", "dylib"] @@ -28,8 +32,13 @@ lazy_static = "1.1" # These changes are safe: # - change branch # - change repo name +<<<<<<< HEAD # But other changes including adding/removing whitespaces in commented lines may break the CI. mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "b2968e3903a5730f2ce33654d75dd2e53b26d8b2" } +======= +# But other changes including adding/removing whitespaces in commented lines may break the CI +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev="7cafe560139211c0e3a74815d2e288278506099d" } +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } log = {version = "0.4", features = ["max_level_trace", "release_max_level_off"] } diff --git a/mmtk/api/mmtk.h b/mmtk/api/mmtk.h index 8f2453eb..126f2c9d 100644 --- a/mmtk/api/mmtk.h +++ b/mmtk/api/mmtk.h @@ -115,6 +115,7 @@ typedef struct { /** * Misc */ +<<<<<<< HEAD extern void gc_init(long long min_heap_size, long long max_heap_size, Julia_Upcalls *calls, long header_size); extern bool will_never_move(void* object); extern bool process(char* name, char* value); @@ -128,6 +129,19 @@ extern void start_worker(void *tls, void* worker, void* mmtk); extern void process_julia_obj(void* addr); extern void register_finalizer(void* obj, void* function, bool is_ptr); extern void run_finalizers_for_obj(void* obj); +======= +extern void mmtk_gc_init(uintptr_t min_heap_size, uintptr_t max_heap_size, uintptr_t n_gcthreads, Julia_Upcalls *calls, uintptr_t header_size, uintptr_t tag); +extern bool mmtk_will_never_move(void* object); +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_start_control_collector(void *tls); +extern void mmtk_start_worker(void *tls, void* worker, void* mmtk); +extern void mmtk_process_julia_obj(void* addr); +extern void mmtk_register_finalizer(void* obj, void* function, bool is_ptr); +extern void mmtk_run_finalizers_for_obj(void* obj); +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) extern void mmtk_run_finalizers(bool at_exit); extern void mmtk_gc_poll(void *tls); diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 2e0df1a1..4e2c2745 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -4,8 +4,12 @@ use crate::reference_glue::JuliaFinalizableObject; use crate::JuliaVM; use crate::Julia_Upcalls; +<<<<<<< HEAD use crate::BLOCK_FOR_GC; use crate::FINALIZER_ROOTS; +======= +use crate::JULIA_HEADER_SIZE; +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) use crate::SINGLETON; use crate::UPCALLS; use crate::{ @@ -197,6 +201,7 @@ pub extern "C" fn initialize_collection(tls: VMThread) { } #[no_mangle] +<<<<<<< HEAD pub extern "C" fn enable_collection() { if AtomicBool::load(&DISABLED_GC, Ordering::SeqCst) { memory_manager::enable_collection(&SINGLETON); @@ -222,6 +227,9 @@ pub extern "C" fn disable_collection() { #[no_mangle] pub extern "C" fn used_bytes() -> usize { +======= +pub extern "C" fn mmtk_used_bytes() -> usize { +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) memory_manager::used_bytes(&SINGLETON) } diff --git a/mmtk/src/collection.rs b/mmtk/src/collection.rs index d90de371..41e1641d 100644 --- a/mmtk/src/collection.rs +++ b/mmtk/src/collection.rs @@ -11,14 +11,22 @@ use mmtk::util::opaque_pointer::*; use mmtk::util::Address; use mmtk::vm::{Collection, GCThreadContext}; use mmtk::Mutator; +<<<<<<< HEAD use mmtk::MutatorContext; use std::sync::atomic::{AtomicBool, Ordering}; +======= +use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicU32, AtomicU64, Ordering}; +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) use crate::{BLOCK_FOR_GC, FINALIZERS_RUNNING, STW_COND, WORLD_HAS_STOPPED}; const GC_THREAD_KIND_CONTROLLER: libc::c_int = 0; const GC_THREAD_KIND_WORKER: libc::c_int = 1; +extern "C" { + pub static jl_gc_disable_counter: AtomicU32; +} + pub struct VMCollection {} impl Collection for VMCollection { @@ -132,11 +140,27 @@ impl Collection for VMCollection { unsafe { ((*UPCALLS).jl_throw_out_of_memory_error)() }; } +<<<<<<< HEAD fn prepare_mutator>( _tls_w: VMWorkerThread, _tls_m: VMMutatorThread, _mutator: &T, ) { +======= + 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 { + match crate::SINGLETON.get_plan().generational() { + Some(gen) => gen.is_current_gc_nursery(), + None => false, +>>>>>>> eac7e88 (Ask from binding if GC is disabled (#126)) } }