diff --git a/vm.c b/vm.c index 49f1353144..730e88d06d 100644 --- a/vm.c +++ b/vm.c @@ -3161,6 +3161,12 @@ ruby_vm_destruct(rb_vm_t *vm) /* after freeing objspace, you *can't* use ruby_xfree() */ ruby_mimfree(vm); ruby_current_vm_ptr = NULL; + +#if USE_YJIT + if (rb_free_at_exit) { + rb_yjit_free_at_exit(); + } +#endif } RUBY_FREE_LEAVE("vm"); return 0; diff --git a/yjit.h b/yjit.h index 5d1de2df90..9360e7fe3c 100644 --- a/yjit.h +++ b/yjit.h @@ -37,6 +37,7 @@ void rb_yjit_collect_binding_alloc(void); void rb_yjit_collect_binding_set(void); void rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception); void rb_yjit_init(bool yjit_enabled); +void rb_yjit_free_at_exit(); void rb_yjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop); void rb_yjit_constant_state_changed(ID id); void rb_yjit_iseq_mark(void *payload); diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 58b18ca0aa..bff7960990 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -10521,6 +10521,10 @@ fn reg_method_codegen(klass: VALUE, mid_str: &str, gen_fn: MethodGenFn) { unsafe { METHOD_CODEGEN_TABLE.as_mut().unwrap().insert(method_serial, gen_fn); } } +pub fn yjit_shutdown_free_codegen_table() { + unsafe { METHOD_CODEGEN_TABLE = None; }; +} + /// Global state needed for code generation pub struct CodegenGlobals { /// Flat vector of bits to store compressed context data diff --git a/yjit/src/yjit.rs b/yjit/src/yjit.rs index a0954dad01..c5864dd2a5 100644 --- a/yjit/src/yjit.rs +++ b/yjit/src/yjit.rs @@ -78,6 +78,11 @@ fn yjit_init() { } } +#[no_mangle] +pub extern "C" fn rb_yjit_free_at_exit() { + yjit_shutdown_free_codegen_table(); +} + /// At the moment, we abort in all cases we panic. /// To aid with getting diagnostics in the wild without requiring /// people to set RUST_BACKTRACE=1, register a panic hook that crash using rb_bug().