1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Do not fork the process on --mjit-wait

fork is for parallel compilation, but --mjit-wait cancels it.
It's more useful to not fork it for binding.irb, debugging, etc.
This commit is contained in:
Takashi Kokubun 2022-09-06 11:43:46 +09:00
parent f4dbfa0f04
commit f6925fab85
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD
4 changed files with 26 additions and 24 deletions

42
mjit.c
View file

@ -1259,18 +1259,18 @@ check_unit_queue(void)
current_cc_ms = real_ms_time(); current_cc_ms = real_ms_time();
current_cc_unit = unit; current_cc_unit = unit;
current_cc_pid = start_mjit_compile(unit);
// JIT failure
if (current_cc_pid == -1) {
current_cc_pid = 0;
current_cc_unit->iseq->body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; // TODO: consider unit->compact_p
current_cc_unit = NULL;
return;
}
if (mjit_opts.wait) { if (mjit_opts.wait) {
mjit_wait(unit->iseq->body); int exit_code = mjit_compile_unit(unit);
mjit_notify_waitpid(exit_code);
}
else {
current_cc_pid = start_mjit_compile(unit);
if (current_cc_pid == -1) { // JIT failure
current_cc_pid = 0;
current_cc_unit->iseq->body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; // TODO: consider unit->compact_p
current_cc_unit = NULL;
return;
}
} }
} }
@ -1315,7 +1315,13 @@ check_compaction(void)
// TODO: assert unit is null // TODO: assert unit is null
current_cc_ms = real_ms_time(); current_cc_ms = real_ms_time();
current_cc_unit = unit; current_cc_unit = unit;
current_cc_pid = start_mjit_compact(unit); if (mjit_opts.wait) {
int exit_code = mjit_compact_unit(unit);
mjit_notify_waitpid(exit_code);
}
else {
current_cc_pid = start_mjit_compact(unit);
}
// TODO: check -1 // TODO: check -1
} }
} }
@ -1323,7 +1329,7 @@ check_compaction(void)
// Check the current CC process if any, and start a next C compiler process as needed. // Check the current CC process if any, and start a next C compiler process as needed.
void void
mjit_notify_waitpid(int status) mjit_notify_waitpid(int exit_code)
{ {
// TODO: check current_cc_pid? // TODO: check current_cc_pid?
current_cc_pid = 0; current_cc_pid = 0;
@ -1333,11 +1339,7 @@ mjit_notify_waitpid(int status)
sprint_uniq_filename(c_file, (int)sizeof(c_file), current_cc_unit->id, MJIT_TMP_PREFIX, ".c"); sprint_uniq_filename(c_file, (int)sizeof(c_file), current_cc_unit->id, MJIT_TMP_PREFIX, ".c");
// Check the result // Check the result
bool success = false; if (exit_code != 0) {
if (WIFEXITED(status)) {
success = (WEXITSTATUS(status) == 0);
}
if (!success) {
verbose(2, "Failed to generate so"); verbose(2, "Failed to generate so");
if (!current_cc_unit->compact_p) { if (!current_cc_unit->compact_p) {
current_cc_unit->iseq->body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; current_cc_unit->iseq->body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC;
@ -1438,8 +1440,8 @@ rb_mjit_add_iseq_to_process(const rb_iseq_t *iseq)
check_unit_queue(); check_unit_queue();
} }
// For this timeout seconds, --jit-wait will wait for JIT compilation finish. // For this timeout seconds, mjit_finish will wait for JIT compilation finish.
#define MJIT_WAIT_TIMEOUT_SECONDS 600 #define MJIT_WAIT_TIMEOUT_SECONDS 5
static void static void
mjit_wait(struct rb_iseq_constant_body *body) mjit_wait(struct rb_iseq_constant_body *body)

2
mjit.h
View file

@ -100,7 +100,7 @@ extern void mjit_mark(void);
extern struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec); extern struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec);
extern void mjit_cont_free(struct mjit_cont *cont); extern void mjit_cont_free(struct mjit_cont *cont);
extern void mjit_mark_cc_entries(const struct rb_iseq_constant_body *const body); extern void mjit_mark_cc_entries(const struct rb_iseq_constant_body *const body);
extern void mjit_notify_waitpid(int status); extern void mjit_notify_waitpid(int exit_code);
void mjit_child_after_fork(void); void mjit_child_after_fork(void);

View file

@ -2323,7 +2323,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
// outside ruby_sigchld_handler to avoid recursively relying on the SIGCHLD handler. // outside ruby_sigchld_handler to avoid recursively relying on the SIGCHLD handler.
if (mjit_waitpid_finished) { if (mjit_waitpid_finished) {
mjit_waitpid_finished = false; mjit_waitpid_finished = false;
mjit_notify_waitpid(mjit_waitpid_status); mjit_notify_waitpid(WIFEXITED(mjit_waitpid_status) ? WEXITSTATUS(mjit_waitpid_status) : -1);
} }
#endif #endif
} }

4
vm.c
View file

@ -393,8 +393,8 @@ mjit_check_iseq(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_ise
RB_DEBUG_COUNTER_INC(mjit_exec_not_added); RB_DEBUG_COUNTER_INC(mjit_exec_not_added);
if (body->total_calls == mjit_opts.min_calls) { if (body->total_calls == mjit_opts.min_calls) {
rb_mjit_add_iseq_to_process(iseq); rb_mjit_add_iseq_to_process(iseq);
if (UNLIKELY(mjit_opts.wait)) { if (UNLIKELY(mjit_opts.wait && (uintptr_t)body->jit_func > LAST_JIT_ISEQ_FUNC)) {
return rb_mjit_wait_call(ec, body); return body->jit_func(ec, ec->cfp);
} }
} }
break; break;