File tree 7 files changed +48
-24
lines changed
7 files changed +48
-24
lines changed Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ probe = "0.5"
36
36
features = [" is_mmtk_object" , " object_pinning" ]
37
37
38
38
# 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 "
41
41
42
42
# Uncomment the following line to use mmtk-core from a local repository.
43
43
path = " ../../mmtk-core"
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ impl RubyObjectAccess {
101
101
102
102
pub fn suffix_size ( ) -> usize {
103
103
// 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 }
105
105
}
106
106
107
107
pub fn object_size ( & self ) -> usize {
Original file line number Diff line number Diff line change 2
2
#![ allow( clippy:: not_unsafe_ptr_arg_deref) ]
3
3
4
4
use std:: ffi:: CStr ;
5
+ use std:: sync:: atomic:: Ordering ;
5
6
6
7
use crate :: abi;
7
8
use crate :: abi:: RawVecOfObjRef ;
@@ -11,6 +12,7 @@ use crate::binding;
11
12
use crate :: binding:: RubyBinding ;
12
13
use crate :: mmtk;
13
14
use crate :: Ruby ;
15
+ use crate :: BINDING_FAST ;
14
16
use mmtk:: memory_manager;
15
17
use mmtk:: memory_manager:: mmtk_init;
16
18
use mmtk:: util:: alloc:: AllocatorInfo ;
@@ -167,12 +169,12 @@ pub extern "C" fn mmtk_after_fork(tls: VMThread) {
167
169
168
170
#[ no_mangle]
169
171
pub extern "C" fn mmtk_enable_collection ( ) {
170
- memory_manager :: enable_collection ( mmtk ( ) )
172
+ BINDING_FAST . gc_enabled . store ( true , Ordering :: Relaxed ) ;
171
173
}
172
174
173
175
#[ no_mangle]
174
176
pub extern "C" fn mmtk_disable_collection ( ) {
175
- memory_manager :: disable_collection ( mmtk ( ) )
177
+ BINDING_FAST . gc_enabled . store ( false , Ordering :: Relaxed ) ;
176
178
}
177
179
178
180
#[ no_mangle]
Original file line number Diff line number Diff line change 1
1
use std:: collections:: HashMap ;
2
2
use std:: ffi:: CString ;
3
+ use std:: sync:: atomic:: AtomicBool ;
3
4
use std:: sync:: Mutex ;
4
5
use std:: thread:: JoinHandle ;
5
6
@@ -13,12 +14,25 @@ use crate::ppp::PPPRegistry;
13
14
use crate :: weak_proc:: WeakProcessor ;
14
15
use crate :: Ruby ;
15
16
16
- #[ derive( Default ) ]
17
17
pub struct RubyBindingFast {
18
- pub suffix_size : usize ,
18
+ pub gc_enabled : AtomicBool ,
19
19
}
20
20
21
21
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 {
22
36
pub const fn new ( ) -> Self {
23
37
Self { suffix_size : 0 }
24
38
}
@@ -50,7 +64,7 @@ impl RubyBinding {
50
64
upcalls : * const abi:: RubyUpcalls ,
51
65
) -> Self {
52
66
unsafe {
53
- crate :: BINDING_FAST . suffix_size = binding_options. suffix_size ;
67
+ crate :: BINDING_FAST_MUT . suffix_size = binding_options. suffix_size ;
54
68
}
55
69
Self {
56
70
mmtk,
Original file line number Diff line number Diff line change @@ -6,11 +6,16 @@ use mmtk::memory_manager;
6
6
use mmtk:: scheduler:: * ;
7
7
use mmtk:: util:: { VMMutatorThread , VMThread , VMWorkerThread } ;
8
8
use mmtk:: vm:: { Collection , GCThreadContext } ;
9
+ use std:: sync:: atomic:: Ordering ;
9
10
use std:: thread;
10
11
11
12
pub struct VMCollection { }
12
13
13
14
impl Collection < Ruby > for VMCollection {
15
+ fn is_collection_enabled ( ) -> bool {
16
+ crate :: BINDING_FAST . gc_enabled . load ( Ordering :: Relaxed )
17
+ }
18
+
14
19
fn stop_all_mutators < F > ( tls : VMWorkerThread , mut mutator_visitor : F )
15
20
where
16
21
F : FnMut ( & ' static mut mmtk:: Mutator < Ruby > ) ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use std::sync::Mutex;
11
11
use std:: thread:: ThreadId ;
12
12
13
13
use abi:: RubyUpcalls ;
14
- use binding:: { RubyBinding , RubyBindingFast } ;
14
+ use binding:: { RubyBinding , RubyBindingFast , RubyBindingFastMut } ;
15
15
use mmtk:: vm:: edge_shape:: { SimpleEdge , UnimplementedMemorySlice } ;
16
16
use mmtk:: vm:: VMBinding ;
17
17
use mmtk:: MMTK ;
@@ -55,9 +55,12 @@ impl VMBinding for Ruby {
55
55
/// The singleton object for the Ruby binding itself.
56
56
pub static BINDING : OnceCell < RubyBinding > = OnceCell :: new ( ) ;
57
57
58
+ /// Some data needs to be accessed fast.
59
+ pub static BINDING_FAST : RubyBindingFast = RubyBindingFast :: new ( ) ;
60
+
58
61
/// Some data needs to be accessed fast.
59
62
/// 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 ( ) ;
61
64
62
65
pub fn binding < ' b > ( ) -> & ' b RubyBinding {
63
66
BINDING
You can’t perform that action at this time.
0 commit comments