8000 Revert "Eliminate mjit_copy_job_t reference from mjit_worker" · jruby/ruby@78e87b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 78e87b7

Browse files
committed
Revert "Eliminate mjit_copy_job_t reference from mjit_worker"
This reverts commit ba51ae0. CI is failing again... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ba51ae0 commit 78e87b7

File tree

2 files changed

+37
-54
lines changed

2 files changed

+37
-54
lines changed

mjit.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ struct mjit_options {
5454
int max_cache_size;
5555
};
5656

57-
typedef struct {
58-
bool success_p;
59-
struct rb_call_cache *cc_entries;
60-
union iseq_inline_storage_entry *is_entries;
61-
} mjit_copy_job_result_t;
62-
6357
typedef VALUE (*mjit_func_t)(rb_execution_context_t *, rb_control_frame_t *);
6458

6559
RUBY_SYMBOL_EXPORT_BEGIN

mjit_worker.c

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,58 +1144,30 @@ int rb_workqueue_register(unsigned flags, rb_postponed_job_func_t , void *);
11441144
/* We're lazily copying cache values from main thread because these cache values
11451145
could be different between ones on enqueue timing and ones on dequeue timing.
11461146
Return true if copy succeeds. */
1147-
static mjit_copy_job_result_t
1148-
copy_cache_from_main_thread(const rb_iseq_t *iseq)
1147+
static bool
1148+
copy_cache_from_main_thread(mjit_copy_job_t *job)
11491149
{
1150-
mjit_copy_job_t *job = &mjit_copy_job; // just a shorthand
1151-
1152-
CRITICAL_SECTION_START(3, "in copy_cache_from_main_thread");
1153-
job->finish_p = true; // disable dispatching this job in mjit_copy_job_handler while it's being modified
1154-
CRITICAL_SECTION_FINISH(3, "in copy_cache_from_main_thread");
1155-
1156-
const struct rb_iseq_constant_body *body = iseq->body;
1157-
job->iseq = iseq;
1158-
job->cc_entries = NULL;
1159-
if (body->ci_size > 0 || body->ci_kw_size > 0)
1160-
job->cc_entries = alloca(sizeof(struct rb_call_cache) * (body->ci_size + body->ci_kw_size));
1161-
job->is_entries = NULL;
1162-
if (body->is_size > 0)
1163-
job->is_entries = alloca(sizeof(union iseq_inline_storage_entry) * body->is_size);
1164-
1165-
if (job->cc_entries == NULL && job->is_entries == NULL) {
1166-
return (mjit_copy_job_result_t){ .success_p = true, .cc_entries = NULL, .is_entries = NULL };
1167-
}
1168-
11691150
CRITICAL_SECTION_START(3, "in copy_cache_from_main_thread");
11701151
job->finish_p = false; // allow dispatching this job in mjit_copy_job_handler
11711152
CRITICAL_SECTION_FINISH(3, "in copy_cache_from_main_thread");
11721153

11731154
if (UNLIKELY(mjit_opts.wait)) {
11741155
mjit_copy_job_handler((void *)job);
1175-
} else {
1176-
if (!rb_workqueue_register(0, mjit_copy_job_handler, (void *)job)) {
1177-
// Disable dispatching this job in mjit_copy_job_handler while memory allocated by alloca
1178-
// could be expired after finishing this function.
1179-
job->finish_p = true;
1180-
return (mjit_copy_job_result_t){ .success_p = false };
1181-
}
1182-
1183-
CRITICAL_SECTION_START(3, "in MJIT copy job wait");
1184-
/* checking `stop_worker_p` too because `RUBY_VM_CHECK_INTS(ec)` may not
1185-
lush mjit_copy_job_handler when EC_EXEC_TAG() is not TAG_NONE, and then
1186-
`stop_worker()` could dead lock with this function. */
1187-
while (!job->finish_p && !stop_worker_p) {
1188-
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
1189-
verbose(3, "Getting wakeup from client");
1190-
}
1191-
CRITICAL_SECTION_FINISH(3, "in MJIT copy job wait");
1156+
return job->finish_p;
11921157
}
11931158

1194-
bool finish_p = job->finish_p;
1195-
// Disable dispatching this job in mjit_copy_job_handler while memory allocated by alloca
1196-
// could be expired after finishing this function.
1197-
job->finish_p = true;
1198-
return (mjit_copy_job_result_t){ .success_p = finish_p, .cc_entries = job->cc_entries, .is_entries = job->is_entries };
1159+
if (!rb_workqueue_register(0, mjit_copy_job_handler, (void *)job))
1160+
return false;
1161+
CRITICAL_SECTION_START(3, "in MJIT copy job wait");
1162+
/* checking `stop_worker_p` too because `RUBY_VM_CHECK_INTS(ec)` may not
1163+
lush mjit_copy_job_handler when EC_EXEC_TAG() is not TAG_NONE, and then
1164+
`stop_worker()` could dead lock with this function. */
1165+
while (!job->finish_p && !stop_worker_p) {
1166+
rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
1167+
verbose(3, "Getting wakeup from client");
1168+
}
1169+
CRITICAL_SECTION_FINISH(3, "in MJIT copy job wait");
1170+
return job->finish_p;
11991171
}
12001172

12011173
/* The function implementing a worker. It is executed in a separate
@@ -1204,6 +1176,8 @@ copy_cache_from_main_thread(const rb_iseq_t *iseq)
12041176
void
12051177
mjit_worker(void)
12061178
{
1179+
mjit_copy_job_t *job = &mjit_copy_job; /* just a shorthand */
1180+
12071181
#ifndef _MSC_VER
12081182
if (pch_status == PCH_NOT_READY) {
12091183
make_pch();
@@ -1230,17 +1204,28 @@ mjit_worker(void)
12301204
verbose(3, "Getting wakeup from client");
12311205
}
12321206
unit = get_from_list(&unit_queue);
1207+
if (unit) job->iseq = unit->iseq;
1208+
job->finish_p = true; // disable dispatching this job in mjit_copy_job_handler while it's being modified
12331209
CRITICAL_SECTION_FINISH(3, "in worker dequeue");
12341210

12351211
if (unit) {
1236-
// Copy mutable values from main threads
1237-
mjit_copy_job_result_t result = copy_cache_from_main_thread(unit->iseq);
1238-
if (result.success_p == false) {
1239-
continue; // retry postponed_job failure, or stop worker
1212+
const struct rb_iseq_constant_body *body = unit->iseq->body;
1213+
job->cc_entries = NULL;
1214+
if (body->ci_size > 0 || body->ci_kw_size > 0)
1215+
job->cc_entries = alloca(sizeof(struct rb_call_cache) * (body->ci_size + body->ci_kw_size));
1216+
job->is_entries = NULL;
1217+
if (body->is_size > 0)
1218+
job->is_entries = alloca(sizeof(union iseq_inline_storage_entry) * body->is_size);
1219+
1220+
/* Copy ISeq's inline caches values to avoid race condition. */
1221+
if (job->cc_entries != NULL || job->is_entries != NULL) {
1222+
if (copy_cache_from_main_thread(job) == false) {
1223+
continue; /* retry postponed_job failure, or stop worker */
1224+
}
12401225< 957B div class="diff-text-inner"> }
12411226

12421227
// JIT compile
1243-
mjit_func_t func = convert_unit_to_func(unit, result.cc_entries, result.is_entries);
1228+
mjit_func_t func = convert_unit_to_func(unit, job->cc_entries, job->is_entries);
12441229

12451230
CRITICAL_SECTION_START(3, "in jit func replace");
12461231
while (in_gc) { /* Make sure we're not GC-ing when touching ISeq */
@@ -1263,6 +1248,10 @@ mjit_worker(void)
12631248
}
12641249
}
12651250

1251+
// Disable dispatching this job in mjit_copy_job_handler while memory allocated by alloca
1252+
// could be expired after finishing this function.
1253+
job->finish_p = true;
1254+
12661255
// To keep mutex unlocked when it is destroyed by mjit_finish, don't wrap CRITICAL_SECTION here.
12671256
worker_stopped = true;
12681257
}

0 commit comments

Comments
 (0)
0