Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
rjit.h (5fab31b15e32622c4b71d1d347a41937e9f9c212)
1#ifndef RUBY_RJIT_H
2#define RUBY_RJIT_H 1
3/**********************************************************************
4
5 rjit.h - Interface to RJIT
6
7 Copyright (C) 2023 Takashi Kokubun <k0kubun@ruby-lang.org>.
8
9**********************************************************************/
10
11#include "ruby/internal/config.h" // defines USE_RJIT
13#include "vm_core.h"
14
15# if USE_RJIT
16
17#include "ruby.h"
18#include "vm_core.h"
19
20// RJIT options which can be defined on the MRI command line.
21struct rb_rjit_options {
22 // Converted from "rjit" feature flag to tell the enablement
23 // information to ruby_show_version().
24 bool on;
25 // Size of executable memory block in MiB
26 unsigned int exec_mem_size;
27 // Number of calls to trigger JIT compilation
28 unsigned int call_threshold;
29 // Collect RJIT statistics
30 bool stats;
31 // Do not start RJIT until RJIT.enable is called
32 bool disable;
33 // Allow TracePoint during JIT compilation
34 bool trace;
35 // Trace side exit locations
36 bool trace_exits;
37 // Enable disasm of all JIT code
38 bool dump_disasm;
39 // Verify context objects
40 bool verify_ctx;
41};
42
43RUBY_SYMBOL_EXPORT_BEGIN
44RUBY_EXTERN struct rb_rjit_options rb_rjit_opts;
45RUBY_EXTERN bool rb_rjit_call_p;
46
47#define rb_rjit_call_threshold() rb_rjit_opts.call_threshold
48
49extern void rb_rjit_compile(const rb_iseq_t *iseq);
50RUBY_SYMBOL_EXPORT_END
51
52extern void rb_rjit_cancel_all(const char *reason);
53extern void rb_rjit_init(const struct rb_rjit_options *opts);
54extern void rb_rjit_free_iseq(const rb_iseq_t *iseq);
55extern void rb_rjit_iseq_update_references(struct rb_iseq_constant_body *const body);
56extern void rb_rjit_mark(void);
57extern void rb_rjit_iseq_mark(VALUE rjit_blocks);
58extern void rjit_notify_waitpid(int exit_code);
59
60extern void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
61extern void rb_rjit_cme_invalidate(rb_callable_method_entry_t *cme);
62extern void rb_rjit_before_ractor_spawn(void);
63extern void rb_rjit_constant_state_changed(ID id);
64extern void rb_rjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx);
65extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events);
66
67extern void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop);
68extern void rb_rjit_before_ractor_spawn(void);
69extern void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events);
70extern void rb_rjit_collect_vm_usage_insn(int insn);
71
72extern bool rb_rjit_enabled;
73extern bool rb_rjit_stats_enabled;
74extern bool rb_rjit_trace_exits_enabled;
75
76# else // USE_RJIT
77
78static inline void rb_rjit_compile(const rb_iseq_t *iseq){}
79
80static inline void rb_rjit_cancel_all(const char *reason){}
81static inline void rb_rjit_free_iseq(const rb_iseq_t *iseq){}
82static inline void rb_rjit_mark(void){}
83
84static inline void rb_rjit_bop_redefined(int redefined_flag, enum ruby_basic_operators bop) {}
85static inline void rb_rjit_cme_invalidate(rb_callable_method_entry_t *cme) {}
86static inline void rb_rjit_before_ractor_spawn(void) {}
87static inline void rb_rjit_constant_state_changed(ID id) {}
88static inline void rb_rjit_constant_ic_update(const rb_iseq_t *const iseq, IC ic, unsigned insn_idx) {}
89static inline void rb_rjit_tracing_invalidate_all(rb_event_flag_t new_iseq_events) {}
90
91#define rb_rjit_enabled false
92#define rb_rjit_call_p false
93#define rb_rjit_stats_enabled false
94#define rb_rjit_trace_exits_enabled false
95
96#define rb_rjit_call_threshold() UINT_MAX
97
98static inline void rb_rjit_collect_vm_usage_insn(int insn) {}
99
100# endif // USE_RJIT
101#endif // RUBY_RJIT_H
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:45
uint32_t rb_event_flag_t
Represents event(s).
Definition event.h:108
C99 shim for <stdbool.h>
Definition method.h:62
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40