mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
9b6b4674d7
based on inline cache when JIT cancel happens by that.
This feature was in the original MJIT implementation by Vladimir, but on
merging MJIT to Ruby it was removed for simplification. This commit adds
the functionality again for the following benchmark:
52f05781f6/concurrent-map/bench.rb
(shown float is duration seconds. shorter is better)
* Before
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6507579649914987
$ INHERIT=0 ruby -v --jit bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.5091587850474752
$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
--
1.6124781150138006
$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
--
1.7495657080435194 # <-- this
```
* After
```
$ INHERIT=0 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.653559010999743
$ INHERIT=0 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.4738391840364784
$ INHERIT=1 ruby -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.645227018976584
$ INHERIT=1 ruby --jit -v bench.rb
ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux]
last_commit=Recompile JIT-ed code without optimization
--
1.523708809982054 # <-- this
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
98 lines
5.4 KiB
Text
98 lines
5.4 KiB
Text
% # -*- C -*-
|
|
% # Copyright (c) 2018 Takashi Kokubun. All rights reserved.
|
|
% #
|
|
% # This file is a part of the programming language Ruby. Permission is hereby
|
|
% # granted, to either redistribute and/or modify this file, provided that the
|
|
% # conditions mentioned in the file COPYING are met. Consult the file for
|
|
% # details.
|
|
%
|
|
% # Optimized case of send / opt_send_without_block instructions.
|
|
{
|
|
MAYBE_UNUSED(int pc_moved_p) = FALSE;
|
|
% # compiler: Prepare operands which may be used by `insn.call_attribute`
|
|
% insn.opes.each_with_index do |ope, i|
|
|
MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>];
|
|
% end
|
|
% # compiler: Use copied cc to avoid race condition
|
|
CALL_CACHE cc_copy = status->cc_entries + (cc - body->cc_entries);
|
|
%
|
|
if (!status->compile_info->disable_send_cache && has_valid_method_type(cc_copy)) {
|
|
const rb_iseq_t *iseq;
|
|
unsigned int argc = ci->orig_argc; // this `argc` variable is for calculating a value's position on stack considering `blockarg`.
|
|
% if insn.name == 'send'
|
|
argc += ((ci->flag & VM_CALL_ARGS_BLOCKARG) ? 1 : 0); // simulate `vm_caller_setup_arg_block`'s `--reg_cfp->sp`
|
|
% end
|
|
|
|
if (!(ci->flag & VM_CALL_TAILCALL) // inlining non-tailcall path
|
|
&& cc_copy->me->def->type == VM_METHOD_TYPE_ISEQ && inlinable_iseq_p(ci, cc_copy, iseq = def_iseq_ptr(cc_copy->me->def))) { // CC_SET_FASTPATH in vm_callee_setup_arg
|
|
int param_size = iseq->body->param.size;
|
|
|
|
fprintf(f, "{\n");
|
|
% # JIT: Declare stack_size to be used in some macro of _mjit_compile_insn_body.erb
|
|
if (status->local_stack_p) {
|
|
fprintf(f, " MAYBE_UNUSED(unsigned int) stack_size = %u;\n", b->stack_size);
|
|
}
|
|
|
|
% # JIT: Invalidate call cache if it requires vm_search_method. This allows to inline some of following things.
|
|
fprintf(f, " if (UNLIKELY(GET_GLOBAL_METHOD_STATE() != %"PRI_SERIALT_PREFIX"u ||\n", cc_copy->method_state);
|
|
fprintf(f, " RCLASS_SERIAL(CLASS_OF(stack[%d])) != %"PRI_SERIALT_PREFIX"u)) {\n", b->stack_size - 1 - argc, cc_copy->class_serial);
|
|
fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos);
|
|
fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size);
|
|
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_send_inline);\n");
|
|
fprintf(f, " rb_mjit_iseq_compile_info(original_iseq->body)->disable_send_cache = true;\n");
|
|
fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n");
|
|
fprintf(f, " goto cancel;\n");
|
|
fprintf(f, " }\n");
|
|
|
|
% # JIT: move sp and pc if necessary
|
|
<%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%>
|
|
|
|
% # JIT: Print insn body in insns.def
|
|
fprintf(f, " {\n");
|
|
fprintf(f, " struct rb_calling_info calling;\n");
|
|
% if insn.name == 'send'
|
|
fprintf(f, " calling.block_handler = vm_caller_setup_arg_block(ec, reg_cfp, (CALL_INFO)0x%"PRIxVALUE", (rb_iseq_t *)0x%"PRIxVALUE", FALSE);\n", operands[0], operands[2]);
|
|
% else
|
|
fprintf(f, " calling.block_handler = VM_BLOCK_HANDLER_NONE;\n");
|
|
% end
|
|
fprintf(f, " calling.argc = %d;\n", ci->orig_argc);
|
|
fprintf(f, " calling.recv = stack[%d];\n", b->stack_size - 1 - argc);
|
|
|
|
% # JIT: Special CALL_METHOD. Bypass cc_copy->call and inline vm_call_iseq_setup_normal for vm_call_iseq_setup_func FASTPATH.
|
|
fprintf(f, " {\n");
|
|
fprintf(f, " VALUE v;\n");
|
|
fprintf(f, " vm_call_iseq_setup_normal(ec, reg_cfp, &calling, (const rb_callable_method_entry_t *)0x%"PRIxVALUE", 0, %d, %d);\n",
|
|
(VALUE)cc_copy->me, param_size, iseq->body->local_table_size); /* inlinable_iseq_p checks rb_simple_iseq_p, which ensures has_opt == FALSE */
|
|
if (iseq->body->catch_except_p) {
|
|
fprintf(f, " VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);\n");
|
|
fprintf(f, " v = vm_exec(ec, TRUE);\n");
|
|
}
|
|
else {
|
|
fprintf(f, " if ((v = mjit_exec(ec)) == Qundef) {\n");
|
|
fprintf(f, " VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);\n"); /* This is vm_call0_body's code after vm_call_iseq_setup */
|
|
fprintf(f, " v = vm_exec(ec, FALSE);\n");
|
|
fprintf(f, " }\n");
|
|
}
|
|
fprintf(f, " stack[%d] = v;\n", b->stack_size - argc - 1);
|
|
fprintf(f, " }\n");
|
|
|
|
fprintf(f, " }\n");
|
|
|
|
% # JIT: We should evaluate ISeq modified for TracePoint if it's enabled. Note: This is slow.
|
|
fprintf(f, " if (UNLIKELY(ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS)) {\n");
|
|
fprintf(f, " reg_cfp->sp = vm_base_ptr(reg_cfp) + %d;\n", b->stack_size + (int)<%= insn.call_attribute('sp_inc') %>);
|
|
if (!pc_moved_p) {
|
|
fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", next_pos);
|
|
}
|
|
fprintf(f, " RB_DEBUG_COUNTER_INC(mjit_cancel_trace);\n");
|
|
fprintf(f, " goto cancel;\n");
|
|
fprintf(f, " }\n");
|
|
|
|
% # compiler: Move JIT compiler's internal stack pointer
|
|
b->stack_size += <%= insn.call_attribute('sp_inc') %>;
|
|
|
|
fprintf(f, "}\n");
|
|
break;
|
|
}
|
|
}
|
|
}
|