Ruby 4.1.0dev (2026-10-28 revision 1b06b950bb460d20a9dcecb8b97d363adbf4a358)
yjit.c (1b06b950bb460d20a9dcecb8b97d363adbf4a358)
1// This part of YJIT helps interfacing with the rest of CRuby and with the OS.
2// Sometimes our FFI binding generation tool gives undesirable outputs when it
3// sees C features that Rust doesn't support well. We mitigate that by binding
4// functions which have simple parameter types. The boilerplate C functions for
5// that purpose are in this file.
6// Similarly, we wrap OS facilities we need in simple functions to help with
7// FFI and to avoid the need to use external crates.io Rust libraries.
8
9#include "internal.h"
10#include "internal/sanitizers.h"
11#include "internal/string.h"
12#include "internal/hash.h"
13#include "internal/variable.h"
14#include "internal/compile.h"
15#include "internal/class.h"
16#include "internal/fixnum.h"
17#include "internal/numeric.h"
18#include "internal/gc.h"
19#include "vm_core.h"
20#include "vm_callinfo.h"
21#include "builtin.h"
22#include "insns.inc"
23#include "insns_info.inc"
24#include "yjit.h"
25#include "zjit.h"
26#include "vm_insnhelper.h"
27#include "probes.h"
28#include "probes_helper.h"
29#include "iseq.h"
30#include "ruby/debug.h"
31#include "internal/cont.h"
32#include "internal/jit.h"
33
34// For mmapp(), sysconf()
35#ifndef _WIN32
36#include <unistd.h>
37#include <sys/mman.h>
38#endif
39
40#include <errno.h>
41
42// We need size_t to have a known size to simplify code generation and FFI.
43// TODO(alan): check this in configure.ac to fail fast on 32 bit platforms.
44STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
45// I don't know any C implementation that has uint64_t and puts padding bits
46// into size_t but the standard seems to allow it.
47STATIC_ASSERT(size_t_no_padding_bits, sizeof(size_t) == sizeof(uint64_t));
48
49// This build config impacts the pointer tagging scheme and we only want to
50// support one scheme for simplicity.
51STATIC_ASSERT(pointer_tagging_scheme, USE_FLONUM);
52
53// The bindings declare rb_len_t as i64, and codegen reads String and Array
54// lengths at that width.
55STATIC_ASSERT(rb_len_t_matches_bindings, sizeof(rb_len_t) == sizeof(int64_t));
56
57enum yjit_bindgen_constants {
58 // ISEQ_TRANSLATED expands to an enum value through a chain of macros,
59 // which bindgen cannot evaluate, so it needs to be re-exposed here.
60 YJIT_ISEQ_TRANSLATED = ISEQ_TRANSLATED,
61};
62
63// NOTE: We can trust that uint8_t has no "padding bits" since the C spec
64// guarantees it. Wording about padding bits is more explicit in C11 compared
65// to C99. See C11 7.20.1.1p2. All this is to say we have _some_ standards backing to
66// use a Rust `*mut u8` to represent a C `uint8_t *`.
67//
68// If we don't want to trust that we can interpreter the C standard correctly, we
69// could outsource that work to the Rust standard library by sticking to fundamental
70// types in C such as int, long, etc. and use `std::os::raw::c_long` and friends on
71// the Rust side.
72//
73// What's up with the long prefix? Even though we build with `-fvisibility=hidden`
74// we are sometimes a static library where the option doesn't prevent name collision.
75// The "_yjit_" part is for trying to be informative. We might want different
76// suffixes for symbols meant for Rust and symbols meant for broader CRuby.
77
78// For a given raw_sample (frame), set the hash with the caller's
79// name, file, and line number. Return the hash with collected frame_info.
80static void
81rb_yjit_add_frame(VALUE hash, VALUE frame)
82{
83 VALUE frame_id = PTR2NUM(frame);
84
85 if (RTEST(rb_hash_aref(hash, frame_id))) {
86 return;
87 }
88 else {
89 VALUE frame_info = rb_hash_new();
90 // Full label for the frame
92 // Absolute path of the frame from rb_iseq_realpath
94 // Line number of the frame
96
97 // If absolute path isn't available use the rb_iseq_path
98 if (NIL_P(file)) {
99 file = rb_profile_frame_path(frame);
100 }
101
102 rb_hash_aset(frame_info, ID2SYM(rb_intern("name")), name);
103 rb_hash_aset(frame_info, ID2SYM(rb_intern("file")), file);
104 rb_hash_aset(frame_info, ID2SYM(rb_intern("samples")), INT2NUM(0));
105 rb_hash_aset(frame_info, ID2SYM(rb_intern("total_samples")), INT2NUM(0));
106 rb_hash_aset(frame_info, ID2SYM(rb_intern("edges")), rb_hash_new());
107 rb_hash_aset(frame_info, ID2SYM(rb_intern("lines")), rb_hash_new());
108
109 if (line != INT2FIX(0)) {
110 rb_hash_aset(frame_info, ID2SYM(rb_intern("line")), line);
111 }
112
113 rb_hash_aset(hash, frame_id, frame_info);
114 }
115}
116
117// Parses the YjitExitLocations raw_samples and line_samples collected by
118// rb_yjit_record_exit_stack and turns them into 3 hashes (raw, lines, and frames) to
119// be used by RubyVM::YJIT.exit_locations. yjit_raw_samples represents the raw frames information
120// (without name, file, and line), and yjit_line_samples represents the line information
121// of the iseq caller.
122VALUE
123rb_yjit_exit_locations_dict(VALUE *yjit_raw_samples, int *yjit_line_samples, int samples_len)
124{
125 VALUE result = rb_hash_new();
126 VALUE raw_samples = rb_ary_new_capa(samples_len);
127 VALUE line_samples = rb_ary_new_capa(samples_len);
128 VALUE frames = rb_hash_new();
129 int idx = 0;
130
131 // While the index is less than samples_len, parse yjit_raw_samples and
132 // yjit_line_samples, then add casted values to raw_samples and line_samples array.
133 while (idx < samples_len) {
134 int num = (int)yjit_raw_samples[idx];
135 int line_num = (int)yjit_line_samples[idx];
136 idx++;
137
138 // + 1 as we append an additional sample for the insn
139 rb_ary_push(raw_samples, SIZET2NUM(num + 1));
140 rb_ary_push(line_samples, INT2NUM(line_num + 1));
141
142 // Loop through the length of samples_len and add data to the
143 // frames hash. Also push the current value onto the raw_samples
144 // and line_samples array respectively.
145 for (int o = 0; o < num; o++) {
146 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
147 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
148 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
149 idx++;
150 }
151
152 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
153 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
154 idx++;
155
156 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
157 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
158 idx++;
159 }
160
161 // Set add the raw_samples, line_samples, and frames to the results
162 // hash.
163 rb_hash_aset(result, ID2SYM(rb_intern("raw")), raw_samples);
164 rb_hash_aset(result, ID2SYM(rb_intern("lines")), line_samples);
165 rb_hash_aset(result, ID2SYM(rb_intern("frames")), frames);
166
167 return result;
168}
169
170// Is anyone listening for :c_call and :c_return event currently?
171bool
172rb_c_method_tracing_currently_enabled(const rb_execution_context_t *ec)
173{
174 return ruby_vm_c_events_enabled > 0;
175}
176
177// The code we generate in gen_send_cfunc() doesn't fire the c_return TracePoint event
178// like the interpreter. When tracing for c_return is enabled, we patch the code after
179// the C method return to call into this to fire the event.
180void
181rb_full_cfunc_return(rb_execution_context_t *ec, VALUE return_value)
182{
183 rb_control_frame_t *cfp = ec->cfp;
184 RUBY_ASSERT_ALWAYS(cfp == GET_EC()->cfp);
185 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
186
187 RUBY_ASSERT_ALWAYS(RUBYVM_CFUNC_FRAME_P(cfp));
188 RUBY_ASSERT_ALWAYS(me->def->type == VM_METHOD_TYPE_CFUNC);
189
190 // CHECK_CFP_CONSISTENCY("full_cfunc_return"); TODO revive this
191
192 // Pop the C func's frame and fire the c_return TracePoint event
193 // Note that this is the same order as vm_call_cfunc_with_frame().
194 rb_vm_pop_frame(ec);
195 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
196 // Note, this deviates from the interpreter in that users need to enable
197 // a c_return TracePoint for this DTrace hook to work. A reasonable change
198 // since the Ruby return event works this way as well.
199 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
200
201 // Push return value into the caller's stack. We know that it's a frame that
202 // uses cfp->sp because we are patching a call done with gen_send_cfunc().
203 ec->cfp->sp[0] = return_value;
204 ec->cfp->sp++;
205}
206
207// This is defined only as a named struct inside rb_iseq_constant_body.
208// By giving it a separate typedef, we make it nameable by rust-bindgen.
209// Bindgen's temp/anon name isn't guaranteed stable.
210typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
211
212ID rb_get_symbol_id(VALUE namep);
213
214// If true, the iseq has only opt_invokebuiltin_delegate(_leave) and leave insns.
215static bool
216invokebuiltin_delegate_leave_p(const rb_iseq_t *iseq)
217{
218 int insn1 = rb_vm_insn_addr2opcode((void *)ISEQ_BODY(iseq)->iseq_encoded[0]);
219 if ((int)ISEQ_BODY(iseq)->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
220 return false;
221 }
222 int insn2 = rb_vm_insn_addr2opcode((void *)ISEQ_BODY(iseq)->iseq_encoded[insn_len(insn1)]);
223 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
224 insn2 == BIN(leave);
225}
226
227// Return an rb_builtin_function if the iseq contains only that builtin function.
228const struct rb_builtin_function *
229rb_yjit_builtin_function(const rb_iseq_t *iseq)
230{
231 if (invokebuiltin_delegate_leave_p(iseq)) {
232 return (const struct rb_builtin_function *)ISEQ_BODY(iseq)->iseq_encoded[1];
233 }
234 else {
235 return NULL;
236 }
237}
238
239extern VALUE *rb_vm_base_ptr(struct rb_control_frame_struct *cfp);
240
241VALUE
242rb_str_neq_internal(VALUE str1, VALUE str2)
243{
244 return rb_str_eql_internal(str1, str2) == Qtrue ? Qfalse : Qtrue;
245}
246
247extern VALUE rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary);
248
249VALUE
250rb_yjit_rb_ary_subseq_length(VALUE ary, rb_len_t beg)
251{
252 rb_len_t len = RARRAY_LEN(ary);
253 return rb_ary_subseq(ary, beg, len);
254}
255
256// Checks to establish preconditions for rb_yjit_splat_varg_cfunc()
257VALUE
258rb_yjit_splat_varg_checks(VALUE *sp, VALUE splat_array, rb_control_frame_t *cfp)
259{
260 // We inserted a T_ARRAY guard before this call
261 rb_len_t len = RARRAY_LEN(splat_array);
262
263 // Large splat arrays need a separate allocation
264 if (len < 0 || len > VM_ARGC_STACK_MAX) return Qfalse;
265
266 // Would we overflow if we put the contents of the array onto the stack?
267 if (sp + len > (VALUE *)(cfp - 2)) return Qfalse;
268
269 // Reject keywords hash since that requires duping it sometimes
270 if (len > 0) {
271 VALUE last_hash = RARRAY_AREF(splat_array, len - 1);
272 if (RB_TYPE_P(last_hash, T_HASH) &&
273 FL_TEST_RAW(last_hash, RHASH_PASS_AS_KEYWORDS)) {
274 return Qfalse;
275 }
276 }
277
278 return Qtrue;
279}
280
281// Push array elements to the stack for a C method that has a variable number
282// of parameters. Returns the number of arguments the splat array contributes.
283int
284rb_yjit_splat_varg_cfunc(VALUE *stack_splat_array)
285{
286 VALUE splat_array = *stack_splat_array;
287 int len;
288
289 // We already checked that length fits in `int`
290 RUBY_ASSERT(RB_TYPE_P(splat_array, T_ARRAY));
291 len = (int)RARRAY_LEN(splat_array);
292
293 // Push the contents of the array onto the stack
294 MEMCPY(stack_splat_array, RARRAY_CONST_PTR(splat_array), VALUE, len);
295
296 return len;
297}
298
299// Print the Ruby source location of some ISEQ for debugging purposes
300void
301rb_yjit_dump_iseq_loc(const rb_iseq_t *iseq, uint32_t insn_idx)
302{
303 char *ptr;
305 VALUE path = rb_iseq_path(iseq);
306 RSTRING_GETMEM(path, ptr, len);
307 fprintf(stderr, "%s %.*s:%u\n", __func__, (int)len, ptr, rb_iseq_line_no(iseq, insn_idx));
308}
309
310// Get the number of digits required to print an integer
311static int
312num_digits(int integer)
313{
314 int num = 1;
315 while (integer /= 10) {
316 num++;
317 }
318 return num;
319}
320
321// Allocate a C string that formats an ISEQ label like iseq_inspect()
322char *
323rb_yjit_iseq_inspect(const rb_iseq_t *iseq)
324{
325 const char *label = RSTRING_PTR(ISEQ_BODY(iseq)->location.label);
326 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
327 int lineno = ISEQ_BODY(iseq)->location.code_location.beg_pos.lineno;
328
329 const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
330 char *buf = ZALLOC_N(char, size);
331 snprintf(buf, size, "%s@%s:%d", label, path, lineno);
332 return buf;
333}
334
335// There are RSTRUCT_SETs in ruby/internal/core/rstruct.h and internal/struct.h
336// with different types (int vs long) for k. Here we use the one from ruby/internal/core/rstruct.h,
337// which takes an int.
338void
339rb_RSTRUCT_SET(VALUE st, int k, VALUE v)
340{
341 RSTRUCT_SET(st, k, v);
342}
343
344// Return the string encoding index
345int
346rb_ENCODING_GET(VALUE obj)
347{
348 return RB_ENCODING_GET(obj);
349}
350
351// For running write barriers from Rust. Required when we add a new edge in the
352// object graph from `old` to `young`.
353void
354rb_yjit_obj_written(VALUE old, VALUE young, const char *file, int line)
355{
356 rb_obj_written(old, Qundef, young, file, line);
357}
358
359void
360rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
361{
362 RB_VM_LOCKING() {
363 rb_vm_barrier();
364
365 // Compile a block version starting at the current instruction
366 uint8_t *rb_yjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception); // defined in Rust
367 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
368
369 if (jit_exception) {
370 ISEQ_BODY(iseq)->jit_exception = (rb_jit_func_t)code_ptr;
371 }
372 else {
373 ISEQ_BODY(iseq)->jit_entry = (rb_jit_func_t)code_ptr;
374 }
375 }
376}
377
378// GC root for interacting with the GC
380 bool unused; // empty structs are not legal in C99
381};
382
383// For dealing with refinements
384void
385rb_yjit_invalidate_all_method_lookup_assumptions(void)
386{
387 // It looks like Module#using actually doesn't need to invalidate all the
388 // method caches, so we do nothing here for now.
389}
390
391// Number of object shapes, which might be useful for investigating YJIT exit reasons.
392VALUE
393rb_object_shape_count(void)
394{
395 // next_shape_id starts from 0, so it's the same as the count
396 return ULONG2NUM((unsigned long)rb_shapes_count());
397}
398
399bool
400rb_yjit_shape_obj_complex_p(VALUE obj)
401{
402 return rb_obj_shape_complex_p(obj);
403}
404
405bool
406rb_yjit_shape_obj_embedded_p(VALUE obj)
407{
408 return rb_obj_shape_embedded_p(obj);
409}
410
411attr_index_t
412rb_yjit_shape_capacity(shape_id_t shape_id)
413{
414 return RSHAPE_CAPACITY(shape_id);
415}
416
417attr_index_t
418rb_yjit_shape_index(shape_id_t shape_id)
419{
420 return RSHAPE_INDEX(shape_id);
421}
422
423// The number of stack slots that vm_sendish() pops for send and invokesuper.
424size_t
425rb_yjit_sendish_sp_pops(const struct rb_callinfo *ci)
426{
427 return 1 - sp_inc_of_sendish(ci); // + 1 to ignore return value push
428}
429
430// The number of stack slots that vm_sendish() pops for invokeblock.
431size_t
432rb_yjit_invokeblock_sp_pops(const struct rb_callinfo *ci)
433{
434 return 1 - sp_inc_of_invokeblock(ci); // + 1 to ignore return value push
435}
436
437rb_serial_t
438rb_yjit_cme_ractor_serial(const rb_callable_method_entry_t *cme)
439{
440 return cme->def->body.bmethod.defined_ractor_id;
441}
442
443// Setup jit_return to avoid returning a non-Qundef value on a non-FINISH frame.
444// See [jit_compile_exception] for details.
445void
446rb_yjit_set_exception_return(rb_control_frame_t *cfp, void *leave_exit, void *leave_exception)
447{
448 if (VM_FRAME_FINISHED_P(cfp)) {
449 // If it's a FINISH frame, just normally exit with a non-Qundef value.
450 cfp->jit_return = leave_exit;
451 }
452 else if (cfp->jit_return) {
453 while (!VM_FRAME_FINISHED_P(cfp)) {
454 if (cfp->jit_return == leave_exit) {
455 // Unlike jit_exec(), leave_exit is not safe on a non-FINISH frame on
456 // jit_exec_exception(). See [jit_exec] and [jit_exec_exception] for
457 // details. Exit to the interpreter with Qundef to let it keep executing
458 // other Ruby frames.
459 cfp->jit_return = leave_exception;
460 return;
461 }
462 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
463 }
464 }
465 else {
466 // If the caller was not JIT code, exit to the interpreter with Qundef
467 // to keep executing Ruby frames with the interpreter.
468 cfp->jit_return = leave_exception;
469 }
470}
471
472#ifdef _WIN32
473// RtlUnwindEx(), which longjmp() and C++ exceptions use, needs unwind info for
474// every frame. JIT code calls out only inside the frame gen_entry_prologue()
475// sets up with frame_pointer, so a single UNWIND_INFO based on RBP is right at
476// every call in the code region. It is wrong within the few instructions that
477// set up and tear down the frame, which make no calls, so only an asynchronous
478// exception there, such as a stack overflow on the push, would unwind wrongly:
479//
480// [RBP] caller's RBP
481// [RBP - 8] copy of RBP
482// [RBP - 16] R13
483// [RBP - 24] R12
484// [RBP - 32] RBX
485static const uint8_t yjit_unwind_info[] = {
486 1, // Version 1, no handler
487 0, // No prologue, since every call happens after it
488 9, // Count of unwind code slots
489 0x25, // Frame register RBP at 2 * 16 bytes above RBX
490 0, 0x34, 0, 0, // UWOP_SAVE_NONVOL RBX at [RBP - 32]
491 0, 0xc4, 1, 0, // UWOP_SAVE_NONVOL R12 at [RBP - 24]
492 0, 0xd4, 2, 0, // UWOP_SAVE_NONVOL R13 at [RBP - 16]
493 0, 0x03, // UWOP_SET_FPREG
494 0, 0x32, // UWOP_ALLOC_SMALL 32 bytes from [RBP - 8] down to RBX
495 0, 0x50, // UWOP_PUSH_NONVOL RBP
496 0, 0, // Padding to an even count
497};
498
499static RUNTIME_FUNCTION yjit_runtime_function;
500
501// Reserve the JIT region after a page holding the unwind info, which has to be
502// within 4GiB above the base address of the registered function table.
503uint8_t *
504rb_yjit_reserve_addr_space(uint32_t mem_size)
505{
506 uint32_t page_size = rb_jit_get_page_size();
507 uint8_t *base = rb_jit_reserve_addr_space(page_size + mem_size);
508 DWORD old_protect;
509
510 if (!VirtualAlloc(base, page_size, MEM_COMMIT, PAGE_READWRITE)) {
511 rb_bug("yjit: failed to commit the unwind info page, error: %lu", GetLastError());
512 }
513 memcpy(base, yjit_unwind_info, sizeof(yjit_unwind_info));
514 VirtualProtect(base, page_size, PAGE_READONLY, &old_protect);
515
516 // RtlVirtualUnwind() takes a call followed by a jmp to the start of the
517 // function for an epilogue, so start it at the unwind info no code jumps to.
518 yjit_runtime_function.BeginAddress = 0;
519 yjit_runtime_function.EndAddress = page_size + mem_size;
520 yjit_runtime_function.UnwindData = 0;
521 if (!RtlAddFunctionTable(&yjit_runtime_function, 1, (DWORD64)base)) {
522 rb_bug("yjit: failed to register unwind info for JIT code");
523 }
524
525 return base + page_size;
526}
527#endif
528
529// VM_INSTRUCTION_SIZE changes depending on if ZJIT is in the build. Since
530// bindgen can only grab one version of the constant and copy that to rust,
531// we make that the upper bound and this the accurate value.
532uint32_t
533rb_vm_instruction_size(void)
534{
535 return VM_INSTRUCTION_SIZE;
536}
537
538static int
539yjit_cdhash_all_fixnum_i(st_data_t key, st_data_t _val, st_data_t data)
540{
541 if (!FIXNUM_P((VALUE)key)) {
542 *((bool *)data) = false;
543 return ST_STOP;
544 }
545 return ST_CONTINUE;
546}
547
548bool
549rb_yjit_cdhash_all_fixnum_p(VALUE cdhash)
550{
551 bool all_fixnum = true;
552 st_foreach(rb_imemo_cdhash_tbl(cdhash), yjit_cdhash_all_fixnum_i, (st_data_t)&all_fixnum);
553 return all_fixnum;
554}
555
556int
557rb_yjit_cdhash_lookup(VALUE cdhash, st_data_t key, st_data_t *val)
558{
559 return st_lookup(rb_imemo_cdhash_tbl(cdhash), key, val);
560}
561
562// Primitives used by yjit.rb
563VALUE rb_yjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self);
564VALUE rb_yjit_print_stats_p(rb_execution_context_t *ec, VALUE self);
565VALUE rb_yjit_log_enabled_p(rb_execution_context_t *c, VALUE self);
566VALUE rb_yjit_print_log_p(rb_execution_context_t *c, VALUE self);
567VALUE rb_yjit_trace_exit_locations_enabled_p(rb_execution_context_t *ec, VALUE self);
568VALUE rb_yjit_get_stats(rb_execution_context_t *ec, VALUE self, VALUE key);
569VALUE rb_yjit_reset_stats_bang(rb_execution_context_t *ec, VALUE self);
570void rb_yjit_update_max_compile_time_ns(uint64_t max_compile_time_ns);
571VALUE rb_yjit_get_log(rb_execution_context_t *ec, VALUE self);
572VALUE rb_yjit_disasm_iseq(rb_execution_context_t *ec, VALUE self, VALUE iseq);
573VALUE rb_yjit_insns_compiled(rb_execution_context_t *ec, VALUE self, VALUE iseq);
574VALUE rb_yjit_code_gc(rb_execution_context_t *ec, VALUE self);
575VALUE rb_yjit_simulate_oom_bang(rb_execution_context_t *ec, VALUE self);
576VALUE rb_yjit_get_exit_locations(rb_execution_context_t *ec, VALUE self);
577VALUE rb_yjit_enable(rb_execution_context_t *ec, VALUE self, VALUE gen_stats, VALUE print_stats, VALUE gen_compilation_log, VALUE print_compilation_log, VALUE mem_size, VALUE call_threshold);
578VALUE rb_yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self);
579
580static VALUE
581rb_yjit_total_compile_time_ns_get(rb_execution_context_t *ec, VALUE self)
582{
583 return ULL2NUM(rb_yjit_total_compile_time_ns);
584}
585
586static VALUE
587rb_yjit_max_compile_time_ns_get(rb_execution_context_t *ec, VALUE self)
588{
589 return ULL2NUM(rb_yjit_max_compile_time_ns);
590}
591
592static VALUE
593rb_yjit_max_compile_time_ns_set(rb_execution_context_t *ec, VALUE self, VALUE max_compile_time_ns)
594{
595 rb_yjit_update_max_compile_time_ns(NUM2ULL(max_compile_time_ns));
596 return max_compile_time_ns;
597}
598
599// Allow YJIT_C_BUILTIN macro to force --yjit-c-builtin
600#ifdef YJIT_C_BUILTIN
601static VALUE yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self) { return Qtrue; }
602#else
603#define yjit_c_builtin_p rb_yjit_c_builtin_p
604#endif
605
606// Preprocessed yjit.rb generated during build
607#include "yjit.rbinc"
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
Definition assert.h:199
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
VALUE rb_profile_frame_absolute_path(VALUE frame)
Identical to rb_profile_frame_path(), except it tries to expand the returning path.
VALUE rb_profile_frame_path(VALUE frame)
Queries the path of the passed backtrace.
VALUE rb_profile_frame_first_lineno(VALUE frame)
Queries the first line of the method of the passed frame pointer.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
Definition event.h:44
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
Definition long.h:48
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
#define ULONG2NUM
Old name of RB_ULONG2NUM.
Definition long.h:60
#define SIZET2NUM
Old name of RB_SIZE2NUM.
Definition size_t.h:62
#define ZALLOC_N
Old name of RB_ZALLOC_N.
Definition memory.h:401
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:128
#define ULL2NUM
Old name of RB_ULL2NUM.
Definition long_long.h:31
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
Definition int.h:43
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
Definition value_type.h:56
#define NIL_P
Old name of RB_NIL_P.
#define NUM2ULL
Old name of RB_NUM2ULL.
Definition long_long.h:35
#define FIXNUM_P
Old name of RB_FIXNUM_P.
static int RB_ENCODING_GET(VALUE obj)
Just another name of rb_enc_get_index.
Definition encoding.h:195
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new_capa(rb_len_t capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_subseq(VALUE ary, rb_len_t beg, rb_len_t len)
Obtains a part of the passed array.
int len
Length of the buffer.
Definition io.h:8
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:50
#define RARRAY_AREF(a, i)
References an object in an array.
Definition rarray.h:421
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:51
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
Definition rstring.h:450
static VALUE RSTRUCT_SET(VALUE st, int k, VALUE v)
Resembles Struct#[]=.
Definition rstruct.h:92
#define RTEST
This is an old name of RB_TEST.
#define USE_FLONUM
Definition method.h:63
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
Definition value.h:142
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
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:376