From e0156bd39656e26971e4236747e9cd4f45f8b35f Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 21 Nov 2020 19:24:59 -0800 Subject: Make sure all threads are scanned on unload_units This has been a TODO since 79df14c04b. While adcf0316d1 covered the root_fiber of the initial thread, it didn't cover root_fibers of other threads. Now it's hooked properly in rb_threadptr_root_fiber_setup. With regards to "XXX: Is this mjit_cont `mjit_cont_free`d?", when rb_threadptr_root_fiber_release is called, although I'm not sure when th->root_fiber is truthy, fiber_free seems to call cont_free and mjit_cont_free. So mjit_conts of root_fibers seem to be freed properly. --- cont.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cont.c') diff --git a/cont.c b/cont.c index 6c26885fef..9b2ad58eb5 100644 --- a/cont.c +++ b/cont.c @@ -945,7 +945,8 @@ cont_free(void *ptr) RUBY_FREE_UNLESS_NULL(cont->saved_vm_stack.ptr); - if (mjit_enabled && cont->mjit_cont != NULL) { + if (mjit_enabled) { + VM_ASSERT(cont->mjit_cont != NULL); mjit_cont_free(cont->mjit_cont); } /* free rb_cont_t or rb_fiber_t */ @@ -1155,11 +1156,10 @@ VALUE rb_fiberptr_self(struct rb_fiber_struct *fiber) return fiber->cont.self; } +// This is used for root_fiber because other fibers call cont_init_mjit_cont through cont_new. void rb_fiber_init_mjit_cont(struct rb_fiber_struct *fiber) { - // Currently this function is meant for root_fiber. Others go through cont_new. - // XXX: Is this mjit_cont `mjit_cont_free`d? cont_init_mjit_cont(&fiber->cont); } @@ -1987,6 +1987,9 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th) fiber->blocking = 1; fiber_status_set(fiber, FIBER_RESUMED); /* skip CREATED */ th->ec = &fiber->cont.saved_ec; + // This skips mjit_cont_new for the initial thread because mjit_enabled is always false + // at this point. mjit_init calls rb_fiber_init_mjit_cont again for this root_fiber. + rb_fiber_init_mjit_cont(fiber); } void -- cgit v1.2.3