@@ -497,6 +497,8 @@ enum gc_mode {
497
497
gc_mode_sweeping
498
498
};
499
499
500
+ typedef void (* gc_writebarrier )(VALUE a , VALUE b , struct rb_objspace * objspace );
501
+
500
502
typedef struct rb_objspace {
501
503
struct {
502
504
size_t limit ;
@@ -637,6 +639,8 @@ typedef struct rb_objspace {
637
639
#if GC_DEBUG_STRESS_TO_CLASS
638
640
VALUE stress_to_class ;
639
641
#endif
642
+
643
+ gc_writebarrier wb ;
640
644
} rb_objspace_t ;
641
645
642
646
@@ -813,6 +817,8 @@ int ruby_gc_debug_indent = 0;
813
817
VALUE rb_mGC ;
814
818
int ruby_disable_gc = 0 ;
815
819
820
+ static void
821
+ gc_set_incremental_marking (rb_objspace_t * objspace , int incremental );
816
822
void rb_iseq_mark (const rb_iseq_t * iseq );
817
823
void rb_iseq_free (const rb_iseq_t * iseq );
818
824
@@ -1309,6 +1315,7 @@ rb_objspace_alloc(void)
1309
1315
#else
1310
1316
rb_objspace_t * objspace = & rb_objspace ;
1311
1317
#endif
1318
+ gc_set_incremental_marking (objspace , is_incremental_marking (objspace ));
1312
1319
malloc_limit = gc_params .malloc_limit_min ;
1313
1320
1314
1321
return objspace ;
@@ -5404,7 +5411,7 @@ gc_marks_finish(rb_objspace_t *objspace)
5404
5411
}
5405
5412
#endif
5406
5413
5407
- objspace -> flags . during_incremental_marking = FALSE;
5414
+ gc_set_incremental_marking ( objspace , FALSE) ;
5408
5415
/* check children of all marked wb-unprotected objects */
5409
5416
gc_marks_wb_unprotected_objects (objspace );
5410
5417
}
@@ -5883,6 +5890,30 @@ gc_writebarrier_incremental(VALUE a, VALUE b, rb_objspace_t *objspace)
5883
5890
}
5884
5891
}
5885
5892
}
5893
+
5894
+ static void
5895
+ gc_non_incremental_wb (VALUE a , VALUE b , rb_objspace_t * objspace )
5896
+ {
5897
+ if (!RVALUE_OLD_P (a ) || RVALUE_OLD_P (b )) {
5898
+ return ;
5899
+ }
5900
+ else {
5901
+ gc_writebarrier_generational (a , b , objspace );
5902
+ }
5903
+ }
5904
+
5905
+ static void
5906
+ gc_set_incremental_marking (rb_objspace_t * objspace , int incremental )
5907
+ {
5908
+ if (incremental ) {
5909
+ objspace -> wb = gc_writebarrier_incremental ;
5910
+ } else {
5911
+ objspace -> wb = gc_non_incremental_wb ;
5912
+ }
5913
+
5914
+ objspace -> flags .during_incremental_marking = incremental ;
5915
+ }
5916
+
5886
5917
#else
5887
5918
#define gc_writebarrier_incremental (a , b , objspace )
5888
5919
#endif
@@ -5895,17 +5926,7 @@ rb_gc_writebarrier(VALUE a, VALUE b)
5895
5926
if (RGENGC_CHECK_MODE && SPECIAL_CONST_P (a )) rb_bug ("rb_gc_writebarrier: a is special const" );
5896
5927
if (RGENGC_CHECK_MODE && SPECIAL_CONST_P (b )) rb_bug ("rb_gc_writebarrier: b is special const" );
5897
5928
5898
- if (!is_incremental_marking (objspace )) {
5899
- if (!RVALUE_OLD_P (a ) || RVALUE_OLD_P (b )) {
5900
- return ;
5901
- }
5902
- else {
5903
- gc_writebarrier_generational (a , b , objspace );
5904
- }
5905
- }
5906
- else { /* slow path */
5907
- gc_writebarrier_incremental (a , b , objspace );
5908
- }
5929
+ (* objspace -> wb )(a , b , objspace );
5909
5930
}
5910
5931
5911
5932
void
@@ -6356,10 +6377,10 @@ gc_start(rb_objspace_t *objspace, const int full_mark, const int immediate_mark,
6356
6377
6357
6378
#if GC_ENABLE_INCREMENTAL_MARK
6358
6379
if (!GC_ENABLE_INCREMENTAL_MARK || objspace -> flags .dont_incremental || immediate_mark ) {
6359
- objspace -> flags . during_incremental_marking = FALSE;
6380
+ gc_set_incremental_marking ( objspace , FALSE) ;
6360
6381
}
6361
6382
else {
6362
- objspace -> flags . during_incremental_marking = do_full_mark ;
6383
+ gc_set_incremental_marking ( objspace , do_full_mark ) ;
6363
6384
}
6364
6385
#endif
6365
6386
0 commit comments