From b9332ac8e7126066ac4238443d63eaa4c06789f9 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 24 Dec 2022 01:13:40 -0800 Subject: MJIT: Cancel all on disastrous situations (#7019) I noticed this while running test_yjit with --mjit-call-threshold=1, which redefines `Integer#<`. When Ruby is monkey-patched, MJIT itself could be broken. Similarly, Ruby scripts could break MJIT in many different ways. I prepared the same set of hooks as YJIT so that we could possibly override it and disable it on those moments. Every constant under RubyVM::MJIT is private and thus it's an unsupported behavior though. --- mjit.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'mjit.h') diff --git a/mjit.h b/mjit.h index dc46ef2112..260cf4af78 100644 --- a/mjit.h +++ b/mjit.h @@ -103,6 +103,13 @@ extern void mjit_mark(void); extern void mjit_mark_cc_entries(const struct rb_iseq_constant_body *const body); extern void mjit_notify_waitpid(int exit_code); +extern void rb_mjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop); +extern void rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme); +extern void rb_mjit_before_ractor_spawn(void); +extern void rb_mjit_constant_state_changed(ID id); +extern void rb_mjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx); +extern void rb_mjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events); + void mjit_child_after_fork(void); # ifdef MJIT_HEADER @@ -122,6 +129,13 @@ static inline void mjit_mark(void){} static inline VALUE jit_exec(rb_execution_context_t *ec) { return Qundef; /* unreachable */ } static inline void mjit_child_after_fork(void){} +static inline void rb_mjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {} +static inline void rb_mjit_cme_invalidate(rb_callable_method_entry_t *cme) {} +static inline void rb_mjit_before_ractor_spawn(void) {} +static inline void rb_mjit_constant_state_changed(ID id) {} +static inline void rb_mjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx) {} +static inline void rb_mjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events) {} + #define mjit_enabled false static inline VALUE mjit_pause(bool wait_p){ return Qnil; } // unreachable static inline VALUE mjit_resume(void){ return Qnil; } // unreachable -- cgit v1.2.3