@@ -61,54 +61,9 @@ check_cfunc_dispatch(VALUE receiver, struct rb_callinfo *ci, void *callee, rb_ca
6161
6262// GC root for interacting with the GC
6363struct yjit_root_struct {
64- int unused ; // empty structs are not legal in C99
64+ bool unused ; // empty structs are not legal in C99
6565};
6666
67- // Map klass => id_table[mid, set of blocks]
68- // While a block `b` is in the table, b->callee_cme == rb_callable_method_entry(klass, mid).
69- // See assume_method_lookup_stable()
70- static st_table * method_lookup_dependency ;
71-
72- // For adding to method_lookup_dependency data with st_update
73- struct lookup_dependency_insertion {
74- //block_t *block;
75- ID mid ;
76- };
77-
78- // Map cme => set of blocks
79- // See assume_method_lookup_stable()
80- static st_table * cme_validity_dependency ;
81-
82- static int
83- mark_and_pin_keys_i (st_data_t k , st_data_t v , st_data_t ignore )
84- {
85- rb_gc_mark ((VALUE )k );
86-
87- return ST_CONTINUE ;
88- }
89-
90- // GC callback during mark phase
91- static void
92- yjit_root_mark (void * ptr )
93- {
94- if (method_lookup_dependency ) {
95- // TODO: This is a leak. Unused blocks linger in the table forever, preventing the
96- // callee class they speculate on from being collected.
97- // We could do a bespoke weak reference scheme on classes similar to
98- // the interpreter's call cache. See finalizer for T_CLASS and cc_table_free().
99- st_foreach (method_lookup_dependency , mark_and_pin_keys_i , 0 );
100- }
101-
102- if (cme_validity_dependency ) {
103- // Why not let the GC move the cme keys in this table?
104- // Because this is basically a compare_by_identity Hash.
105- // If a key moves, we would need to reinsert it into the table so it is rehashed.
106- // That is tricky to do, espcially as it could trigger allocation which could
107- // trigger GC. Not sure if it is okay to trigger GC while the GC is updating
108- // references.
109- st_foreach (cme_validity_dependency , mark_and_pin_keys_i , 0 );
110- }
111- }
11267
11368static void
11469yjit_root_free (void * ptr )
@@ -120,20 +75,23 @@ static size_t
12075yjit_root_memsize (const void * ptr )
12176{
12277 // Count off-gc-heap allocation size of the dependency table
123- return st_memsize ( method_lookup_dependency ) ; // TODO: more accurate accounting
78+ return 0 ; // TODO: more accurate accounting
12479}
12580
12681// GC callback during compaction
12782static void
12883yjit_root_update_references (void * ptr )
12984{
85+ // Do nothing since we use rb_gc_mark(), which pins.
13086}
13187
88+ void rb_yjit_root_mark (void * ptr ); // in Rust
89+
13290// Custom type for interacting with the GC
13391// TODO: make this write barrier protected
13492static const rb_data_type_t yjit_root_type = {
13593 "yjit_root" ,
136- {yjit_root_mark , yjit_root_free , yjit_root_memsize , yjit_root_update_references },
94+ {rb_yjit_root_mark , yjit_root_free , yjit_root_memsize , yjit_root_update_references },
13795 0 , 0 , RUBY_TYPED_FREE_IMMEDIATELY
13896};
13997
@@ -361,12 +319,10 @@ rb_yjit_init(void)
361319
362320 // Call the Rust initialization code
363321 void rb_yjit_init_rust (void );
364- return rb_yjit_init_rust ();
322+ rb_yjit_init_rust ();
365323
366- /*
367- // Initialize the GC hooks
324+ // Initialize the GC hooks. Do this second as some code depend on Rust initialization.
368325 struct yjit_root_struct * root ;
369326 VALUE yjit_root = TypedData_Make_Struct (0 , struct yjit_root_struct , & yjit_root_type , root );
370327 rb_gc_register_mark_object (yjit_root );
371- */
372328}
0 commit comments