11#include "ruby/internal/config.h"
17#include "debug_counter.h"
24enum rb_mjit_iseq_func {
26 NOT_ADDED_JIT_ISEQ_FUNC = 0,
29 NOT_READY_JIT_ISEQ_FUNC = 1,
32 NOT_COMPILED_JIT_ISEQ_FUNC = 2,
34 LAST_JIT_ISEQ_FUNC = 3
56 unsigned int min_calls;
68 bool disable_ivar_cache;
70 bool disable_exivar_cache;
72 bool disable_send_cache;
74 bool disable_inlining;
76 bool disable_const_cache;
81RUBY_SYMBOL_EXPORT_BEGIN
85extern void rb_mjit_add_iseq_to_process(
const rb_iseq_t *iseq);
88extern void rb_mjit_recompile_send(
const rb_iseq_t *iseq);
89extern void rb_mjit_recompile_ivar(
const rb_iseq_t *iseq);
90extern void rb_mjit_recompile_exivar(
const rb_iseq_t *iseq);
91extern void rb_mjit_recompile_inlining(
const rb_iseq_t *iseq);
92extern void rb_mjit_recompile_const(
const rb_iseq_t *iseq);
95extern void mjit_cancel_all(
const char *reason);
96extern bool mjit_compile(
FILE *f,
const rb_iseq_t *iseq,
const char *funcname,
int id);
98extern void mjit_gc_start_hook(
void);
99extern void mjit_gc_exit_hook(
void);
100extern void mjit_free_iseq(
const rb_iseq_t *iseq);
101extern void mjit_update_references(
const rb_iseq_t *iseq);
102extern void mjit_mark(
void);
104extern void mjit_cont_free(
struct mjit_cont *cont);
115 uintptr_t func_i = (uintptr_t)(body->jit_func);
116 ASSUME(func_i <= LAST_JIT_ISEQ_FUNC);
117 switch ((
enum rb_mjit_iseq_func)func_i) {
118 case NOT_ADDED_JIT_ISEQ_FUNC:
119 RB_DEBUG_COUNTER_INC(mjit_exec_not_added);
120 if (body->total_calls == mjit_opts.min_calls) {
121 rb_mjit_add_iseq_to_process(iseq);
122 if (UNLIKELY(mjit_opts.wait)) {
123 return rb_mjit_wait_call(ec, body);
127 case NOT_READY_JIT_ISEQ_FUNC:
128 RB_DEBUG_COUNTER_INC(mjit_exec_not_ready);
130 case NOT_COMPILED_JIT_ISEQ_FUNC:
131 RB_DEBUG_COUNTER_INC(mjit_exec_not_compiled);
147 bool yjit_enabled =
false;
151 yjit_enabled = rb_yjit_enabled_p();
154 if (mjit_call_p || yjit_enabled) {
159 if (yjit_enabled && !mjit_call_p && body->total_calls == rb_yjit_call_threshold()) {
162 if (!rb_yjit_compile_iseq(iseq, ec)) {
168 if (!(mjit_call_p || yjit_enabled))
171 RB_DEBUG_COUNTER_INC(mjit_exec);
173 mjit_func_t func = body->jit_func;
177 if (yjit_enabled && func == 0) {
181 if (UNLIKELY((uintptr_t)func <= LAST_JIT_ISEQ_FUNC)) {
183 RB_DEBUG_COUNTER_INC(mjit_frame_JT2VM);
185 RB_DEBUG_COUNTER_INC(mjit_frame_VM2VM);
187 return mjit_exec_slowpath(ec, iseq, body);
191 RB_DEBUG_COUNTER_INC(mjit_frame_JT2JT);
193 RB_DEBUG_COUNTER_INC(mjit_frame_VM2JT);
195 RB_DEBUG_COUNTER_INC(mjit_exec_call_func);
199 return func(ec, ec->cfp);
202void mjit_child_after_fork(
void);
205#define mjit_enabled true
207extern bool mjit_enabled;
209VALUE mjit_pause(
bool wait_p);
210VALUE mjit_resume(
void);
211void mjit_finish(
bool close_handle_p);
215static inline void mjit_cancel_all(
const char *reason){}
217static inline void mjit_cont_free(
struct mjit_cont *cont){}
218static inline void mjit_gc_start_hook(
void){}
219static inline void mjit_gc_exit_hook(
void){}
220static inline void mjit_free_iseq(
const rb_iseq_t *iseq){}
221static inline void mjit_mark(
void){}
223static inline void mjit_child_after_fork(
void){}
225#define mjit_enabled false
226static inline VALUE mjit_pause(
bool wait_p){
return Qnil; }
227static inline VALUE mjit_resume(
void){
return Qnil; }
228static inline void mjit_finish(
bool close_handle_p){}
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define Qundef
Old name of RUBY_Qundef.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define Qnil
Old name of RUBY_Qnil.
uintptr_t VALUE
Type that represents a Ruby object.