@@ -7315,6 +7315,11 @@ rb_gc_remove_weak(VALUE parent_obj, VALUE *ptr)
7315
7315
static inline void
7316
7316
gc_mark_set_parent (rb_objspace_t * objspace , VALUE obj )
7317
7317
{
7318
+ WHEN_USING_MMTK ({
7319
+ // MMTk scans object concurrently. This function only adds one more source of data race.
7320
+ return ;
7321
+ })
7322
+
7318
7323
if (RVALUE_OLD_P (obj )) {
7319
7324
objspace -> rgengc .parent_object = obj ;
7320
7325
}
@@ -7664,21 +7669,14 @@ show_mark_ticks(void)
7664
7669
static void
7665
7670
gc_mark_roots (rb_objspace_t * objspace , const char * * categoryp )
7666
7671
{
7667
- rb_execution_context_t * ec ;
7668
- rb_vm_t * vm ;
7672
+ WHEN_USING_MMTK ({
7673
+ // When using MMTk, we parallelize root scanning by splitting this function into multiple
7674
+ // functions, and call each one in a separate work packet.
7675
+ rb_bug ("gc_mark_roots should not be called when using MMTk." );
7676
+ })
7669
7677
7670
- #if USE_MMTK
7671
- const bool mmtk_enabled_local = rb_mmtk_enabled_p (); // Allows control-flow sensitive analysis of ec etc
7672
- if (mmtk_enabled_local ) {
7673
- rb_mmtk_assert_mmtk_worker ();
7674
- vm = GET_VM ();
7675
- } else {
7676
- #endif
7677
- ec = GET_EC ();
7678
- vm = rb_ec_vm_ptr (ec );
7679
- #if USE_MMTK
7680
- }
7681
- #endif
7678
+ rb_execution_context_t * ec = GET_EC ();
7679
+ rb_vm_t * vm = rb_ec_vm_ptr (ec );
7682
7680
7683
7681
#if PRINT_ROOT_TICKS
7684
7682
tick_t start_tick = tick ();
@@ -7715,32 +7713,15 @@ gc_mark_roots(rb_objspace_t *objspace, const char **categoryp)
7715
7713
} while (0)
7716
7714
7717
7715
MARK_CHECKPOINT ("vm" );
7718
-
7719
- #if USE_MMTK
7720
- // Note that when using MMTk, this function is executed by a GC worker thread, not a mutator.
7721
- // Therefore we don't set stack end or scan the current stack.
7722
- if (!mmtk_enabled_local ) {
7723
- #endif
7724
7716
SET_STACK_END ;
7725
- #if USE_MMTK
7726
- }
7727
- #endif
7728
-
7729
7717
rb_vm_mark (vm );
7730
7718
if (vm -> self ) gc_mark (objspace , vm -> self );
7731
7719
7732
7720
MARK_CHECKPOINT ("finalizers" );
7733
7721
mark_finalizer_tbl (objspace , finalizer_table );
7734
7722
7735
- #if USE_MMTK
7736
- if (!mmtk_enabled_local ) {
7737
- #endif
7738
- // When using MMTk, the current thread is a GC worker. Mutators are scanned separately.
7739
7723
MARK_CHECKPOINT ("machine_context" );
7740
7724
mark_current_machine_context (objspace , ec );
7741
- #if USE_MMTK
7742
- }
7743
- #endif
7744
7725
7745
7726
/* mark protected global variables */
7746
7727
@@ -7759,6 +7740,57 @@ gc_mark_roots(rb_objspace_t *objspace, const char **categoryp)
7759
7740
#undef MARK_CHECKPOINT
7760
7741
}
7761
7742
7743
+ #if USE_MMTK
7744
+ void
7745
+ rb_mmtk_scan_vm_roots (void )
7746
+ {
7747
+ rb_vm_t * vm = GET_VM ();
7748
+ rb_objspace_t * objspace = vm -> objspace ;
7749
+
7750
+ rb_vm_mark (vm );
7751
+ if (vm -> self ) gc_mark (objspace , vm -> self );
7752
+ }
7753
+
7754
+ void
7755
+ rb_mmtk_scan_finalizer_tbl_roots (void )
7756
+ {
7757
+ rb_vm_t * vm = GET_VM ();
7758
+ rb_objspace_t * objspace = vm -> objspace ;
7759
+
7760
+ mark_finalizer_tbl (objspace , finalizer_table );
7761
+ }
7762
+
7763
+ void
7764
+ rb_mmtk_scan_end_proc_roots (void )
7765
+ {
7766
+ rb_mark_end_proc ();
7767
+ }
7768
+
7769
+ void
7770
+ rb_mmtk_scan_global_tbl_roots (void )
7771
+ {
7772
+ rb_gc_mark_global_tbl ();
7773
+ }
7774
+
7775
+ void
7776
+ rb_mmtk_scan_obj_to_id_tbl_roots (void )
7777
+ {
7778
+ rb_vm_t * vm = GET_VM ();
7779
+ rb_objspace_t * objspace = vm -> objspace ;
7780
+
7781
+ mark_tbl_no_pin (objspace , objspace -> obj_to_id_tbl ); /* Only mark ids */
7782
+ }
7783
+
7784
+ void
7785
+ rb_mmtk_scan_misc_roots (void )
7786
+ {
7787
+ rb_vm_t * vm = GET_VM ();
7788
+ rb_objspace_t * objspace = vm -> objspace ;
7789
+
7790
+ if (stress_to_class ) rb_gc_mark (stress_to_class );
7791
+ }
7792
+ #endif
7793
+
7762
7794
#if RGENGC_CHECK_MODE >= 4
7763
7795
7764
7796
#define MAKE_ROOTSIG (obj ) (((VALUE)(obj) << 1) | 0x01)
@@ -14778,11 +14810,8 @@ rb_mmtk_update_ci_table(void)
14778
14810
14779
14811
// Workaround private functions
14780
14812
void
14781
- rb_mmtk_mark_roots (void )
14813
+ rb_mmtk_scan_final_jobs_roots (void )
14782
14814
{
14783
- rb_vm_t * vm = GET_VM ();
14784
- const char * phase ;
14785
- gc_mark_roots (vm -> objspace , & phase );
14786
14815
rb_mmtk_mark_final_jobs ();
14787
14816
}
14788
14817
0 commit comments