8000 Merge pull request #1 from wildmaples/mo/iseq-inline-attempt · wildmaples/ruby@8d78477 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d78477

Browse files
authored
Merge pull request #1 from wildmaples/mo/iseq-inline-attempt
Add helper methods in RubyVM used for tests
2 parents 0bfa803 + 353c51e commit 8d78477

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

mjit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ mjit_exec_slowpath(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_
138138
return Qundef;
139139
}
140140

141+
static int inline_threshold = 2;
142+
141143
// Try to execute the current iseq in ec. Use JIT code if it is ready.
142144
// If it is not, add ISEQ to the compilation queue and return Qundef for MJIT.
143145
// YJIT compiles on the thread running the iseq.
@@ -157,7 +159,7 @@ mjit_exec(rb_execution_context_t *ec)
157159
body->total_calls++;
158160
}
159161

160-
if (body->total_calls == 2) {
162+
if (body->total_calls == (unsigned long) inline_threshold) {
161163
const rb_callable_method_entry_t *cme;
162164

163165
cme = rb_vm_frame_method_entry(ec->cfp);

vm.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,48 @@ vm_keep_script_lines_set(VALUE self, VALUE flags)
34753475
return flags;
34763476
}
34773477

3478+
/*
3479+
* call-seq:
3480+
* RubyVM.enable_inlining! -> true
3481+
*
3482+
* It turns on the experimenal inlining feature.
3483+
* This API is used for testing purposes.
3484+
*/
3485+
static VALUE
3486+
vm_enable_inlining(VALUE self)
3487+
{
3488+
mjit_call_p = true;
3489+
return RBOOL(true);
3490+
}
3491+
3492+
/*
3493+
* call-seq:
3494+
* RubyVM.disable_inlining! -> false
3495+
*
3496+
* It turns off the experimenal inlining feature.
3497+
* This API is used for testing purposes.
3498+
*/
3499+
static VALUE
3500+
vm_disable_inlining(VALUE self)
3501+
{
3502+
mjit_call_p = false;
3503+
return RBOOL(false);
3504+
}
3505+
3506+
/*
3507+
* call-seq:
3508+
* RubyVM.inline_threshold = int
3509+
*
3510+
* It sets the number of method call as the inlining threshold.
3511+
* This API is used for testing purposes.
3512+
*/
3513+
static VALUE
3514+
vm_inline_threshold_set(VALUE self, VALUE n)
3515+
{
3516+
inline_threshold = NUM2INT(n);
3517+
return n;
3518+
}
3519+
34783520
void
34793521
Init_VM(void)
34803522
{
@@ -3499,6 +3541,9 @@ Init_VM(void)
34993541
rb_define_singleton_method(rb_cRubyVM, "stat", vm_stat, -1);
35003542
rb_define_singleton_method(rb_cRubyVM, "keep_script_lines", vm_keep_script_lines, 0);
35013543
rb_define_singleton_method(rb_cRubyVM, "keep_script_lines=", vm_keep_script_lines_set, 1);
3544+
rb_define_singleton_method(rb_cRubyVM, "enable_inlining!", vm_enable_inlining, 0);
3545+
rb_define_singleton_method(rb_cRubyVM, "disable_inlining!", vm_disable_inlining, 0);
3546+
rb_define_singleton_method(rb_cRubyVM, "inline_threshold=", vm_inline_threshold_set, 1);
35023547

35033548
#if USE_DEBUG_COUNTER
35043549
rb_define_singleton_method(rb_cRubyVM, "reset_debug_counters", rb_debug_counter_reset, 0);

0 commit comments

Comments
 (0)
0