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

ruby-changes:55367

From: k0kubun <ko1@a...>
Date: Wed, 17 Apr 2019 02:08:53 +0900 (JST)
Subject: [ruby-changes:55367] k0kubun:r67575 (trunk): Recompile without method inlining

k0kubun	2019-04-17 02:02:35 +0900 (Wed, 17 Apr 2019)

  New Revision: 67575

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

  Log:
    Recompile without method inlining
    
    if cancel happens in an inlined method.

  Modified files:
    trunk/mjit.h
    trunk/mjit_compile.c
    trunk/tool/ruby_vm/views/_mjit_compile_send.erb
Index: mjit.h
===================================================================
--- mjit.h	(revision 67574)
+++ mjit.h	(revision 67575)
@@ -61,6 +61,8 @@ struct rb_mjit_compile_info { https://github.com/ruby/ruby/blob/trunk/mjit.h#L61
     bool disable_ivar_cache;
     // Disable send/opt_send_without_block optimizations based on inline cache
     bool disable_send_cache;
+    // Disable method inlining
+    bool disable_inlining;
 };
 
 typedef VALUE (*mjit_func_t)(rb_execution_context_t *, rb_control_frame_t *);
Index: mjit_compile.c
===================================================================
--- mjit_compile.c	(revision 67574)
+++ mjit_compile.c	(revision 67575)
@@ -202,6 +202,8 @@ compile_inlined_cancel_handler(FILE *f, https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L202
 {
     fprintf(f, "\ncancel:\n");
     fprintf(f, "    RB_DEBUG_COUNTER_INC(mjit_cancel);\n");
+    fprintf(f, "    rb_mjit_iseq_compile_info(original_iseq->body)->disable_inlining = true;\n");
+    fprintf(f, "    rb_mjit_recompile_iseq(original_iseq);\n");
 
     // Swap pc/sp set on cancel with original pc/sp.
     fprintf(f, "    const VALUE current_pc = reg_cfp->pc;\n");
@@ -276,7 +278,8 @@ mjit_compile_body(FILE *f, const rb_iseq https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L278
     else {
         fprintf(f, "    VALUE *stack = reg_cfp->sp;\n");
     }
-    fprintf(f, "    static const rb_iseq_t *original_iseq = 0x%"PRIxVALUE";\n", (VALUE)iseq);
+    if (status->inlined_iseqs != NULL) // i.e. compile root
+        fprintf(f, "    static const rb_iseq_t *original_iseq = 0x%"PRIxVALUE";\n", (VALUE)iseq);
     fprintf(f, "    static const VALUE *const original_body_iseq = (VALUE *)0x%"PRIxVALUE";\n",
             (VALUE)body->iseq_encoded);
 
@@ -396,8 +399,8 @@ precompile_inlinable_iseqs(FILE *f, cons https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L399
                         && !mjit_copy_cache_from_main_thread(child_iseq, child_status.cc_entries, child_status.is_entries))
                     return false;
 
-                fprintf(f, "ALWAYS_INLINE(static VALUE _mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self));\n", pos);
-                fprintf(f, "static inline VALUE\n_mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self)\n{\n", pos);
+                fprintf(f, "ALWAYS_INLINE(static VALUE _mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq));\n", pos);
+                fprintf(f, "static inline VALUE\n_mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq)\n{\n", pos);
                 fprintf(f, "    const VALUE *orig_pc = reg_cfp->pc;\n");
                 fprintf(f, "    const VALUE *orig_sp = reg_cfp->sp;\n");
                 bool success = mjit_compile_body(f, child_iseq, &child_status);
@@ -428,15 +431,16 @@ mjit_compile(FILE *f, const rb_iseq_t *i https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L431
             && !mjit_copy_cache_from_main_thread(iseq, status.cc_entries, status.is_entries))
         return false;
 
-    bool success = precompile_inlinable_iseqs(f, iseq, &status);
-    if (!success)
-        return false;
+    if (!status.compile_info->disable_send_cache && !status.compile_info->disable_inlining) {
+        if (!precompile_inlinable_iseqs(f, iseq, &status))
+            return false;
+    }
 
 #ifdef _WIN32
     fprintf(f, "__declspec(dllexport)\n");
 #endif
     fprintf(f, "VALUE\n%s(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)\n{\n", funcname);
-    success = mjit_compile_body(f, iseq, &status);
+    bool success = mjit_compile_body(f, iseq, &status);
     fprintf(f, "\n} // end of %s\n", funcname);
     return success;
 }
Index: tool/ruby_vm/views/_mjit_compile_send.erb
===================================================================
--- tool/ruby_vm/views/_mjit_compile_send.erb	(revision 67574)
+++ tool/ruby_vm/views/_mjit_compile_send.erb	(revision 67575)
@@ -49,7 +49,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_send.erb#L49
                 fprintf(f, "    {\n");
                 fprintf(f, "        VALUE orig_self = reg_cfp->self;\n");
                 fprintf(f, "        reg_cfp->self = stack[%d];\n", b->stack_size - argc - 1);
-                fprintf(f, "        stack[%d] = _mjit_inlined_%d(ec, reg_cfp, orig_self);\n", b->stack_size - argc - 1, pos);
+                fprintf(f, "        stack[%d] = _mjit_inlined_%d(ec, reg_cfp, orig_self, original_iseq);\n", b->stack_size - argc - 1, pos);
                 fprintf(f, "        reg_cfp->self = orig_self;\n");
                 fprintf(f, "    }\n");
             }

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

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