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

ruby-changes:51122

From: k0kubun <ko1@a...>
Date: Thu, 3 May 2018 09:52:35 +0900 (JST)
Subject: [ruby-changes:51122] k0kubun:r63329 (trunk): mjit_compile.inc.erb: verify stack consistency

k0kubun	2018-05-03 09:52:30 +0900 (Thu, 03 May 2018)

  New Revision: 63329

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

  Log:
    mjit_compile.inc.erb: verify stack consistency
    
    on JIT compilation. r63092 was risky without this check.
    
    mjit_compile.c: update comment about stack consistency check

  Modified files:
    trunk/mjit_compile.c
    trunk/tool/ruby_vm/views/mjit_compile.inc.erb
Index: mjit_compile.c
===================================================================
--- mjit_compile.c	(revision 63328)
+++ mjit_compile.c	(revision 63329)
@@ -176,7 +176,7 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L176
     status.compiled_for_pos = ZALLOC_N(int, body->iseq_size);
     status.local_stack_p = !body->catch_except_p;
 
-    /* For performance, disable stack consistency check on JIT unless debugging */
+    /* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */
     if (!mjit_opts.debug) {
         fprintf(f, "#undef OPT_CHECKED_RUN\n");
         fprintf(f, "#define OPT_CHECKED_RUN 0\n\n");
Index: tool/ruby_vm/views/mjit_compile.inc.erb
===================================================================
--- tool/ruby_vm/views/mjit_compile.inc.erb	(revision 63328)
+++ tool/ruby_vm/views/mjit_compile.inc.erb	(revision 63329)
@@ -46,14 +46,25 @@ switch (insn) { https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/mjit_compile.inc.erb#L46
 % (RubyVM::BareInstructions.to_a + RubyVM::OperandsUnifications.to_a).each do |insn|
 %   next if unsupported_insns.include?(insn.name)
   case BIN(<%= insn.name %>):
-%   if %w[opt_send_without_block send].include?(insn.name)
-<%= render 'mjit_compile_send', locals: { insn: insn } -%>
-%   elsif %w[opt_aref].include?(insn.name) # experimental. TODO: increase insns and make the list automatically by finding DISPATCH_ORIGINAL_INSN
-<%= render 'mjit_compile_send', locals: { insn: opt_send_without_block } -%>
+%   # Instruction-specific behavior in JIT
+%   case insn.name
+%   when 'opt_send_without_block', 'send'
+<%=   render 'mjit_compile_send', locals: { insn: insn } -%>
+%   when 'opt_aref' # experimental. TODO: increase insns and make the list automatically by finding DISPATCH_ORIGINAL_INSN
+<%=   render 'mjit_compile_send', locals: { insn: opt_send_without_block } -%>
+%   when 'leave'
+    if (b->stack_size != 1) {
+        if (mjit_opts.warnings || mjit_opts.verbose)
+            fprintf(stderr, "MJIT warning: Unexpected JIT stack_size on leave: %d\n", b->stack_size);
+        status->success = FALSE;
+    }
 %   end
+%
+%   # Main insn implementation generated by insns.def
 <%= render 'mjit_compile_insn', locals: { insn: insn, dispatched: false } -%>
     break;
 % end
+%
 % # We don't support InstructionsUnifications yet because it's not used for now.
 % # We don't support TraceInstructions yet. There is no blocker for it but it's just not implemented.
   default:

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

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