Skip to content

Commit 81ecc45

Browse files
committed
Merge branch 'master' into feature/fork
2 parents 06753f0 + 5ccaf8e commit 81ecc45

File tree

7 files changed

+48
-24
lines changed

7 files changed

+48
-24
lines changed

mmtk/Cargo.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mmtk/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ probe = "0.5"
3636
features = ["is_mmtk_object", "object_pinning"]
3737

3838
# Uncomment the following lines to use mmtk-core from the official repository.
39-
#git = "https://github.com/wks/mmtk-core.git"
40-
#rev = "7cb0b2c12be341c084e03f2cd943fad8ac088f83"
39+
#git = "https://github.com/mmtk/mmtk-core.git"
40+
#rev = "42754a5f23fdb513039d7f07e52014ded42c98bf"
4141

4242
# Uncomment the following line to use mmtk-core from a local repository.
4343
path = "../../mmtk-core"

mmtk/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl RubyObjectAccess {
101101

102102
pub fn suffix_size() -> usize {
103103
// In RACTOR_CHECK_MODE, Ruby hides a field after each object to hold the Ractor ID.
104-
unsafe { crate::BINDING_FAST.suffix_size }
104+
unsafe { crate::BINDING_FAST_MUT.suffix_size }
105105
}
106106

107107
pub fn object_size(&self) -> usize {

mmtk/src/api.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(clippy::not_unsafe_ptr_arg_deref)]
33

44
use std::ffi::CStr;
5+
use std::sync::atomic::Ordering;
56

67
use crate::abi;
78
use crate::abi::RawVecOfObjRef;
@@ -11,6 +12,7 @@ use crate::binding;
1112
use crate::binding::RubyBinding;
1213
use crate::mmtk;
1314
use crate::Ruby;
15+
use crate::BINDING_FAST;
1416
use mmtk::memory_manager;
1517
use mmtk::memory_manager::mmtk_init;
1618
use mmtk::util::alloc::AllocatorInfo;
@@ -167,12 +169,12 @@ pub extern "C" fn mmtk_after_fork(tls: VMThread) {
167169

168170
#[no_mangle]
169171
pub extern "C" fn mmtk_enable_collection() {
170-
memory_manager::enable_collection(mmtk())
172+
BINDING_FAST.gc_enabled.store(true, Ordering::Relaxed);
171173
}
172174

173175
#[no_mangle]
174176
pub extern "C" fn mmtk_disable_collection() {
175-
memory_manager::disable_collection(mmtk())
177+
BINDING_FAST.gc_enabled.store(false, Ordering::Relaxed);
176178
}
177179

178180
#[no_mangle]

mmtk/src/binding.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22
use std::ffi::CString;
3+
use std::sync::atomic::AtomicBool;
34
use std::sync::Mutex;
45
use std::thread::JoinHandle;
56

@@ -13,12 +14,25 @@ use crate::ppp::PPPRegistry;
1314
use crate::weak_proc::WeakProcessor;
1415
use crate::Ruby;
1516

16-
#[derive(Default)]
1717
pub struct RubyBindingFast {
18-
pub suffix_size: usize,
18+
pub gc_enabled: AtomicBool,
1919
}
2020

2121
impl RubyBindingFast {
22+
pub const fn new() -> Self {
23+
Self {
24+
// Mimic the old behavior when the gc_enabled flag was in mmtk-core.
25+
// We may refactor it so that it is false by default.
26+
gc_enabled: AtomicBool::new(true),
27+
}
28+
}
29+
}
30+
31+
pub struct RubyBindingFastMut {
32+
pub suffix_size: usize,
33+
}
34+
35+
impl RubyBindingFastMut {
2236
pub const fn new() -> Self {
2337
Self { suffix_size: 0 }
2438
}
@@ -50,7 +64,7 @@ impl RubyBinding {
5064
upcalls: *const abi::RubyUpcalls,
5165
) -> Self {
5266
unsafe {
53-
crate::BINDING_FAST.suffix_size = binding_options.suffix_size;
67+
crate::BINDING_FAST_MUT.suffix_size = binding_options.suffix_size;
5468
}
5569
Self {
5670
mmtk,

mmtk/src/collection.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ use mmtk::memory_manager;
66
use mmtk::scheduler::*;
77
use mmtk::util::{VMMutatorThread, VMThread, VMWorkerThread};
88
use mmtk::vm::{Collection, GCThreadContext};
9+
use std::sync::atomic::Ordering;
910
use std::thread;
1011

1112
pub struct VMCollection {}
1213

1314
impl Collection<Ruby> for VMCollection {
15+
fn is_collection_enabled() -> bool {
16+
crate::BINDING_FAST.gc_enabled.load(Ordering::Relaxed)
17+
}
18+
1419
fn stop_all_mutators<F>(tls: VMWorkerThread, mut mutator_visitor: F)
1520
where
1621
F: FnMut(&'static mut mmtk::Mutator<Ruby>),

mmtk/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::sync::Mutex;
1111
use std::thread::ThreadId;
1212

1313
use abi::RubyUpcalls;
14-
use binding::{RubyBinding, RubyBindingFast};
14+
use binding::{RubyBinding, RubyBindingFast, RubyBindingFastMut};
1515
use mmtk::vm::edge_shape::{SimpleEdge, UnimplementedMemorySlice};
1616
use mmtk::vm::VMBinding;
1717
use mmtk::MMTK;
@@ -55,9 +55,12 @@ impl VMBinding for Ruby {
5555
/// The singleton object for the Ruby binding itself.
5656
pub static BINDING: OnceCell<RubyBinding> = OnceCell::new();
5757

58+
/// Some data needs to be accessed fast.
59+
pub static BINDING_FAST: RubyBindingFast = RubyBindingFast::new();
60+
5861
/// Some data needs to be accessed fast.
5962
/// We sacrifice safety for speed using unsynchronized global variables.
60-
pub static mut BINDING_FAST: RubyBindingFast = RubyBindingFast::new();
63+
pub static mut BINDING_FAST_MUT: RubyBindingFastMut = RubyBindingFastMut::new();
6164

6265
pub fn binding<'b>() -> &'b RubyBinding {
6366
BINDING

0 commit comments

Comments
 (0)