From e8a78d7df899291aa025e41207436a450235a4d7 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 30 Apr 2020 21:37:55 -0700 Subject: Do not stop the world during JIT compaction Running C compiler for JIT compaction inside a critical section may lock main thread for a long time when it triggers GC. As I'm planning to increase this duration a bit, I'd like to make sure this doesn't stop the world. For now, I chose to give up unloading units when it's during JIT compaction, assuming other calls may unload them later. --- mjit.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'mjit.c') diff --git a/mjit.c b/mjit.c index c394cd5ddb..59e58f3f70 100644 --- a/mjit.c +++ b/mjit.c @@ -362,11 +362,7 @@ unload_units(void) free_unit(worst); } - if (units_num == active_units.length && mjit_opts.wait) { - mjit_opts.max_cache_size++; // avoid infinite loop on `rb_mjit_wait_call`. Note that --jit-wait is just for testing. - verbose(1, "No units can be unloaded -- incremented max-cache-size to %d for --jit-wait", mjit_opts.max_cache_size); - } - else { + if (units_num > active_units.length) { verbose(1, "Too many JIT code -- %d units unloaded", units_num - active_units.length); } } @@ -389,8 +385,16 @@ mjit_add_iseq_to_process(const rb_iseq_t *iseq, const struct rb_mjit_compile_inf CRITICAL_SECTION_START(3, "in add_iseq_to_process"); add_to_list(iseq->body->jit_unit, &unit_queue); if (active_units.length >= mjit_opts.max_cache_size) { - RB_DEBUG_COUNTER_INC(mjit_unload_units); - unload_units(); + if (in_compact) { + verbose(1, "Too many JIT code, but skipped unloading units for JIT compaction"); + } else { + RB_DEBUG_COUNTER_INC(mjit_unload_units); + unload_units(); + } + if (active_units.length == mjit_opts.max_cache_size && mjit_opts.wait) { // Sometimes all methods may be in use + mjit_opts.max_cache_size++; // avoid infinite loop on `rb_mjit_wait_call`. Note that --jit-wait is just for testing. + verbose(1, "No units can be unloaded -- incremented max-cache-size to %d for --jit-wait", mjit_opts.max_cache_size); + } } verbose(3, "Sending wakeup signal to workers in mjit_add_iseq_to_process"); rb_native_cond_broadcast(&mjit_worker_wakeup); -- cgit v1.2.3