diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2020-11-21 19:24:59 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2020-11-21 19:36:55 -0800 |
commit | e0156bd39656e26971e4236747e9cd4f45f8b35f (patch) | |
tree | eea453a551e34906c5208299d516795cf94318ba /mjit.c | |
parent | eb3906c6b8ea3d88c5c53cb420e18dcda4d7081e (diff) |
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.
Diffstat (limited to 'mjit.c')
-rw-r--r-- | mjit.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -262,7 +262,7 @@ mark_ec_units(rb_execution_context_t *ec) if (cfp->pc && (iseq = cfp->iseq) != NULL && imemo_type((VALUE) iseq) == imemo_iseq && (iseq->body->jit_unit) != NULL) { - iseq->body->jit_unit->used_code_p = TRUE; + iseq->body->jit_unit->used_code_p = true; } if (cfp == ec->cfp) @@ -275,8 +275,6 @@ mark_ec_units(rb_execution_context_t *ec) static void unload_units(void) { - //rb_vm_t *vm = GET_THREAD()->vm; - //rb_thread_t *th = NULL; struct rb_mjit_unit *unit = 0, *next, *worst; struct mjit_cont *cont; int delete_num, units_num = active_units.length; @@ -293,16 +291,14 @@ unload_units(void) // Detect units which are in use and can't be unloaded. list_for_each(&active_units.head, unit, unode) { assert(unit->iseq != NULL && unit->handle != NULL); - unit->used_code_p = FALSE; + unit->used_code_p = false; } - // TODO - //list_for_each(&vm->living_threads, th, lt_node) { - // mark_ec_units(th->ec); - //} + // All threads have a root_fiber which has a mjit_cont. Other normal fibers also + // have a mjit_cont. Thus we can check ISeqs in use by scanning ec of mjit_conts. for (cont = first_cont; cont != NULL; cont = cont->next) { mark_ec_units(cont->ec); } - // TODO: check slale_units and unload unused ones! (note that the unit is not associated to ISeq anymore) + // TODO: check stale_units and unload unused ones! (note that the unit is not associated to ISeq anymore) // Remove 1/10 units more to decrease unloading calls. // TODO: Calculate max total_calls in unit_queue and don't unload units @@ -801,7 +797,11 @@ mjit_init(const struct mjit_options *opts) rb_native_cond_initialize(&mjit_worker_wakeup); rb_native_cond_initialize(&mjit_gc_wakeup); - // Make sure root_fiber's saved_ec is scanned by mark_ec_units + // Make sure the saved_ec of the initial thread's root_fiber is scanned by mark_ec_units. + // + // rb_threadptr_root_fiber_setup for the initial thread is called before mjit_init, + // meaning mjit_cont_new is skipped for the root_fiber. Therefore we need to call + // rb_fiber_init_mjit_cont again with mjit_enabled=true to set the root_fiber's mjit_cont. rb_fiber_init_mjit_cont(GET_EC()->fiber_ptr); // Initialize class_serials cache for compilation |