Skip to content

Commit 0a6a835

Browse files
committed
Do root scanning in scan_vm_specific_roots
We rely on scan_vm_specific_roots to reach all stacks via the following path: VM -> ractors -> threads -> fibers -> stacks
1 parent 9c9ebef commit 0a6a835

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

gc/mmtk/mmtk.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ rb_mmtk_get_mutators(void (*visit_mutator)(MMTk_Mutator *mutator, void *data), v
203203
static void
204204
rb_mmtk_scan_gc_roots(void)
205205
{
206-
// rb_gc_mark_roots(rb_gc_get_objspace(), NULL);
206+
struct objspace *objspace = rb_gc_get_objspace();
207+
208+
// FIXME: Make `rb_gc_mark_roots` aware that the current thread may not have EC.
209+
// See: https://github.com/ruby/mmtk/issues/22
210+
rb_gc_worker_thread_set_vm_context(&objspace->vm_context);
211+
rb_gc_mark_roots(objspace, NULL);
212+
rb_gc_worker_thread_unset_vm_context(&objspace->vm_context);
207213
}
208214

209215
static int
@@ -242,18 +248,6 @@ rb_mmtk_scan_objspace(void)
242248
}
243249
}
244250

245-
static void
246-
rb_mmtk_scan_roots_in_mutator_thread(MMTk_VMMutatorThread mutator, MMTk_VMWorkerThread worker)
247-
{
248-
if (mutator->gc_mutator_p) {
249-
struct objspace *objspace = rb_gc_get_objspace();
250-
251-
rb_gc_worker_thread_set_vm_context(&objspace->vm_context);
252-
rb_gc_mark_roots(objspace, NULL);
253-
rb_gc_worker_thread_unset_vm_context(&objspace->vm_context);
254-
}
255-
}
256-
257251
static void
258252
rb_mmtk_scan_object_ruby_style(MMTk_ObjectReference object)
259253
{
@@ -402,7 +396,6 @@ MMTk_RubyUpcalls ruby_upcalls = {
402396
rb_mmtk_get_mutators,
403397
rb_mmtk_scan_gc_roots,
404398
rb_mmtk_scan_objspace,
405-
rb_mmtk_scan_roots_in_mutator_thread,
406399
rb_mmtk_scan_object_ruby_style,
407400
rb_mmtk_call_gc_mark_children,
408401
rb_mmtk_call_obj_free,

gc/mmtk/mmtk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ typedef struct MMTk_RubyUpcalls {
6161
void (*get_mutators)(void (*visit_mutator)(MMTk_Mutator*, void*), void *data);
6262
void (*scan_gc_roots)(void);
6363
void (*scan_objspace)(void);
64-
void (*scan_roots_in_mutator_thread)(MMTk_VMMutatorThread mutator_tls,
65-
MMTk_VMWorkerThread worker_tls);
6664
void (*scan_object_ruby_style)(MMTk_ObjectReference object);
6765
void (*call_gc_mark_children)(MMTk_ObjectReference object);
6866
void (*call_obj_free)(MMTk_ObjectReference object);

gc/mmtk/src/abi.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ pub struct RubyUpcalls {
315315
),
316316
pub scan_gc_roots: extern "C" fn(),
317317
pub scan_objspace: extern "C" fn(),
318-
pub scan_roots_in_mutator_thread:
319-
extern "C" fn(mutator_tls: VMMutatorThread, worker_tls: VMWorkerThread),
320318
pub scan_object_ruby_style: extern "C" fn(object: ObjectReference),
321319
pub call_gc_mark_children: extern "C" fn(object: ObjectReference),
322320
pub call_obj_free: extern "C" fn(object: ObjectReference),

gc/mmtk/src/scanning.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{upcalls, Ruby, RubySlot};
55
use mmtk::scheduler::{GCWork, GCWorker, WorkBucketStage};
66
use mmtk::util::{ObjectReference, VMWorkerThread};
77
use mmtk::vm::{ObjectTracer, RootsWorkFactory, Scanning, SlotVisitor};
8-
use mmtk::{Mutator, MutatorContext};
8+
use mmtk::Mutator;
99

1010
pub struct VMScanning {}
1111

@@ -67,14 +67,13 @@ impl Scanning<Ruby> for VMScanning {
6767
}
6868

6969
fn scan_roots_in_mutator_thread(
70-
tls: VMWorkerThread,
71-
mutator: &'static mut Mutator<Ruby>,
72-
mut factory: impl RootsWorkFactory<RubySlot>,
70+
_tls: VMWorkerThread,
71+
_mutator: &'static mut Mutator<Ruby>,
72+
mut _factory: impl RootsWorkFactory<RubySlot>,
7373
) {
74-
let gc_tls = unsafe { GCThreadTLS::from_vwt_check(tls) };
75-
Self::collect_object_roots_in("scan_thread_root", gc_tls, &mut factory, || {
76-
(upcalls().scan_roots_in_mutator_thread)(mutator.get_tls(), tls);
77-
});
74+
// Do nothing. All stacks (including Ruby stacks and machine stacks) are reachable from
75+
// `rb_vm_t` -> ractor -> thread -> fiber -> stacks. It is part of `ScanGCRoots` which
76+
// calls `rb_gc_mark_roots` -> `rb_vm_mark`.
7877
}
7978

8079
fn scan_vm_specific_roots(tls: VMWorkerThread, factory: impl RootsWorkFactory<RubySlot>) {

0 commit comments

Comments
 (0)