@@ -566,7 +566,7 @@ rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val)
566566
567567static const char * obj_type_name (VALUE obj );
568568#define RB_AMALGAMATED_DEFAULT_GC
569- #include "gc/default.c"
569+ #include "gc/default/default .c"
570570static int external_gc_loaded = FALSE;
571571
572572
@@ -580,7 +580,7 @@ typedef struct gc_function_map {
580580 void * (* objspace_alloc )(void );
581581 void (* objspace_init )(void * objspace_ptr );
582582 void (* objspace_free )(void * objspace_ptr );
583- void * (* ractor_cache_alloc )(void * objspace_ptr );
583+ void * (* ractor_cache_alloc )(void * objspace_ptr , void * ractor );
584584 void (* ractor_cache_free )(void * objspace_ptr , void * cache );
585585 void (* set_params )(void * objspace_ptr );
586586 void (* init )(void );
@@ -635,6 +635,9 @@ typedef struct gc_function_map {
635635 // Object ID
636636 VALUE (* object_id )(void * objspace_ptr , VALUE obj );
637637 VALUE (* object_id_to_ref )(void * objspace_ptr , VALUE object_id );
638+ // Forking
639+ void (* before_fork )(void * objspace_ptr );
640+ void (* after_fork )(void * objspace_ptr , rb_pid_t pid );
638641 // Statistics
639642 void (* set_measure_total_time )(void * objspace_ptr , VALUE flag );
640643 bool (* get_measure_total_time )(void * objspace_ptr );
@@ -683,7 +686,7 @@ ruby_external_gc_init(void)
683686 }
684687 }
685688
686- size_t gc_so_path_size = strlen (SHARED_GC_DIR "librubygc." SOEXT ) + strlen (gc_so_file ) + 1 ;
689+ size_t gc_so_path_size = strlen (SHARED_GC_DIR "librubygc." DLEXT ) + strlen (gc_so_file ) + 1 ;
687690 gc_so_path = alloca (gc_so_path_size );
688691 {
689692 size_t gc_so_path_idx = 0 ;
@@ -693,7 +696,7 @@ ruby_external_gc_init(void)
693696 GC_SO_PATH_APPEND (SHARED_GC_DIR );
694697 GC_SO_PATH_APPEND ("librubygc." );
695698 GC_SO_PATH_APPEND (gc_so_file );
696- GC_SO_PATH_APPEND (SOEXT );
699+ GC_SO_PATH_APPEND (DLEXT );
697700 GC_ASSERT (gc_so_path_idx == gc_so_path_size - 1 );
698701#undef GC_SO_PATH_APPEND
699702 }
@@ -781,6 +784,9 @@ ruby_external_gc_init(void)
781784 // Object ID
782785 load_external_gc_func (object_id );
783786 load_external_gc_func (object_id_to_ref );
787+ // Forking
788+ load_external_gc_func (before_fork );
789+ load_external_gc_func (after_fork );
784790 // Statistics
785791 load_external_gc_func (set_measure_total_time );
786792 load_external_gc_func (get_measure_total_time );
@@ -862,6 +868,9 @@ ruby_external_gc_init(void)
862868// Object ID
863869# define rb_gc_impl_object_id rb_gc_functions.object_id
864870# define rb_gc_impl_object_id_to_ref rb_gc_functions.object_id_to_ref
871+ // Forking
872+ # define rb_gc_impl_before_fork rb_gc_functions.before_fork
873+ # define rb_gc_impl_after_fork rb_gc_functions.after_fork
865874// Statistics
866875# define rb_gc_impl_set_measure_total_time rb_gc_functions.set_measure_total_time
867876# define rb_gc_impl_get_measure_total_time rb_gc_functions.get_measure_total_time
@@ -915,7 +924,7 @@ newobj_of(rb_ractor_t *cr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v
915924{
916925 VALUE obj = rb_gc_impl_new_obj (rb_gc_get_objspace (), cr -> newobj_cache , klass , flags , v1 , v2 , v3 , wb_protected , size );
917926
918- if (UNLIKELY (ruby_vm_event_flags & RUBY_INTERNAL_EVENT_NEWOBJ )) {
927+ if (UNLIKELY (rb_gc_event_hook_required_p ( RUBY_INTERNAL_EVENT_NEWOBJ ) )) {
919928 unsigned int lev ;
920929 RB_VM_LOCK_ENTER_CR_LEV (cr , & lev );
921930 {
@@ -1104,6 +1113,44 @@ rb_data_free(void *objspace, VALUE obj)
11041113 return true;
11051114}
11061115
1116+ void
1117+ rb_gc_obj_free_vm_weak_references (VALUE obj )
1118+ {
1119+ if (FL_TEST (obj , FL_EXIVAR )) {
1120+ rb_free_generic_ivar ((VALUE )obj );
1121+ FL_UNSET (obj , FL_EXIVAR );
1122+ }
1123+
1124+ switch (BUILTIN_TYPE (obj )) {
1125+ case T_STRING :
1126+ if (FL_TEST (obj , RSTRING_FSTR )) {
1127+ st_data_t fstr = (st_data_t )obj ;
1128+ st_delete (rb_vm_fstring_table (), & fstr , NULL );
1129+ RB_DEBUG_COUNTER_INC (obj_str_fstr );
1130+
1131+ FL_UNSET (obj , RSTRING_FSTR );
1132+ }
1133+ break ;
1134+ case T_SYMBOL :
1135+ rb_gc_free_dsymbol (obj );
1136+ break ;
1137+ case T_IMEMO :
1138+ switch (imemo_type (obj )) {
1139+ case imemo_callinfo :
1140+ rb_vm_ci_free ((const struct rb_callinfo * )obj );
1141+ break ;
1142+ case imemo_ment :
1143+ rb_free_method_entry_vm_weak_references ((const rb_method_entry_t * )obj );
1144+ break ;
1145+ default :
1146+ break ;
1147+ }
1148+ break ;
1149+ default :
1150+ break ;
1151+ }
1152+ }
1153+
11071154bool
11081155rb_gc_obj_free (void * objspace , VALUE obj )
11091156{
0 commit comments