summaryrefslogtreecommitdiff
path: root/mjit_worker.c
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-21 13:21:28 (GMT)
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-21 13:21:28 (GMT)
commit1b5aa4f5161972d3598b738312e771c6706a7af6 (patch)
tree0960e925b2bb2d8fda66845e56d8d36da599eb1f /mjit_worker.c
parente01c9c743f467b7ba9b4a4416f04f967f3e9a6ea (diff)
mjit.c: copy inline cache values to MJIT worker
on VM_CHECK_INTS. Letting MJIT worker directly see inline cache which may be being updated could result in inconsistent IC index and serial. mjit_worker.c: request the copy job after dequeue, and receive the result synchronously. tool/ruby_vm/views/_mjit_compile_ivar.erb: use the copied IC mjit_compile.c: change the interface to pass is_entries mjit.h: ditto === Optcarrot Benchmark === Thankfully this didn't have major performance regression. $ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems --jit;after::after --disable-gems --jit' -v --repeat-count 24 before: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux] last_commit=mjit.c: copy inline cache values to MJIT worker Calculating ------------------------------------- before after Optcarrot Lan_Master.nes 85.421 85.454 fps Comparison: Optcarrot Lan_Master.nes after: 85.5 fps before: 85.4 fps - 1.00x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index dbf21cc..0dcd253 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -76,6 +76,7 @@
#include "mjit.h"
#include "gc.h"
#include "ruby_assert.h"
+#include "ruby/debug.h"
#include "ruby/thread.h"
#ifdef _WIN32
@@ -1028,7 +1029,7 @@ compile_prelude(FILE *f)
/* Compile ISeq in UNIT and return function pointer of JIT-ed code.
It may return NOT_COMPILED_JIT_ISEQ_FUNC if something went wrong. */
static mjit_func_t
-convert_unit_to_func(struct rb_mjit_unit *unit)
+convert_unit_to_func(struct rb_mjit_unit *unit, union iseq_inline_storage_entry *is_entries)
{
char c_file_buff[MAXPATHLEN], *c_file = c_file_buff, *so_file, funcname[35]; /* TODO: reconsider `35` */
int success;
@@ -1096,7 +1097,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
verbose(2, "start compilation: %s@%s:%d -> %s", label, path, lineno, c_file);
fprintf(f, "/* %s@%s:%d */\n\n", label, path, lineno);
}
- success = mjit_compile(f, unit->iseq->body, funcname);
+ success = mjit_compile(f, unit->iseq->body, funcname, is_entries);
/* release blocking mjit_gc_start_hook */
CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC");
@@ -1160,6 +1161,14 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
return (mjit_func_t)func;
}
+struct mjit_copy_job {
+ const struct rb_iseq_constant_body *body;
+ union iseq_inline_storage_entry *is_entries;
+ int finish_p;
+};
+
+static void mjit_copy_job_handler(void *data);
+
/* The function implementing a worker. It is executed in a separate
thread by rb_thread_create_mjit_thread. It compiles precompiled header
and then compiles requested ISeqs. */
@@ -1195,7 +1204,27 @@ mjit_worker(void)
CRITICAL_SECTION_FINISH(3, "in worker dequeue");
if (node) {
- mjit_func_t func = convert_unit_to_func(node->unit);
+ mjit_func_t func;
+ struct mjit_copy_job job;
+
+ /* Copy ISeq's inline caches from main thread. */
+ job.is_entries = NULL;
+ job.body = node->unit->iseq->body;
+ if (job.body->is_size > 0) {
+ job.is_entries = malloc(sizeof(union iseq_inline_storage_entry) * job.body->is_size);
+ job.finish_p = FALSE;
+
+ rb_postponed_job_register(0, mjit_copy_job_handler, (void *)&job);
+ CRITICAL_SECTION_START(3, "in MJIT copy job wait");
+ while (!job.finish_p) {
+ rb_native_cond_wait(&mjit_worker_wakeup, &mjit_engine_mutex);
+ verbose(3, "Getting wakeup from client");
+ }
+ CRITICAL_SECTION_FINISH(3, "in MJIT copy job wait");
+ }
+
+ /* JIT compile */
+ func = convert_unit_to_func(node->unit, job.is_entries);
CRITICAL_SECTION_START(3, "in jit func replace");
if (node->unit->iseq) { /* Check whether GCed or not */
@@ -1212,6 +1241,9 @@ mjit_worker(void)
compact_all_jit_code();
}
#endif
+ if (job.is_entries != NULL) {
+ free(job.is_entries);
+ }
}
}