summaryrefslogtreecommitdiff
path: root/mjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-09-06 11:43:46 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2022-09-06 15:42:02 +0900
commitf6925fab853ffc1872038f33d93e4e5c5379b4db (patch)
treea0dc7ae8b69a6b7092c4394344d3d68d2e354f10 /mjit.c
parentf4dbfa0f04448386a662611682adf6b2219089a4 (diff)
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.
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/mjit.c b/mjit.c
index 4895e42d7d..d25fa79d24 100644
--- a/mjit.c
+++ b/mjit.c
@@ -1259,18 +1259,18 @@ check_unit_queue(void)
current_cc_ms = real_ms_time();
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) {
- 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
current_cc_ms = real_ms_time();
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
}
}
@@ -1323,7 +1329,7 @@ check_compaction(void)
// Check the current CC process if any, and start a next C compiler process as needed.
void
-mjit_notify_waitpid(int status)
+mjit_notify_waitpid(int exit_code)
{
// TODO: check current_cc_pid?
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");
// Check the result
- bool success = false;
- if (WIFEXITED(status)) {
- success = (WEXITSTATUS(status) == 0);
- }
- if (!success) {
+ if (exit_code != 0) {
verbose(2, "Failed to generate so");
if (!current_cc_unit->compact_p) {
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();
}
-// For this timeout seconds, --jit-wait will wait for JIT compilation finish.
-#define MJIT_WAIT_TIMEOUT_SECONDS 600
+// For this timeout seconds, mjit_finish will wait for JIT compilation finish.
+#define MJIT_WAIT_TIMEOUT_SECONDS 5
static void
mjit_wait(struct rb_iseq_constant_body *body)