1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move RubyVM::MJIT to builtin Ruby

just less C code to maintain
This commit is contained in:
Takashi Kokubun 2022-06-15 10:19:33 -07:00
parent 1162523bae
commit 23459e4dbb
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD
5 changed files with 27 additions and 42 deletions

View file

@ -1054,6 +1054,7 @@ BUILTIN_RB_SRCS = \
$(srcdir)/numeric.rb \ $(srcdir)/numeric.rb \
$(srcdir)/io.rb \ $(srcdir)/io.rb \
$(srcdir)/marshal.rb \ $(srcdir)/marshal.rb \
$(srcdir)/mjit.rb \
$(srcdir)/pack.rb \ $(srcdir)/pack.rb \
$(srcdir)/trace_point.rb \ $(srcdir)/trace_point.rb \
$(srcdir)/warning.rb \ $(srcdir)/warning.rb \
@ -9430,6 +9431,7 @@ miniinit.$(OBJEXT): {$(VPATH)}mini_builtin.c
miniinit.$(OBJEXT): {$(VPATH)}miniinit.c miniinit.$(OBJEXT): {$(VPATH)}miniinit.c
miniinit.$(OBJEXT): {$(VPATH)}miniprelude.c miniinit.$(OBJEXT): {$(VPATH)}miniprelude.c
miniinit.$(OBJEXT): {$(VPATH)}missing.h miniinit.$(OBJEXT): {$(VPATH)}missing.h
miniinit.$(OBJEXT): {$(VPATH)}mjit.rb
miniinit.$(OBJEXT): {$(VPATH)}nilclass.rb miniinit.$(OBJEXT): {$(VPATH)}nilclass.rb
miniinit.$(OBJEXT): {$(VPATH)}node.h miniinit.$(OBJEXT): {$(VPATH)}node.h
miniinit.$(OBJEXT): {$(VPATH)}numeric.rb miniinit.$(OBJEXT): {$(VPATH)}numeric.rb
@ -9652,6 +9654,8 @@ mjit.$(OBJEXT): {$(VPATH)}method.h
mjit.$(OBJEXT): {$(VPATH)}missing.h mjit.$(OBJEXT): {$(VPATH)}missing.h
mjit.$(OBJEXT): {$(VPATH)}mjit.c mjit.$(OBJEXT): {$(VPATH)}mjit.c
mjit.$(OBJEXT): {$(VPATH)}mjit.h mjit.$(OBJEXT): {$(VPATH)}mjit.h
mjit.$(OBJEXT): {$(VPATH)}mjit.rb
mjit.$(OBJEXT): {$(VPATH)}mjit.rbinc
mjit.$(OBJEXT): {$(VPATH)}mjit_config.h mjit.$(OBJEXT): {$(VPATH)}mjit_config.h
mjit.$(OBJEXT): {$(VPATH)}mjit_worker.c mjit.$(OBJEXT): {$(VPATH)}mjit_worker.c
mjit.$(OBJEXT): {$(VPATH)}node.h mjit.$(OBJEXT): {$(VPATH)}node.h

View file

@ -101,6 +101,9 @@ rb_call_builtin_inits(void)
BUILTIN(yjit); BUILTIN(yjit);
BUILTIN(nilclass); BUILTIN(nilclass);
BUILTIN(marshal); BUILTIN(marshal);
#if USE_MJIT
BUILTIN(mjit);
#endif
Init_builtin_prelude(); Init_builtin_prelude();
} }
#undef CALL #undef CALL

10
mjit.c
View file

@ -375,10 +375,12 @@ mjit_notify_waitpid(int status)
// Return true if given ISeq body should be compiled by MJIT // Return true if given ISeq body should be compiled by MJIT
static inline int static inline int
mjit_target_iseq_p(struct rb_iseq_constant_body *body) mjit_target_iseq_p(const rb_iseq_t *iseq)
{ {
struct rb_iseq_constant_body *body = ISEQ_BODY(iseq);
return (body->type == ISEQ_TYPE_METHOD || body->type == ISEQ_TYPE_BLOCK) return (body->type == ISEQ_TYPE_METHOD || body->type == ISEQ_TYPE_BLOCK)
&& !body->builtin_inline_p; && !body->builtin_inline_p
&& strcmp("<internal:mjit>", RSTRING_PTR(rb_iseq_path(iseq)));
} }
// If recompile_p is true, the call is initiated by mjit_recompile. // If recompile_p is true, the call is initiated by mjit_recompile.
@ -389,7 +391,7 @@ mjit_add_iseq_to_process(const rb_iseq_t *iseq, const struct rb_mjit_compile_inf
// TODO: Support non-main Ractors // TODO: Support non-main Ractors
if (!mjit_enabled || pch_status == PCH_FAILED || !rb_ractor_main_p()) if (!mjit_enabled || pch_status == PCH_FAILED || !rb_ractor_main_p())
return; return;
if (!mjit_target_iseq_p(ISEQ_BODY(iseq))) { if (!mjit_target_iseq_p(iseq)) {
ISEQ_BODY(iseq)->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; // skip mjit_wait ISEQ_BODY(iseq)->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; // skip mjit_wait
return; return;
} }
@ -1104,4 +1106,6 @@ mjit_mark_cc_entries(const struct rb_iseq_constant_body *const body)
} }
} }
#include "mjit.rbinc"
#endif // USE_MJIT #endif // USE_MJIT

13
mjit.rb Normal file
View file

@ -0,0 +1,13 @@
module RubyVM::MJIT
def self.enabled?
Primitive.cexpr! 'RBOOL(mjit_enabled)'
end
def self.pause(wait: true)
Primitive.cexpr! 'mjit_pause(RTEST(wait))'
end
def self.resume
Primitive.cexpr! 'mjit_resume()'
end
end

39
vm.c
View file

@ -3408,36 +3408,6 @@ core_hash_merge_kwd(VALUE hash, VALUE kw)
return hash; return hash;
} }
/* Returns true if JIT is enabled */
static VALUE
mjit_enabled_p(VALUE _)
{
return RBOOL(mjit_enabled);
}
static VALUE
mjit_pause_m(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
{
VALUE options = Qnil;
VALUE wait = Qtrue;
rb_scan_args(argc, argv, "0:", &options);
if (!NIL_P(options)) {
static ID keyword_ids[1];
if (!keyword_ids[0])
keyword_ids[0] = rb_intern("wait");
rb_get_kwargs(options, keyword_ids, 0, 1, &wait);
}
return mjit_pause(RTEST(wait));
}
static VALUE
mjit_resume_m(VALUE _)
{
return mjit_resume();
}
extern VALUE *rb_gc_stack_start; extern VALUE *rb_gc_stack_start;
extern size_t rb_gc_stack_maxsize; extern size_t rb_gc_stack_maxsize;
@ -3618,15 +3588,6 @@ Init_VM(void)
rb_gc_register_mark_object(fcore); rb_gc_register_mark_object(fcore);
rb_mRubyVMFrozenCore = fcore; rb_mRubyVMFrozenCore = fcore;
/* ::RubyVM::MJIT
* Provides access to the Method JIT compiler of MRI.
* Of course, this module is MRI specific.
*/
VALUE mjit = rb_define_module_under(rb_cRubyVM, "MJIT");
rb_define_singleton_method(mjit, "enabled?", mjit_enabled_p, 0);
rb_define_singleton_method(mjit, "pause", mjit_pause_m, -1);
rb_define_singleton_method(mjit, "resume", mjit_resume_m, 0);
/* /*
* Document-class: Thread * Document-class: Thread
* *