[前][次][番号順一覧][スレッド一覧]

ruby-changes:55081

From: k0kubun <ko1@a...>
Date: Mon, 18 Mar 2019 03:29:36 +0900 (JST)
Subject: [ruby-changes:55081] k0kubun:r67288 (trunk): Request inline cache values from mjit_compile

k0kubun	2019-03-18 03:29:30 +0900 (Mon, 18 Mar 2019)

  New Revision: 67288

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67288

  Log:
    Request inline cache values from mjit_compile
    
    rather than preparing beforehand.
    
    By having this change, implementing inlining by calling
    `mjit_copy_cache_from_main_thread` for inlined methods was made
    possible.

  Modified files:
    trunk/mjit.h
    trunk/mjit_compile.c
    trunk/mjit_worker.c
Index: mjit.h
===================================================================
--- mjit.h	(revision 67287)
+++ mjit.h	(revision 67288)
@@ -64,7 +64,7 @@ extern void mjit_add_iseq_to_process(con https://github.com/ruby/ruby/blob/trunk/mjit.h#L64
 extern VALUE mjit_wait_call(rb_execution_context_t *ec, struct rb_iseq_constant_body *body);
 RUBY_SYMBOL_EXPORT_END
 
-extern bool mjit_compile(FILE *f, const struct rb_iseq_constant_body *body, const char *funcname, struct rb_call_cache *cc_entries, union iseq_inline_storage_entry *is_entries);
+extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname);
 extern void mjit_init(struct mjit_options *opts);
 extern void mjit_postponed_job_register_start_hook(void);
 extern void mjit_postponed_job_register_finish_hook(void);
Index: mjit_worker.c
===================================================================
--- mjit_worker.c	(revision 67287)
+++ mjit_worker.c	(revision 67288)
@@ -986,7 +986,7 @@ compile_prelude(FILE *f) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L986
 /* 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, struct rb_call_cache *cc_entries, union iseq_inline_storage_entry *is_entries)
+convert_unit_to_func(struct rb_mjit_unit *unit)
 {
     char c_file_buff[MAXPATHLEN], *c_file = c_file_buff, *so_file, funcname[35]; /* TODO: reconsider `35` */
     int fd;
@@ -1067,7 +1067,7 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1067
         verbose(2, "start compilation: %s@%s:%d -> %s", label, path, lineno, c_file);
         fprintf(f, "/* %s@%s:%d */\n\n", label, path, lineno);
     }
-    bool success = mjit_compile(f, unit->iseq->body, funcname, cc_entries, is_entries);
+    bool success = mjit_compile(f, unit->iseq, funcname);
 
     /* release blocking mjit_gc_start_hook */
     CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC");
@@ -1146,14 +1146,14 @@ int rb_workqueue_register(unsigned flags https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1146
 //
 // We're lazily copying cache values from main thread because these cache values
 // could be different between ones on enqueue timing and ones on dequeue timing.
-static bool
-copy_cache_from_main_thread(const rb_iseq_t *iseq, struct rb_call_cache **cc_entries, union iseq_inline_storage_entry **is_entries)
+bool
+mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, struct rb_call_cache **cc_entries, union iseq_inline_storage_entry **is_entries)
 {
     mjit_copy_job_t *job = &mjit_copy_job; // just a short hand
 
-    CRITICAL_SECTION_START(3, "in copy_cache_from_main_thread");
+    CRITICAL_SECTION_START(3, "in mjit_copy_cache_from_main_thread");
     job->finish_p = true; // disable dispatching this job in mjit_copy_job_handler while it's being modified
-    CRITICAL_SECTION_FINISH(3, "in copy_cache_from_main_thread");
+    CRITICAL_SECTION_FINISH(3, "in mjit_copy_cache_from_main_thread");
 
     const struct rb_iseq_constant_body *body = iseq->body;
     job->cc_entries = NULL;
@@ -1170,10 +1170,10 @@ copy_cache_from_main_thread(const rb_ise https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1170
         return true;
     }
 
-    CRITICAL_SECTION_START(3, "in copy_cache_from_main_thread");
+    CRITICAL_SECTION_START(3, "in mjit_copy_cache_from_main_thread");
     job->iseq = iseq; // Prevernt GC of this ISeq from here
     job->finish_p = false; // allow dispatching this job in mjit_copy_job_handler
-    CRITICAL_SECTION_FINISH(3, "in copy_cache_from_main_thread");
+    CRITICAL_SECTION_FINISH(3, "in mjit_copy_cache_from_main_thread");
 
     if (UNLIKELY(mjit_opts.wait)) {
         mjit_copy_job_handler((void *)job);
@@ -1194,12 +1194,12 @@ copy_cache_from_main_thread(const rb_ise https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1194
     *is_entries = job->is_entries;
 
     bool result = job->finish_p;
-    CRITICAL_SECTION_START(3, "in copy_cache_from_main_thread");
-    job->iseq = NULL; // Skip `mjit_mark`-ing this ISeq to allow GC
+    CRITICAL_SECTION_START(3, "in mjit_copy_cache_from_main_thread");
+    job->iseq = NULL; // Allow GC of this ISeq from here
     // Disable dispatching this job in mjit_copy_job_handler while memory allocated by alloca
     // could be expired after finishing this function.
     job->finish_p = true;
-    CRITICAL_SECTION_FINISH(3, "in copy_cache_from_main_thread");
+    CRITICAL_SECTION_FINISH(3, "in mjit_copy_cache_from_main_thread");
     return result;
 }
 
@@ -1238,16 +1238,13 @@ mjit_worker(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1238
         CRITICAL_SECTION_FINISH(3, "in worker dequeue");
 
         if (unit) {
-            struct rb_call_cache *cc_entries;
-            union iseq_inline_storage_entry *is_entries;
-
-            // Copy mutable values from main threads
-            if (copy_cache_from_main_thread(unit->iseq, &cc_entries, &is_entries) == false) {
-                continue; // retry postponed_job failure, or stop worker
-            }
-
             // JIT compile
-            mjit_func_t func = convert_unit_to_func(unit, cc_entries, is_entries);
+            mjit_func_t func = convert_unit_to_func(unit);
+
+            // `mjit_copy_cache_from_main_thread` in `mjit_compile` may wait for a long time
+            // and worker may be stopped during the compilation.
+            if (stop_worker_p)
+                break;
 
             CRITICAL_SECTION_START(3, "in jit func replace");
             while (in_gc) { /* Make sure we're not GC-ing when touching ISeq */
Index: mjit_compile.c
===================================================================
--- mjit_compile.c	(revision 67287)
+++ mjit_compile.c	(revision 67288)
@@ -196,10 +196,14 @@ compile_cancel_handler(FILE *f, const st https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L196
     fprintf(f, "    return Qundef;\n");
 }
 
+extern bool mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, struct rb_call_cache **cc_entries, union iseq_inline_storage_entry **is_entries);
+
 // Compile ISeq to C code in `f`. It returns true if it succeeds to compile.
 bool
-mjit_compile(FILE *f, const struct rb_iseq_constant_body *body, const char *funcname, struct rb_call_cache *cc_entries, union iseq_inline_storage_entry *is_entries)
+mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname)
 {
+    const struct rb_iseq_constant_body *body = iseq->body;
+
     struct compile_status status;
     status.success = true;
     status.local_stack_p = !body->catch_except_p;
@@ -207,8 +211,8 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L211
     if (status.stack_size_for_pos == NULL)
         return false;
     memset(status.stack_size_for_pos, NOT_COMPILED_STACK_SIZE, sizeof(int) * body->iseq_size);
-    status.cc_entries = cc_entries;
-    status.is_entries = is_entries;
+    if (mjit_copy_cache_from_main_thread(iseq, &status.cc_entries, &status.is_entries) == false)
+        return false;
 
     /* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */
     if (!mjit_opts.debug) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]