diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 6cc45cd..4ed69da 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -44,9 +44,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "built" @@ -59,9 +59,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "ed2490600f404f2b94c167e31d3ed1d5f3c225a0f3b80230053b3e0b7b962bd9" dependencies = [ "bytemuck_derive", ] @@ -200,9 +200,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "humantime", "is-terminal", @@ -251,9 +251,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "humantime" @@ -284,9 +284,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.14" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" +checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" dependencies = [ "cc", "libc", @@ -338,9 +338,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -376,7 +376,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.22.1" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=42754a5f23fdb513039d7f07e52014ded42c98bf#42754a5f23fdb513039d7f07e52014ded42c98bf" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=7cafe560139211c0e3a74815d2e288278506099d#7cafe560139211c0e3a74815d2e288278506099d" dependencies = [ "atomic", "atomic-traits", @@ -411,7 +411,7 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.22.1" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=42754a5f23fdb513039d7f07e52014ded42c98bf#42754a5f23fdb513039d7f07e52014ded42c98bf" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=7cafe560139211c0e3a74815d2e288278506099d#7cafe560139211c0e3a74815d2e288278506099d" dependencies = [ "proc-macro-error", "proc-macro2", @@ -486,9 +486,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "portable-atomic" @@ -528,9 +528,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -546,9 +546,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" dependencies = [ "either", "rayon-core", @@ -556,9 +556,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -566,9 +566,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -578,9 +578,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -604,9 +604,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ "bitflags", "errno", @@ -718,9 +718,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -768,9 +768,9 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 7342e17..2c03c09 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -37,7 +37,7 @@ features = ["is_mmtk_object", "object_pinning"] # Uncomment the following lines to use mmtk-core from the official repository. git = "https://github.com/mmtk/mmtk-core.git" -rev = "42754a5f23fdb513039d7f07e52014ded42c98bf" +rev = "7cafe560139211c0e3a74815d2e288278506099d" # Uncomment the following line to use mmtk-core from a local repository. #path = "../../mmtk-core" diff --git a/mmtk/src/abi.rs b/mmtk/src/abi.rs index a67faaf..e1ae321 100644 --- a/mmtk/src/abi.rs +++ b/mmtk/src/abi.rs @@ -102,7 +102,7 @@ impl RubyObjectAccess { pub fn suffix_size() -> usize { // In RACTOR_CHECK_MODE, Ruby hides a field after each object to hold the Ractor ID. - unsafe { crate::BINDING_FAST.suffix_size } + unsafe { crate::BINDING_FAST_MUT.suffix_size } } pub fn object_size(&self) -> usize { diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 601326f..3d1d255 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -2,6 +2,7 @@ #![allow(clippy::not_unsafe_ptr_arg_deref)] use std::ffi::CStr; +use std::sync::atomic::Ordering; use crate::abi; use crate::abi::RawVecOfObjRef; @@ -11,6 +12,7 @@ use crate::binding; use crate::binding::RubyBinding; use crate::mmtk; use crate::Ruby; +use crate::BINDING_FAST; use mmtk::memory_manager; use mmtk::memory_manager::mmtk_init; use mmtk::util::alloc::AllocatorInfo; @@ -156,12 +158,12 @@ pub extern "C" fn mmtk_initialize_collection(tls: VMThread) { #[no_mangle] pub extern "C" fn mmtk_enable_collection() { - memory_manager::enable_collection(mmtk()) + BINDING_FAST.gc_enabled.store(true, Ordering::Relaxed); } #[no_mangle] pub extern "C" fn mmtk_disable_collection() { - memory_manager::disable_collection(mmtk()) + BINDING_FAST.gc_enabled.store(false, Ordering::Relaxed); } #[no_mangle] diff --git a/mmtk/src/binding.rs b/mmtk/src/binding.rs index 8acc9a1..6ef1d7e 100644 --- a/mmtk/src/binding.rs +++ b/mmtk/src/binding.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::ffi::CString; +use std::sync::atomic::AtomicBool; use std::sync::Mutex; use libc::c_void; @@ -12,12 +13,25 @@ use crate::ppp::PPPRegistry; use crate::weak_proc::WeakProcessor; use crate::Ruby; -#[derive(Default)] pub struct RubyBindingFast { - pub suffix_size: usize, + pub gc_enabled: AtomicBool, } impl RubyBindingFast { + pub const fn new() -> Self { + Self { + // Mimic the old behavior when the gc_enabled flag was in mmtk-core. + // We may refactor it so that it is false by default. + gc_enabled: AtomicBool::new(true), + } + } +} + +pub struct RubyBindingFastMut { + pub suffix_size: usize, +} + +impl RubyBindingFastMut { pub const fn new() -> Self { Self { suffix_size: 0 } } @@ -48,7 +62,7 @@ impl RubyBinding { upcalls: *const abi::RubyUpcalls, ) -> Self { unsafe { - crate::BINDING_FAST.suffix_size = binding_options.suffix_size; + crate::BINDING_FAST_MUT.suffix_size = binding_options.suffix_size; } Self { mmtk, diff --git a/mmtk/src/collection.rs b/mmtk/src/collection.rs index 2b788bb..3995975 100644 --- a/mmtk/src/collection.rs +++ b/mmtk/src/collection.rs @@ -6,11 +6,16 @@ use mmtk::memory_manager; use mmtk::scheduler::*; use mmtk::util::{VMMutatorThread, VMThread, VMWorkerThread}; use mmtk::vm::{Collection, GCThreadContext}; +use std::sync::atomic::Ordering; use std::thread; pub struct VMCollection {} impl Collection for VMCollection { + fn is_collection_enabled() -> bool { + crate::BINDING_FAST.gc_enabled.load(Ordering::Relaxed) + } + fn stop_all_mutators(tls: VMWorkerThread, mut mutator_visitor: F) where F: FnMut(&'static mut mmtk::Mutator), diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index 1c66664..af95bb3 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -11,7 +11,7 @@ use std::sync::Mutex; use std::thread::ThreadId; use abi::RubyUpcalls; -use binding::{RubyBinding, RubyBindingFast}; +use binding::{RubyBinding, RubyBindingFast, RubyBindingFastMut}; use mmtk::vm::edge_shape::{SimpleEdge, UnimplementedMemorySlice}; use mmtk::vm::VMBinding; use mmtk::MMTK; @@ -55,9 +55,12 @@ impl VMBinding for Ruby { /// The singleton object for the Ruby binding itself. pub static BINDING: OnceCell = OnceCell::new(); +/// Some data needs to be accessed fast. +pub static BINDING_FAST: RubyBindingFast = RubyBindingFast::new(); + /// Some data needs to be accessed fast. /// We sacrifice safety for speed using unsynchronized global variables. -pub static mut BINDING_FAST: RubyBindingFast = RubyBindingFast::new(); +pub static mut BINDING_FAST_MUT: RubyBindingFastMut = RubyBindingFastMut::new(); pub fn binding<'b>() -> &'b RubyBinding { BINDING