Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ mjit_exec_slowpath(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_
return Qundef;
}

static int inline_threshold = 2;

// Try to execute the current iseq in ec. Use JIT code if it is ready.
// If it is not, add ISEQ to the compilation queue and return Qundef for MJIT.
// YJIT compiles on the thread running the iseq.
Expand All @@ -157,7 +159,7 @@ mjit_exec(rb_execution_context_t *ec)
body->total_calls++;
}

if (body->total_calls == 2) {
if (body->total_calls == (unsigned long) inline_threshold) {
const rb_callable_method_entry_t *cme;

cme = rb_vm_frame_method_entry(ec->cfp);
Expand Down
45 changes: 45 additions & 0 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,48 @@ vm_keep_script_lines_set(VALUE self, VALUE flags)
return flags;
}

/*
* call-seq:
* RubyVM.enable_inlining! -> true
*
* It turns on the experimenal inlining feature.
* This API is used for testing purposes.
*/
static VALUE
vm_enable_inlining(VALUE self)
{
mjit_call_p = true;
return RBOOL(true);
}

/*
* call-seq:
* RubyVM.disable_inlining! -> false
*
* It turns off the experimenal inlining feature.
* This API is used for testing purposes.
*/
static VALUE
vm_disable_inlining(VALUE self)
{
mjit_call_p = false;
return RBOOL(false);
}

/*
* call-seq:
* RubyVM.inline_threshold = int
*
* It sets the number of method call as the inlining threshold.
* This API is used for testing purposes.
*/
static VALUE
vm_inline_threshold_set(VALUE self, VALUE n)
{
inline_threshold = NUM2INT(n);
return n;
}

void
Init_VM(void)
{
Expand All @@ -3499,6 +3541,9 @@ Init_VM(void)
rb_define_singleton_method(rb_cRubyVM, "stat", vm_stat, -1);
rb_define_singleton_method(rb_cRubyVM, "keep_script_lines", vm_keep_script_lines, 0);
rb_define_singleton_method(rb_cRubyVM, "keep_script_lines=", vm_keep_script_lines_set, 1);
rb_define_singleton_method(rb_cRubyVM, "enable_inlining!", vm_enable_inlining, 0);
rb_define_singleton_method(rb_cRubyVM, "disable_inlining!", vm_disable_inlining, 0);
rb_define_singleton_method(rb_cRubyVM, "inline_threshold=", vm_inline_threshold_set, 1);

#if USE_DEBUG_COUNTER
rb_define_singleton_method(rb_cRubyVM, "reset_debug_counters", rb_debug_counter_reset, 0);
Expand Down