mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Cache RubyVM::MJIT constants
for performance
This commit is contained in:
parent
5b3bd91fcb
commit
341b40bd0c
2 changed files with 11 additions and 8 deletions
7
mjit.c
7
mjit.c
|
@ -1804,6 +1804,11 @@ const struct ruby_opt_message mjit_option_messages[] = {
|
||||||
};
|
};
|
||||||
#undef M
|
#undef M
|
||||||
|
|
||||||
|
// RubyVM::MJIT::Compiler
|
||||||
|
VALUE rb_mMJITCompiler = 0;
|
||||||
|
// RubyVM::MJIT::C
|
||||||
|
VALUE rb_mMJITC = 0;
|
||||||
|
|
||||||
// Initialize MJIT. Start a thread creating the precompiled header and
|
// Initialize MJIT. Start a thread creating the precompiled header and
|
||||||
// processing ISeqs. The function should be called first for using MJIT.
|
// processing ISeqs. The function should be called first for using MJIT.
|
||||||
// If everything is successful, MJIT_INIT_P will be TRUE.
|
// If everything is successful, MJIT_INIT_P will be TRUE.
|
||||||
|
@ -1820,6 +1825,8 @@ mjit_init(const struct mjit_options *opts)
|
||||||
mjit_enabled = false;
|
mjit_enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
rb_mMJITCompiler = rb_const_get(rb_mMJIT, rb_intern("Compiler"));
|
||||||
|
rb_mMJITC = rb_const_get(rb_mMJIT, rb_intern("C"));
|
||||||
|
|
||||||
mjit_call_p = true;
|
mjit_call_p = true;
|
||||||
mjit_pid = getpid();
|
mjit_pid = getpid();
|
||||||
|
|
|
@ -36,10 +36,8 @@ struct case_dispatch_var {
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_ptr(const char *type, const void *ptr)
|
rb_ptr(const char *type, const void *ptr)
|
||||||
{
|
{
|
||||||
// TODO: cache constant
|
extern VALUE rb_mMJITC;
|
||||||
VALUE rb_mMJIT = rb_const_get(rb_cRubyVM, rb_intern("MJIT"));
|
VALUE rb_type = rb_funcall(rb_mMJITC, rb_intern(type), 0);
|
||||||
VALUE rb_mC = rb_const_get(rb_mMJIT, rb_intern("C"));
|
|
||||||
VALUE rb_type = rb_funcall(rb_mC, rb_intern(type), 0);
|
|
||||||
return rb_funcall(rb_type, rb_intern("new"), 1, ULONG2NUM((size_t)ptr));
|
return rb_funcall(rb_type, rb_intern("new"), 1, ULONG2NUM((size_t)ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,10 +122,8 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id)
|
||||||
bool original_call_p = mjit_call_p;
|
bool original_call_p = mjit_call_p;
|
||||||
mjit_call_p = false; // Avoid impacting JIT metrics by itself
|
mjit_call_p = false; // Avoid impacting JIT metrics by itself
|
||||||
|
|
||||||
// TODO: initialize the constant in mjit_init and use it
|
extern VALUE rb_mMJITCompiler;
|
||||||
VALUE rb_mMJIT = rb_const_get(rb_cRubyVM, rb_intern("MJIT"));
|
bool success = RTEST(rb_funcall(rb_mMJITCompiler, rb_intern("compile"), 4,
|
||||||
VALUE rb_mCompiler = rb_const_get(rb_mMJIT, rb_intern("Compiler"));
|
|
||||||
bool success = RTEST(rb_funcall(rb_mCompiler, rb_intern("compile"), 4,
|
|
||||||
PTR2NUM((VALUE)f), rb_ptr("rb_iseq_t", iseq), rb_str_new_cstr(funcname), INT2NUM(id)));
|
PTR2NUM((VALUE)f), rb_ptr("rb_iseq_t", iseq), rb_str_new_cstr(funcname), INT2NUM(id)));
|
||||||
|
|
||||||
mjit_call_p = original_call_p;
|
mjit_call_p = original_call_p;
|
||||||
|
|
Loading…
Add table
Reference in a new issue