aboutsummaryrefslogtreecommitdiffstats
path: root/mjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-04-30 21:37:55 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2020-04-30 21:38:50 -0700
commite8a78d7df899291aa025e41207436a450235a4d7 (patch)
tree01e3af7befd7dcbd59b7debd4efb039fcb3dd7b3 /mjit.c
parent520ac5da22c30d6db25de6dcbff9607d8a9cd870 (diff)
downloadruby-e8a78d7df899291aa025e41207436a450235a4d7.tar.gz
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.
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c18
1 files changed, 11 insertions, 7 deletions
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);