diff --git a/iseq.c b/iseq.c index 82f045d62a..0ead40fec2 100644 --- a/iseq.c +++ b/iseq.c @@ -262,6 +262,9 @@ rb_iseq_update_references(rb_iseq_t *iseq) } } } +#if USE_MJIT + mjit_update_references(iseq); +#endif } } diff --git a/mjit.c b/mjit.c index bd5dd46b19..3eb2ee8a50 100644 --- a/mjit.c +++ b/mjit.c @@ -110,6 +110,19 @@ mjit_gc_finish_hook(void) CRITICAL_SECTION_FINISH(4, "mjit_gc_finish_hook"); } +// Deal with ISeq movement from compactor +void +mjit_update_references(const rb_iseq_t *iseq) +{ + if (!mjit_enabled) + return; + CRITICAL_SECTION_START(4, "mjit_free_iseq"); + if (iseq->body->jit_unit) { + iseq->body->jit_unit->iseq = (rb_iseq_t *)rb_gc_new_location(iseq->body->jit_unit->iseq); + } + CRITICAL_SECTION_FINISH(4, "mjit_free_iseq"); +} + // Iseqs can be garbage collected. This function should call when it // happens. It removes iseq from the unit. void diff --git a/mjit.h b/mjit.h index 4aadc8eb6f..e71df7f07c 100644 --- a/mjit.h +++ b/mjit.h @@ -84,6 +84,7 @@ extern void mjit_postponed_job_register_finish_hook(void); extern void mjit_gc_start_hook(void); extern void mjit_gc_finish_hook(void); extern void mjit_free_iseq(const rb_iseq_t *iseq); +extern void mjit_update_references(const rb_iseq_t *iseq); extern void mjit_mark(void); extern struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec); extern void mjit_cont_free(struct mjit_cont *cont);