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. --- vm_method.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'vm_method.c') diff --git a/vm_method.c b/vm_method.c index 07001e3835..30241cc9cd 100644 --- a/vm_method.c +++ b/vm_method.c @@ -4,6 +4,7 @@ #include "id_table.h" #include "yjit.h" +#include "mjit.h" #define METHOD_DEBUG 0 @@ -124,6 +125,7 @@ vm_cme_invalidate(rb_callable_method_entry_t *cme) RB_DEBUG_COUNTER_INC(cc_cme_invalidate); rb_yjit_cme_invalidate(cme); + rb_mjit_cme_invalidate(cme); } static int @@ -149,6 +151,7 @@ rb_clear_constant_cache_for_id(ID id) } rb_yjit_constant_state_changed(id); + rb_mjit_constant_state_changed(id); } static void @@ -188,6 +191,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, &ccs_data)) { struct rb_class_cc_entries *ccs = (struct rb_class_cc_entries *)ccs_data; rb_yjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme); + rb_mjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme); if (NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid); rb_vm_ccs_free(ccs); rb_id_table_delete(cc_tbl, mid); @@ -200,6 +204,7 @@ clear_method_cache_by_id_in_class(VALUE klass, ID mid) VALUE cme; if (rb_yjit_enabled_p() && rb_id_table_lookup(cm_tbl, mid, &cme)) { rb_yjit_cme_invalidate((rb_callable_method_entry_t *)cme); + rb_mjit_cme_invalidate((rb_callable_method_entry_t *)cme); } rb_id_table_delete(cm_tbl, mid); RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable); -- cgit v1.2.1