mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mark an ISeq being JIT-ed
This is to avoid SEGV on a CC reference in a normal compilation https://github.com/ruby/ruby/runs/1586578023
This commit is contained in:
parent
1fdc97f1b7
commit
f26f905b28
2 changed files with 15 additions and 2 deletions
12
mjit.c
12
mjit.c
|
@ -935,8 +935,13 @@ mjit_finish(bool close_handle_p)
|
||||||
verbose(1, "Successful MJIT finish");
|
verbose(1, "Successful MJIT finish");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by rb_vm_mark() to mark active_units so that we do not GC ISeq which
|
// Called by rb_vm_mark().
|
||||||
// may still be referred to by mjit_recompile() or compact_all_jit_code().
|
//
|
||||||
|
// Mark an ISeq being compiled to prevent its CCs from being GC-ed, which
|
||||||
|
// an MJIT worker may concurrently see.
|
||||||
|
//
|
||||||
|
// Also mark active_units so that we do not GC ISeq which may still be
|
||||||
|
// referred to by mjit_recompile() or compact_all_jit_code().
|
||||||
void
|
void
|
||||||
mjit_mark(void)
|
mjit_mark(void)
|
||||||
{
|
{
|
||||||
|
@ -944,6 +949,9 @@ mjit_mark(void)
|
||||||
return;
|
return;
|
||||||
RUBY_MARK_ENTER("mjit");
|
RUBY_MARK_ENTER("mjit");
|
||||||
|
|
||||||
|
if (compiling_iseq != NULL)
|
||||||
|
rb_gc_mark((VALUE)compiling_iseq);
|
||||||
|
|
||||||
// We need to release a lock when calling rb_gc_mark to avoid doubly acquiring
|
// We need to release a lock when calling rb_gc_mark to avoid doubly acquiring
|
||||||
// a lock by by mjit_gc_start_hook inside rb_gc_mark.
|
// a lock by by mjit_gc_start_hook inside rb_gc_mark.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1103,6 +1103,8 @@ compile_prelude(FILE *f)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rb_iseq_t *compiling_iseq = NULL;
|
||||||
|
|
||||||
// Compile ISeq in UNIT and return function pointer of JIT-ed code.
|
// Compile ISeq in UNIT and return function pointer of JIT-ed code.
|
||||||
// It may return NOT_COMPILED_JIT_ISEQ_FUNC if something went wrong.
|
// It may return NOT_COMPILED_JIT_ISEQ_FUNC if something went wrong.
|
||||||
static mjit_func_t
|
static mjit_func_t
|
||||||
|
@ -1136,6 +1138,8 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
}
|
}
|
||||||
// We need to check again here because we could've waited on GC above
|
// We need to check again here because we could've waited on GC above
|
||||||
in_jit = (unit->iseq != NULL);
|
in_jit = (unit->iseq != NULL);
|
||||||
|
if (in_jit)
|
||||||
|
compiling_iseq = unit->iseq;
|
||||||
CRITICAL_SECTION_FINISH(3, "before mjit_compile to wait GC finish");
|
CRITICAL_SECTION_FINISH(3, "before mjit_compile to wait GC finish");
|
||||||
if (!in_jit) {
|
if (!in_jit) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -1160,6 +1164,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
|
|
||||||
// release blocking mjit_gc_start_hook
|
// release blocking mjit_gc_start_hook
|
||||||
CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC");
|
CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC");
|
||||||
|
compiling_iseq = NULL;
|
||||||
in_jit = false;
|
in_jit = false;
|
||||||
verbose(3, "Sending wakeup signal to client in a mjit-worker for GC");
|
verbose(3, "Sending wakeup signal to client in a mjit-worker for GC");
|
||||||
rb_native_cond_signal(&mjit_client_wakeup);
|
rb_native_cond_signal(&mjit_client_wakeup);
|
||||||
|
|
Loading…
Add table
Reference in a new issue