Never make a method call from MJIT worker

by showing line number only when it's Fixnum.

When it's not Fixnum, we need to call a method to know the line number.
This commit is contained in:
Takashi Kokubun 2019-05-29 16:47:57 +09:00
parent ce7b1132c5
commit 7c0639f3f8
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD

View file

@ -944,13 +944,13 @@ load_func_from_so(const char *so_file, const char *funcname, struct rb_mjit_unit
} }
static void static void
print_jit_result(const char *result, const struct rb_mjit_unit *unit, const double duration, int lineno, const char *c_file) print_jit_result(const char *result, const struct rb_mjit_unit *unit, const double duration, long lineno, const char *c_file)
{ {
if (unit->iseq == NULL) { if (unit->iseq == NULL) {
verbose(1, "JIT %s (%.1fms): (GCed) -> %s", result, duration, c_file); verbose(1, "JIT %s (%.1fms): (GCed) -> %s", result, duration, c_file);
} }
else { else {
verbose(1, "JIT %s (%.1fms): %s@%s:%d -> %s", result, verbose(1, "JIT %s (%.1fms): %s@%s:%ld -> %s", result,
duration, RSTRING_PTR(unit->iseq->body->location.label), duration, RSTRING_PTR(unit->iseq->body->location.label),
RSTRING_PTR(rb_iseq_path(unit->iseq)), lineno, c_file); RSTRING_PTR(rb_iseq_path(unit->iseq)), lineno, c_file);
} }
@ -1075,14 +1075,17 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
return (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; return (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC;
} }
// FIX2INT calls method_entry_get(). Thus we should not call it while GC or GC.compact may happen. // FIX2INT may fallback to rb_num2long(), which is a method call and dangerous in MJIT worker. So showing the
int lineno = FIX2INT(unit->iseq->body->location.first_lineno); // line number only when it's Fixnum. Also note that doing this while in_jit is true to avoid GC / GC.compact.
long lineno = 0;
if (FIXNUM_P(unit->iseq->body->location.first_lineno))
lineno = FIX2LONG(unit->iseq->body->location.first_lineno);
{ {
VALUE s = rb_iseq_path(unit->iseq); VALUE s = rb_iseq_path(unit->iseq);
const char *label = RSTRING_PTR(unit->iseq->body->location.label); const char *label = RSTRING_PTR(unit->iseq->body->location.label);
const char *path = RSTRING_PTR(s); const char *path = RSTRING_PTR(s);
verbose(2, "start compilation: %s@%s:%d -> %s", label, path, lineno, c_file); verbose(2, "start compilation: %s@%s:%ld -> %s", label, path, lineno, c_file);
fprintf(f, "/* %s@%s:%d */\n\n", label, path, lineno); fprintf(f, "/* %s@%s:%ld */\n\n", label, path, lineno);
} }
bool success = mjit_compile(f, unit->iseq, funcname); bool success = mjit_compile(f, unit->iseq, funcname);