diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-02-10 16:04:04 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2023-03-05 22:41:35 -0800 |
commit | 1892ec5738b70ef13593417b6ec20858a94cec47 (patch) | |
tree | b8fb57d760ae1e2eae0910947c391b8ffdf29136 | |
parent | 1bdc23f35b31625cf570f6e8bc85b8289d783a71 (diff) | |
download | ruby-1892ec5738b70ef13593417b6ec20858a94cec47.tar.gz |
Lazily invalidate cme for safety
-rw-r--r-- | mjit.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -331,10 +331,11 @@ rb_mjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) mjit_call_p = false; } -void -rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme) +static void +mjit_cme_invalidate(void *data) { if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; + rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)data; WITH_MJIT_DISABLED({ VALUE cme_klass = rb_funcall(rb_mMJITC, rb_intern("rb_callable_method_entry_struct"), 0); VALUE cme_ptr = rb_funcall(cme_klass, rb_intern("new"), 1, SIZET2NUM((size_t)cme)); @@ -343,6 +344,15 @@ rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme) } void +rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme) +{ + if (!mjit_enabled || !mjit_call_p || !rb_mMJITHooks) return; + // Asynchronously hook the Ruby code since running Ruby in the middle of cme invalidation is dangerous. + extern int rb_workqueue_register(unsigned flags, rb_postponed_job_func_t func, void *data); + rb_workqueue_register(0, mjit_cme_invalidate, (void *)cme); +} + +void rb_mjit_before_ractor_spawn(void) { if (!mjit_call_p) return; |