summaryrefslogtreecommitdiff
path: root/mjit_worker.c
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2021-06-03 20:46:53 +0900
committernagachika <nagachika@ruby-lang.org>2021-06-03 20:46:53 +0900
commit2dd18df4a35a4b2dd0cf2dec7759898246fc6935 (patch)
tree9ec562b07900603960bc76f0ab7c669b9b281dba /mjit_worker.c
parent9680ee97e0b3e87c0fc9a65c01de1ee50a1a178b (diff)
merge revision(s) 86c262541ad07528842d76dab4b9b34bd888d5f4,7e14762159643b4415e094f9d2a90afaf7994588: [Backport #17935]
Fix a race condition around mjit_recompile This fixes SEGVs like https://github.com/ruby/ruby/runs/2715166621?check_suite_focus=true. When mjit_recompile is called when mjit_compile is compiling the exact same iseq (and after it called mjit_capture_cc_entries), iseq->body->jit_unit is re-created and its cc_entries becomes NULL. Then, when it tries to lookup cc_entries through iseq->body->jit_unit, it fails. --- mjit.c | 21 +++++++++++++-------- mjit_worker.c | 4 ++++ 2 files changed, 17 insertions(+), 8 deletions(-) Do not doubly hold an MJIT lock This is a follow-up of 86c262541ad07528842d76dab4b9b34bd888d5f4. CRITICAL_SECTION_START/FINISH are not needed when it's called from an MJIT worker. Also, ZALLOC needs to be calloc because ZALLOC may trigger GC, which an MJIT worker must not do. --- mjit.c | 23 ++++++++++++++--------- mjit_worker.c | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-)
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index ad36ec6151..e2db644c92 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -1402,6 +1402,8 @@ unload_units(void)
}
}
+static void mjit_add_iseq_to_process(const rb_iseq_t *iseq, const struct rb_mjit_compile_info *compile_info, bool worker_p);
+
// The function implementing a worker. It is executed in a separate
// thread by rb_thread_create_mjit_thread. It compiles precompiled header
// and then compiles requested ISeqs.
@@ -1451,6 +1453,8 @@ mjit_worker(void)
unit->stale_p = false;
remove_from_list(unit, &active_units);
add_to_list(unit, &stale_units);
+ // Lazily put it to unit_queue as well to avoid race conditions on jit_unit with mjit_compile.
+ mjit_add_iseq_to_process(unit->iseq, &unit->iseq->body->jit_unit->compile_info, true);
}
}
}