Ruby: yjit.c Source File

Ruby 3.4.9p82 (2026-03-11 revision 76cca827ab52ab1d346a728f068d5b8da3e2952b)

yjit.c
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 "vm_sync.h"
25#include "yjit.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
33// For mmapp(), sysconf()
34#ifndef _WIN32
35#include <unistd.h>
36#include <sys/mman.h>
37#endif
38
39#include <errno.h>
40
41// Field offsets for the RObject struct
42enum robject_offsets {
43 ROBJECT_OFFSET_AS_HEAP_IVPTR = offsetof(struct RObject, as.heap.ivptr),
44 ROBJECT_OFFSET_AS_HEAP_IV_INDEX_TBL = offsetof(struct RObject, as.heap.iv_index_tbl),
45 ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary),
46};
47
48// Field offsets for the RString struct
49enum rstring_offsets {
50 RUBY_OFFSET_RSTRING_LEN = offsetof(struct RString, len)
51};
52
53// We need size_t to have a known size to simplify code generation and FFI.
54// TODO(alan): check this in configure.ac to fail fast on 32 bit platforms.
55STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
56// I don't know any C implementation that has uint64_t and puts padding bits
57// into size_t but the standard seems to allow it.
58STATIC_ASSERT(size_t_no_padding_bits, sizeof(size_t) == sizeof(uint64_t));
59
60// This build config impacts the pointer tagging scheme and we only want to
61// support one scheme for simplicity.
62STATIC_ASSERT(pointer_tagging_scheme, USE_FLONUM);
63
64// NOTE: We can trust that uint8_t has no "padding bits" since the C spec
65// guarantees it. Wording about padding bits is more explicit in C11 compared
66// to C99. See C11 7.20.1.1p2. All this is to say we have _some_ standards backing to
67// use a Rust `*mut u8` to represent a C `uint8_t *`.
68//
69// If we don't want to trust that we can interpreter the C standard correctly, we
70// could outsource that work to the Rust standard library by sticking to fundamental
71// types in C such as int, long, etc. and use `std::os::raw::c_long` and friends on
72// the Rust side.
73//
74// What's up with the long prefix? Even though we build with `-fvisibility=hidden`
75// we are sometimes a static library where the option doesn't prevent name collision.
76// The "_yjit_" part is for trying to be informative. We might want different
77// suffixes for symbols meant for Rust and symbols meant for broader CRuby.
78
79bool
80rb_yjit_mark_writable(void *mem_block, uint32_t mem_size)
81{
82 return mprotect(mem_block, mem_size, PROT_READ | PROT_WRITE) == 0;
83}
84
85void
86rb_yjit_mark_executable(void *mem_block, uint32_t mem_size)
87{
88 // Do not call mprotect when mem_size is zero. Some platforms may return
89 // an error for it. https://github.com/Shopify/ruby/issues/450
90 if (mem_size == 0) {
91 return;
92 }
93 if (mprotect(mem_block, mem_size, PROT_READ | PROT_EXEC)) {
94 rb_bug("Couldn't make JIT page (%p, %lu bytes) executable, errno: %s",
95 mem_block, (unsigned long)mem_size, strerror(errno));
96 }
97}
98
99// Free the specified memory block.
100bool
101rb_yjit_mark_unused(void *mem_block, uint32_t mem_size)
102{
103 // On Linux, you need to use madvise MADV_DONTNEED to free memory.
104 // We might not need to call this on macOS, but it's not really documented.
105 // We generally prefer to do the same thing on both to ease testing too.
106 madvise(mem_block, mem_size, MADV_DONTNEED);
107
108 // On macOS, mprotect PROT_NONE seems to reduce RSS.
109 // We also call this on Linux to avoid executing unused pages.
110 return mprotect(mem_block, mem_size, PROT_NONE) == 0;
111}
112
113long
114rb_yjit_array_len(VALUE a)
115{
116 return rb_array_len(a);
117}
118
119// `start` is inclusive and `end` is exclusive.
120void
121rb_yjit_icache_invalidate(void *start, void *end)
122{
123 // Clear/invalidate the instruction cache. Compiles to nothing on x86_64
124 // but required on ARM before running freshly written code.
125 // On Darwin it's the same as calling sys_icache_invalidate().
126#ifdef __GNUC__
127 __builtin___clear_cache(start, end);
128#elif defined(__aarch64__)
129#error No instruction cache clear available with this compiler on Aarch64!
130#endif
131}
132
133# define PTR2NUM(x) (rb_int2inum((intptr_t)(void *)(x)))
134
135// For a given raw_sample (frame), set the hash with the caller's
136// name, file, and line number. Return the hash with collected frame_info.
137static void
138rb_yjit_add_frame(VALUE hash, VALUE frame)
139{
140 VALUE frame_id = PTR2NUM(frame);
141
142 if (RTEST(rb_hash_aref(hash, frame_id))) {
143 return;
144 }
145 else {
146 VALUE frame_info = rb_hash_new();
147 // Full label for the frame
148 VALUE name = rb_profile_frame_full_label(frame);
149 // Absolute path of the frame from rb_iseq_realpath
150 VALUE file = rb_profile_frame_absolute_path(frame);
151 // Line number of the frame
152 VALUE line = rb_profile_frame_first_lineno(frame);
153
154 // If absolute path isn't available use the rb_iseq_path
155 if (NIL_P(file)) {
156 file = rb_profile_frame_path(frame);
157 }
158
159 rb_hash_aset(frame_info, ID2SYM(rb_intern("name")), name);
160 rb_hash_aset(frame_info, ID2SYM(rb_intern("file")), file);
161 rb_hash_aset(frame_info, ID2SYM(rb_intern("samples")), INT2NUM(0));
162 rb_hash_aset(frame_info, ID2SYM(rb_intern("total_samples")), INT2NUM(0));
163 rb_hash_aset(frame_info, ID2SYM(rb_intern("edges")), rb_hash_new());
164 rb_hash_aset(frame_info, ID2SYM(rb_intern("lines")), rb_hash_new());
165
166 if (line != INT2FIX(0)) {
167 rb_hash_aset(frame_info, ID2SYM(rb_intern("line")), line);
168 }
169
170 rb_hash_aset(hash, frame_id, frame_info);
171 }
172}
173
174// Parses the YjitExitLocations raw_samples and line_samples collected by
175// rb_yjit_record_exit_stack and turns them into 3 hashes (raw, lines, and frames) to
176// be used by RubyVM::YJIT.exit_locations. yjit_raw_samples represents the raw frames information
177// (without name, file, and line), and yjit_line_samples represents the line information
178// of the iseq caller.
179 VALUE
180rb_yjit_exit_locations_dict(VALUE *yjit_raw_samples, int *yjit_line_samples, int samples_len)
181{
182 VALUE result = rb_hash_new();
183 VALUE raw_samples = rb_ary_new_capa(samples_len);
184 VALUE line_samples = rb_ary_new_capa(samples_len);
185 VALUE frames = rb_hash_new();
186 int idx = 0;
187
188 // While the index is less than samples_len, parse yjit_raw_samples and
189 // yjit_line_samples, then add casted values to raw_samples and line_samples array.
190 while (idx < samples_len) {
191 int num = (int)yjit_raw_samples[idx];
192 int line_num = (int)yjit_line_samples[idx];
193 idx++;
194
195 // + 1 as we append an additional sample for the insn
196 rb_ary_push(raw_samples, SIZET2NUM(num + 1));
197 rb_ary_push(line_samples, INT2NUM(line_num + 1));
198
199 // Loop through the length of samples_len and add data to the
200 // frames hash. Also push the current value onto the raw_samples
201 // and line_samples array respectively.
202 for (int o = 0; o < num; o++) {
203 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
204 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
205 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
206 idx++;
207 }
208
209 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
210 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
211 idx++;
212
213 rb_ary_push(raw_samples, SIZET2NUM(yjit_raw_samples[idx]));
214 rb_ary_push(line_samples, INT2NUM(yjit_line_samples[idx]));
215 idx++;
216 }
217
218 // Set add the raw_samples, line_samples, and frames to the results
219 // hash.
220 rb_hash_aset(result, ID2SYM(rb_intern("raw")), raw_samples);
221 rb_hash_aset(result, ID2SYM(rb_intern("lines")), line_samples);
222 rb_hash_aset(result, ID2SYM(rb_intern("frames")), frames);
223
224 return result;
225}
226
227uint32_t
228rb_yjit_get_page_size(void)
229{
230#if defined(_SC_PAGESIZE)
231 long page_size = sysconf(_SC_PAGESIZE);
232 if (page_size <= 0) rb_bug("yjit: failed to get page size");
233
234 // 1 GiB limit. x86 CPUs with PDPE1GB can do this and anything larger is unexpected.
235 // Though our design sort of assume we have fine grained control over memory protection
236 // which require small page sizes.
237 if (page_size > 0x40000000l) rb_bug("yjit page size too large");
238
239 return (uint32_t)page_size;
240#else
241#error "YJIT supports POSIX only for now"
242#endif
243}
244
245#if defined(MAP_FIXED_NOREPLACE) && defined(_SC_PAGESIZE)
246// Align the current write position to a multiple of bytes
247static uint8_t *
248align_ptr(uint8_t *ptr, uint32_t multiple)
249{
250 // Compute the pointer modulo the given alignment boundary
251 uint32_t rem = ((uint32_t)(uintptr_t)ptr) % multiple;
252
253 // If the pointer is already aligned, stop
254 if (rem == 0)
255 return ptr;
256
257 // Pad the pointer by the necessary amount to align it
258 uint32_t pad = multiple - rem;
259
260 return ptr + pad;
261}
262#endif
263
264// Address space reservation. Memory pages are mapped on an as needed basis.
265// See the Rust mm module for details.
266uint8_t *
267rb_yjit_reserve_addr_space(uint32_t mem_size)
268{
269#ifndef _WIN32
270 uint8_t *mem_block;
271
272 // On Linux
273 #if defined(MAP_FIXED_NOREPLACE) && defined(_SC_PAGESIZE)
274 uint32_t const page_size = (uint32_t)sysconf(_SC_PAGESIZE);
275 uint8_t *const cfunc_sample_addr = (void *)(uintptr_t)&rb_yjit_reserve_addr_space;
276 uint8_t *const probe_region_end = cfunc_sample_addr + INT32_MAX;
277 // Align the requested address to page size
278 uint8_t *req_addr = align_ptr(cfunc_sample_addr, page_size);
279
280 // Probe for addresses close to this function using MAP_FIXED_NOREPLACE
281 // to improve odds of being in range for 32-bit relative call instructions.
282 do {
283 mem_block = mmap(
284 req_addr,
285 mem_size,
286 PROT_NONE,
287 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE,
288 -1,
289 0
290 );
291
292 // If we succeeded, stop
293 if (mem_block != MAP_FAILED) {
294 ruby_annotate_mmap(mem_block, mem_size, "Ruby:rb_yjit_reserve_addr_space");
295 break;
296 }
297
298 // -4MiB. Downwards to probe away from the heap. (On x86/A64 Linux
299 // main_code_addr < heap_addr, and in case we are in a shared
300 // library mapped higher than the heap, downwards is still better
301 // since it's towards the end of the heap rather than the stack.)
302 req_addr -= 4 * 1024 * 1024;
303 } while (req_addr < probe_region_end);
304
305 // On MacOS and other platforms
306 #else
307 // Try to map a chunk of memory as executable
308 mem_block = mmap(
309 (void *)rb_yjit_reserve_addr_space,
310 mem_size,
311 PROT_NONE,
312 MAP_PRIVATE | MAP_ANONYMOUS,
313 -1,
314 0
315 );
316 #endif
317
318 // Fallback
319 if (mem_block == MAP_FAILED) {
320 // Try again without the address hint (e.g., valgrind)
321 mem_block = mmap(
322 NULL,
323 mem_size,
324 PROT_NONE,
325 MAP_PRIVATE | MAP_ANONYMOUS,
326 -1,
327 0
328 );
329
330 if (mem_block != MAP_FAILED) {
331 ruby_annotate_mmap(mem_block, mem_size, "Ruby:rb_yjit_reserve_addr_space:fallback");
332 }
333 }
334
335 // Check that the memory mapping was successful
336 if (mem_block == MAP_FAILED) {
337 perror("ruby: yjit: mmap:");
338 if(errno == ENOMEM) {
339 // No crash report if it's only insufficient memory
340 exit(EXIT_FAILURE);
341 }
342 rb_bug("mmap failed");
343 }
344
345 return mem_block;
346#else
347 // Windows not supported for now
348 return NULL;
349#endif
350}
351
352// Is anyone listening for :c_call and :c_return event currently?
353bool
354rb_c_method_tracing_currently_enabled(const rb_execution_context_t *ec)
355{
356 rb_event_flag_t tracing_events;
357 if (rb_multi_ractor_p()) {
358 tracing_events = ruby_vm_event_enabled_global_flags;
359 }
360 else {
361 // At the time of writing, events are never removed from
362 // ruby_vm_event_enabled_global_flags so always checking using it would
363 // mean we don't compile even after tracing is disabled.
364 tracing_events = rb_ec_ractor_hooks(ec)->events;
365 }
366
367 return tracing_events & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN);
368}
369
370// The code we generate in gen_send_cfunc() doesn't fire the c_return TracePoint event
371// like the interpreter. When tracing for c_return is enabled, we patch the code after
372// the C method return to call into this to fire the event.
373void
374rb_full_cfunc_return(rb_execution_context_t *ec, VALUE return_value)
375{
376 rb_control_frame_t *cfp = ec->cfp;
377 RUBY_ASSERT_ALWAYS(cfp == GET_EC()->cfp);
378 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
379
380 RUBY_ASSERT_ALWAYS(RUBYVM_CFUNC_FRAME_P(cfp));
381 RUBY_ASSERT_ALWAYS(me->def->type == VM_METHOD_TYPE_CFUNC);
382
383 // CHECK_CFP_CONSISTENCY("full_cfunc_return"); TODO revive this
384
385 // Pop the C func's frame and fire the c_return TracePoint event
386 // Note that this is the same order as vm_call_cfunc_with_frame().
387 rb_vm_pop_frame(ec);
388 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
389 // Note, this deviates from the interpreter in that users need to enable
390 // a c_return TracePoint for this DTrace hook to work. A reasonable change
391 // since the Ruby return event works this way as well.
392 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
393
394 // Push return value into the caller's stack. We know that it's a frame that
395 // uses cfp->sp because we are patching a call done with gen_send_cfunc().
396 ec->cfp->sp[0] = return_value;
397 ec->cfp->sp++;
398}
399
400unsigned int
401rb_iseq_encoded_size(const rb_iseq_t *iseq)
402{
403 return iseq->body->iseq_size;
404}
405
406// TODO(alan): consider using an opaque pointer for the payload rather than a void pointer
407void *
408rb_iseq_get_yjit_payload(const rb_iseq_t *iseq)
409{
410 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
411 if (iseq->body) {
412 return iseq->body->yjit_payload;
413 }
414 else {
415 // Body is NULL when constructing the iseq.
416 return NULL;
417 }
418}
419
420void
421rb_iseq_set_yjit_payload(const rb_iseq_t *iseq, void *payload)
422{
423 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
424 RUBY_ASSERT_ALWAYS(iseq->body);
425 RUBY_ASSERT_ALWAYS(NULL == iseq->body->yjit_payload);
426 iseq->body->yjit_payload = payload;
427}
428
429void
430rb_iseq_reset_jit_func(const rb_iseq_t *iseq)
431{
432 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
433 iseq->body->jit_entry = NULL;
434 iseq->body->jit_exception = NULL;
435 // Enable re-compiling this ISEQ. Event when it's invalidated for TracePoint,
436 // we'd like to re-compile ISEQs that haven't been converted to trace_* insns.
437 iseq->body->jit_entry_calls = 0;
438 iseq->body->jit_exception_calls = 0;
439}
440
441// Get the PC for a given index in an iseq
442 VALUE *
443rb_iseq_pc_at_idx(const rb_iseq_t *iseq, uint32_t insn_idx)
444{
445 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(iseq, imemo_iseq));
446 RUBY_ASSERT_ALWAYS(insn_idx < iseq->body->iseq_size);
447 VALUE *encoded = iseq->body->iseq_encoded;
448 VALUE *pc = &encoded[insn_idx];
449 return pc;
450}
451
452// Get the opcode given a program counter. Can return trace opcode variants.
453int
454rb_iseq_opcode_at_pc(const rb_iseq_t *iseq, const VALUE *pc)
455{
456 // YJIT should only use iseqs after AST to bytecode compilation
457 RUBY_ASSERT_ALWAYS(FL_TEST_RAW((VALUE)iseq, ISEQ_TRANSLATED));
458
459 const VALUE at_pc = *pc;
460 return rb_vm_insn_addr2opcode((const void *)at_pc);
461}
462
463unsigned long
464rb_RSTRING_LEN(VALUE str)
465{
466 return RSTRING_LEN(str);
467}
468
469char *
470rb_RSTRING_PTR(VALUE str)
471{
472 return RSTRING_PTR(str);
473}
474
475 rb_proc_t *
476rb_yjit_get_proc_ptr(VALUE procv)
477{
478 rb_proc_t *proc;
479 GetProcPtr(procv, proc);
480 return proc;
481}
482
483// This is defined only as a named struct inside rb_iseq_constant_body.
484// By giving it a separate typedef, we make it nameable by rust-bindgen.
485// Bindgen's temp/anon name isn't guaranteed stable.
486typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
487
488const char *
489rb_insn_name(VALUE insn)
490{
491 return insn_name(insn);
492}
493
494unsigned int
495rb_vm_ci_argc(const struct rb_callinfo *ci)
496{
497 return vm_ci_argc(ci);
498}
499
500 ID
501rb_vm_ci_mid(const struct rb_callinfo *ci)
502{
503 return vm_ci_mid(ci);
504}
505
506unsigned int
507rb_vm_ci_flag(const struct rb_callinfo *ci)
508{
509 return vm_ci_flag(ci);
510}
511
512const struct rb_callinfo_kwarg *
513rb_vm_ci_kwarg(const struct rb_callinfo *ci)
514{
515 return vm_ci_kwarg(ci);
516}
517
518int
519rb_get_cikw_keyword_len(const struct rb_callinfo_kwarg *cikw)
520{
521 return cikw->keyword_len;
522}
523
524 VALUE
525rb_get_cikw_keywords_idx(const struct rb_callinfo_kwarg *cikw, int idx)
526{
527 return cikw->keywords[idx];
528}
529
530rb_method_visibility_t
531rb_METHOD_ENTRY_VISI(const rb_callable_method_entry_t *me)
532{
533 return METHOD_ENTRY_VISI(me);
534}
535
536rb_method_type_t
537rb_get_cme_def_type(const rb_callable_method_entry_t *cme)
538{
539 if (UNDEFINED_METHOD_ENTRY_P(cme)) {
540 return VM_METHOD_TYPE_UNDEF;
541 }
542 else {
543 return cme->def->type;
544 }
545}
546
547 ID
548rb_get_cme_def_body_attr_id(const rb_callable_method_entry_t *cme)
549{
550 return cme->def->body.attr.id;
551}
552
553 ID rb_get_symbol_id(VALUE namep);
554
555enum method_optimized_type
556rb_get_cme_def_body_optimized_type(const rb_callable_method_entry_t *cme)
557{
558 return cme->def->body.optimized.type;
559}
560
561unsigned int
562rb_get_cme_def_body_optimized_index(const rb_callable_method_entry_t *cme)
563{
564 return cme->def->body.optimized.index;
565}
566
567rb_method_cfunc_t *
568rb_get_cme_def_body_cfunc(const rb_callable_method_entry_t *cme)
569{
570 return UNALIGNED_MEMBER_PTR(cme->def, body.cfunc);
571}
572
573uintptr_t
574rb_get_def_method_serial(const rb_method_definition_t *def)
575{
576 return def->method_serial;
577}
578
579 ID
580rb_get_def_original_id(const rb_method_definition_t *def)
581{
582 return def->original_id;
583}
584
585int
586rb_get_mct_argc(const rb_method_cfunc_t *mct)
587{
588 return mct->argc;
589}
590
591void *
592rb_get_mct_func(const rb_method_cfunc_t *mct)
593{
594 return (void*)(uintptr_t)mct->func; // this field is defined as type VALUE (*func)(ANYARGS)
595}
596
597const rb_iseq_t *
598rb_get_def_iseq_ptr(rb_method_definition_t *def)
599{
600 return def_iseq_ptr(def);
601}
602
603 VALUE
604rb_get_def_bmethod_proc(rb_method_definition_t *def)
605{
606 RUBY_ASSERT(def->type == VM_METHOD_TYPE_BMETHOD);
607 return def->body.bmethod.proc;
608}
609
610const rb_iseq_t *
611rb_get_iseq_body_local_iseq(const rb_iseq_t *iseq)
612{
613 return iseq->body->local_iseq;
614}
615
616const rb_iseq_t *
617rb_get_iseq_body_parent_iseq(const rb_iseq_t *iseq)
618{
619 return iseq->body->parent_iseq;
620}
621
622unsigned int
623rb_get_iseq_body_local_table_size(const rb_iseq_t *iseq)
624{
625 return iseq->body->local_table_size;
626}
627
628 VALUE *
629rb_get_iseq_body_iseq_encoded(const rb_iseq_t *iseq)
630{
631 return iseq->body->iseq_encoded;
632}
633
634unsigned
635rb_get_iseq_body_stack_max(const rb_iseq_t *iseq)
636{
637 return iseq->body->stack_max;
638}
639
640enum rb_iseq_type
641rb_get_iseq_body_type(const rb_iseq_t *iseq)
642{
643 return iseq->body->type;
644}
645
646bool
647rb_get_iseq_flags_has_lead(const rb_iseq_t *iseq)
648{
649 return iseq->body->param.flags.has_lead;
650}
651
652bool
653rb_get_iseq_flags_has_opt(const rb_iseq_t *iseq)
654{
655 return iseq->body->param.flags.has_opt;
656}
657
658bool
659rb_get_iseq_flags_has_kw(const rb_iseq_t *iseq)
660{
661 return iseq->body->param.flags.has_kw;
662}
663
664bool
665rb_get_iseq_flags_has_post(const rb_iseq_t *iseq)
666{
667 return iseq->body->param.flags.has_post;
668}
669
670bool
671rb_get_iseq_flags_has_kwrest(const rb_iseq_t *iseq)
672{
673 return iseq->body->param.flags.has_kwrest;
674}
675
676bool
677rb_get_iseq_flags_anon_kwrest(const rb_iseq_t *iseq)
678{
679 return iseq->body->param.flags.anon_kwrest;
680}
681
682bool
683rb_get_iseq_flags_has_rest(const rb_iseq_t *iseq)
684{
685 return iseq->body->param.flags.has_rest;
686}
687
688bool
689rb_get_iseq_flags_ruby2_keywords(const rb_iseq_t *iseq)
690{
691 return iseq->body->param.flags.ruby2_keywords;
692}
693
694bool
695rb_get_iseq_flags_has_block(const rb_iseq_t *iseq)
696{
697 return iseq->body->param.flags.has_block;
698}
699
700bool
701rb_get_iseq_flags_ambiguous_param0(const rb_iseq_t *iseq)
702{
703 return iseq->body->param.flags.ambiguous_param0;
704}
705
706bool
707rb_get_iseq_flags_accepts_no_kwarg(const rb_iseq_t *iseq)
708{
709 return iseq->body->param.flags.accepts_no_kwarg;
710}
711
712bool
713rb_get_iseq_flags_forwardable(const rb_iseq_t *iseq)
714{
715 return iseq->body->param.flags.forwardable;
716}
717
718const rb_seq_param_keyword_struct *
719rb_get_iseq_body_param_keyword(const rb_iseq_t *iseq)
720{
721 return iseq->body->param.keyword;
722}
723
724unsigned
725rb_get_iseq_body_param_size(const rb_iseq_t *iseq)
726{
727 return iseq->body->param.size;
728}
729
730int
731rb_get_iseq_body_param_lead_num(const rb_iseq_t *iseq)
732{
733 return iseq->body->param.lead_num;
734}
735
736int
737rb_get_iseq_body_param_opt_num(const rb_iseq_t *iseq)
738{
739 return iseq->body->param.opt_num;
740}
741
742const VALUE *
743rb_get_iseq_body_param_opt_table(const rb_iseq_t *iseq)
744{
745 return iseq->body->param.opt_table;
746}
747
748 VALUE
749rb_optimized_call(VALUE *recv, rb_execution_context_t *ec, int argc, VALUE *argv, int kw_splat, VALUE block_handler)
750{
751 rb_proc_t *proc;
752 GetProcPtr(recv, proc);
753 return rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, block_handler);
754}
755
756unsigned int
757rb_yjit_iseq_builtin_attrs(const rb_iseq_t *iseq)
758{
759 return iseq->body->builtin_attrs;
760}
761
762// If true, the iseq has only opt_invokebuiltin_delegate(_leave) and leave insns.
763static bool
764invokebuiltin_delegate_leave_p(const rb_iseq_t *iseq)
765{
766 int insn1 = rb_vm_insn_addr2opcode((void *)iseq->body->iseq_encoded[0]);
767 if ((int)iseq->body->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
768 return false;
769 }
770 int insn2 = rb_vm_insn_addr2opcode((void *)iseq->body->iseq_encoded[insn_len(insn1)]);
771 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
772 insn2 == BIN(leave);
773}
774
775// Return an rb_builtin_function if the iseq contains only that builtin function.
776const struct rb_builtin_function *
777rb_yjit_builtin_function(const rb_iseq_t *iseq)
778{
779 if (invokebuiltin_delegate_leave_p(iseq)) {
780 return (const struct rb_builtin_function *)iseq->body->iseq_encoded[1];
781 }
782 else {
783 return NULL;
784 }
785}
786
787 VALUE
788rb_yjit_str_simple_append(VALUE str1, VALUE str2)
789{
790 return rb_str_cat(str1, RSTRING_PTR(str2), RSTRING_LEN(str2));
791}
792
793struct rb_control_frame_struct *
794rb_get_ec_cfp(const rb_execution_context_t *ec)
795{
796 return ec->cfp;
797}
798
799const rb_iseq_t *
800rb_get_cfp_iseq(struct rb_control_frame_struct *cfp)
801{
802 return cfp->iseq;
803}
804
805 VALUE *
806rb_get_cfp_pc(struct rb_control_frame_struct *cfp)
807{
808 return (VALUE*)cfp->pc;
809}
810
811 VALUE *
812rb_get_cfp_sp(struct rb_control_frame_struct *cfp)
813{
814 return cfp->sp;
815}
816
817void
818rb_set_cfp_pc(struct rb_control_frame_struct *cfp, const VALUE *pc)
819{
820 cfp->pc = pc;
821}
822
823void
824rb_set_cfp_sp(struct rb_control_frame_struct *cfp, VALUE *sp)
825{
826 cfp->sp = sp;
827}
828
829 VALUE
830rb_get_cfp_self(struct rb_control_frame_struct *cfp)
831{
832 return cfp->self;
833}
834
835 VALUE *
836rb_get_cfp_ep(struct rb_control_frame_struct *cfp)
837{
838 return (VALUE*)cfp->ep;
839}
840
841const VALUE *
842rb_get_cfp_ep_level(struct rb_control_frame_struct *cfp, uint32_t lv)
843{
844 uint32_t i;
845 const VALUE *ep = (VALUE*)cfp->ep;
846 for (i = 0; i < lv; i++) {
847 ep = VM_ENV_PREV_EP(ep);
848 }
849 return ep;
850}
851
852extern VALUE *rb_vm_base_ptr(struct rb_control_frame_struct *cfp);
853
854 VALUE
855rb_yarv_class_of(VALUE obj)
856{
857 return rb_class_of(obj);
858}
859
860// YJIT needs this function to never allocate and never raise
861 VALUE
862rb_yarv_str_eql_internal(VALUE str1, VALUE str2)
863{
864 // We wrap this since it's static inline
865 return rb_str_eql_internal(str1, str2);
866}
867
868 VALUE
869rb_str_neq_internal(VALUE str1, VALUE str2)
870{
871 return rb_str_eql_internal(str1, str2) == Qtrue ? Qfalse : Qtrue;
872}
873
874// YJIT needs this function to never allocate and never raise
875 VALUE
876rb_yarv_ary_entry_internal(VALUE ary, long offset)
877{
878 return rb_ary_entry_internal(ary, offset);
879}
880
881extern VALUE rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary);
882
883 VALUE
884rb_yjit_rb_ary_subseq_length(VALUE ary, long beg)
885{
886 long len = RARRAY_LEN(ary);
887 return rb_ary_subseq(ary, beg, len);
888}
889
890 VALUE
891rb_yjit_fix_div_fix(VALUE recv, VALUE obj)
892{
893 return rb_fix_div_fix(recv, obj);
894}
895
896 VALUE
897rb_yjit_fix_mod_fix(VALUE recv, VALUE obj)
898{
899 return rb_fix_mod_fix(recv, obj);
900}
901
902// Return non-zero when `obj` is an array and its last item is a
903// `ruby2_keywords` hash. We don't support this kind of splat.
904size_t
905rb_yjit_ruby2_keywords_splat_p(VALUE obj)
906{
907 if (!RB_TYPE_P(obj, T_ARRAY)) return 0;
908 long len = RARRAY_LEN(obj);
909 if (len == 0) return 0;
910 VALUE last = RARRAY_AREF(obj, len - 1);
911 if (!RB_TYPE_P(last, T_HASH)) return 0;
912 return FL_TEST_RAW(last, RHASH_PASS_AS_KEYWORDS);
913}
914
915// Checks to establish preconditions for rb_yjit_splat_varg_cfunc()
916 VALUE
917rb_yjit_splat_varg_checks(VALUE *sp, VALUE splat_array, rb_control_frame_t *cfp)
918{
919 // We inserted a T_ARRAY guard before this call
920 long len = RARRAY_LEN(splat_array);
921
922 // Large splat arrays need a separate allocation
923 if (len < 0 || len > VM_ARGC_STACK_MAX) return Qfalse;
924
925 // Would we overflow if we put the contents of the array onto the stack?
926 if (sp + len > (VALUE *)(cfp - 2)) return Qfalse;
927
928 // Reject keywords hash since that requires duping it sometimes
929 if (len > 0) {
930 VALUE last_hash = RARRAY_AREF(splat_array, len - 1);
931 if (RB_TYPE_P(last_hash, T_HASH) &&
932 FL_TEST_RAW(last_hash, RHASH_PASS_AS_KEYWORDS)) {
933 return Qfalse;
934 }
935 }
936
937 return Qtrue;
938}
939
940// Push array elements to the stack for a C method that has a variable number
941// of parameters. Returns the number of arguments the splat array contributes.
942int
943rb_yjit_splat_varg_cfunc(VALUE *stack_splat_array)
944{
945 VALUE splat_array = *stack_splat_array;
946 int len;
947
948 // We already checked that length fits in `int`
949 RUBY_ASSERT(RB_TYPE_P(splat_array, T_ARRAY));
950 len = (int)RARRAY_LEN(splat_array);
951
952 // Push the contents of the array onto the stack
953 MEMCPY(stack_splat_array, RARRAY_CONST_PTR(splat_array), VALUE, len);
954
955 return len;
956}
957
958// Print the Ruby source location of some ISEQ for debugging purposes
959void
960rb_yjit_dump_iseq_loc(const rb_iseq_t *iseq, uint32_t insn_idx)
961{
962 char *ptr;
963 long len;
964 VALUE path = rb_iseq_path(iseq);
965 RSTRING_GETMEM(path, ptr, len);
966 fprintf(stderr, "%s %.*s:%u\n", __func__, (int)len, ptr, rb_iseq_line_no(iseq, insn_idx));
967}
968
969// Get the number of digits required to print an integer
970static int
971num_digits(int integer)
972{
973 int num = 1;
974 while (integer /= 10) {
975 num++;
976 }
977 return num;
978}
979
980// Allocate a C string that formats an ISEQ label like iseq_inspect()
981char *
982rb_yjit_iseq_inspect(const rb_iseq_t *iseq)
983{
984 const char *label = RSTRING_PTR(iseq->body->location.label);
985 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
986 int lineno = iseq->body->location.code_location.beg_pos.lineno;
987
988 char *buf = ZALLOC_N(char, strlen(label) + strlen(path) + num_digits(lineno) + 3);
989 sprintf(buf, "%s@%s:%d", label, path, lineno);
990 return buf;
991}
992
993// The FL_TEST() macro
994 VALUE
995rb_FL_TEST(VALUE obj, VALUE flags)
996{
997 return RB_FL_TEST(obj, flags);
998}
999
1000// The FL_TEST_RAW() macro, normally an internal implementation detail
1001 VALUE
1002rb_FL_TEST_RAW(VALUE obj, VALUE flags)
1003{
1004 return FL_TEST_RAW(obj, flags);
1005}
1006
1007// The RB_TYPE_P macro
1008bool
1009rb_RB_TYPE_P(VALUE obj, enum ruby_value_type t)
1010{
1011 return RB_TYPE_P(obj, t);
1012}
1013
1014long
1015rb_RSTRUCT_LEN(VALUE st)
1016{
1017 return RSTRUCT_LEN(st);
1018}
1019
1020// There are RSTRUCT_SETs in ruby/internal/core/rstruct.h and internal/struct.h
1021// with different types (int vs long) for k. Here we use the one from ruby/internal/core/rstruct.h,
1022// which takes an int.
1023void
1024rb_RSTRUCT_SET(VALUE st, int k, VALUE v)
1025{
1026 RSTRUCT_SET(st, k, v);
1027}
1028
1029const struct rb_callinfo *
1030rb_get_call_data_ci(const struct rb_call_data *cd)
1031{
1032 return cd->ci;
1033}
1034
1035bool
1036rb_BASIC_OP_UNREDEFINED_P(enum ruby_basic_operators bop, uint32_t klass)
1037{
1038 return BASIC_OP_UNREDEFINED_P(bop, klass);
1039}
1040
1041 VALUE
1042rb_RCLASS_ORIGIN(VALUE c)
1043{
1044 return RCLASS_ORIGIN(c);
1045}
1046
1047// Return the string encoding index
1048int
1049rb_ENCODING_GET(VALUE obj)
1050{
1051 return RB_ENCODING_GET(obj);
1052}
1053
1054bool
1055rb_yjit_multi_ractor_p(void)
1056{
1057 return rb_multi_ractor_p();
1058}
1059
1060// For debug builds
1061void
1062rb_assert_iseq_handle(VALUE handle)
1063{
1064 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(handle, imemo_iseq));
1065}
1066
1067int
1068rb_IMEMO_TYPE_P(VALUE imemo, enum imemo_type imemo_type)
1069{
1070 return IMEMO_TYPE_P(imemo, imemo_type);
1071}
1072
1073bool
1074rb_yjit_constcache_shareable(const struct iseq_inline_constant_cache_entry *ice)
1075{
1076 return (ice->flags & IMEMO_CONST_CACHE_SHAREABLE) != 0;
1077}
1078
1079void
1080rb_assert_cme_handle(VALUE handle)
1081{
1082 RUBY_ASSERT_ALWAYS(!rb_objspace_garbage_object_p(handle));
1083 RUBY_ASSERT_ALWAYS(IMEMO_TYPE_P(handle, imemo_ment));
1084}
1085
1086// Used for passing a callback and other data over rb_objspace_each_objects
1087 struct iseq_callback_data {
1088 rb_iseq_callback callback;
1089 void *data;
1090};
1091
1092// Heap-walking callback for rb_yjit_for_each_iseq().
1093static int
1094for_each_iseq_i(void *vstart, void *vend, size_t stride, void *data)
1095{
1096 const struct iseq_callback_data *callback_data = (struct iseq_callback_data *)data;
1097 VALUE v = (VALUE)vstart;
1098 for (; v != (VALUE)vend; v += stride) {
1099 void *ptr = rb_asan_poisoned_object_p(v);
1100 rb_asan_unpoison_object(v, false);
1101
1102 if (rb_obj_is_iseq(v)) {
1103 rb_iseq_t *iseq = (rb_iseq_t *)v;
1104 callback_data->callback(iseq, callback_data->data);
1105 }
1106
1107 asan_poison_object_if(ptr, v);
1108 }
1109 return 0;
1110}
1111
1112// Iterate through the whole GC heap and invoke a callback for each iseq.
1113// Used for global code invalidation.
1114void
1115rb_yjit_for_each_iseq(rb_iseq_callback callback, void *data)
1116{
1117 struct iseq_callback_data callback_data = { .callback = callback, .data = data };
1118 rb_objspace_each_objects(for_each_iseq_i, (void *)&callback_data);
1119}
1120
1121// For running write barriers from Rust. Required when we add a new edge in the
1122// object graph from `old` to `young`.
1123void
1124rb_yjit_obj_written(VALUE old, VALUE young, const char *file, int line)
1125{
1126 rb_obj_written(old, Qundef, young, file, line);
1127}
1128
1129// Acquire the VM lock and then signal all other Ruby threads (ractors) to
1130// contend for the VM lock, putting them to sleep. YJIT uses this to evict
1131// threads running inside generated code so among other things, it can
1132// safely change memory protection of regions housing generated code.
1133void
1134rb_yjit_vm_lock_then_barrier(unsigned int *recursive_lock_level, const char *file, int line)
1135{
1136 rb_vm_lock_enter(recursive_lock_level, file, line);
1137 rb_vm_barrier();
1138}
1139
1140// Release the VM lock. The lock level must point to the same integer used to
1141// acquire the lock.
1142void
1143rb_yjit_vm_unlock(unsigned int *recursive_lock_level, const char *file, int line)
1144{
1145 rb_vm_lock_leave(recursive_lock_level, file, line);
1146}
1147
1148void
1149rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception)
1150{
1151 RB_VM_LOCK_ENTER();
1152 rb_vm_barrier();
1153
1154 // Compile a block version starting at the current instruction
1155 uint8_t *rb_yjit_iseq_gen_entry_point(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception); // defined in Rust
1156 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
1157
1158 if (jit_exception) {
1159 iseq->body->jit_exception = (rb_jit_func_t)code_ptr;
1160 }
1161 else {
1162 iseq->body->jit_entry = (rb_jit_func_t)code_ptr;
1163 }
1164
1165 RB_VM_LOCK_LEAVE();
1166}
1167
1168// GC root for interacting with the GC
1169 struct yjit_root_struct {
1170 bool unused; // empty structs are not legal in C99
1171};
1172
1173// For dealing with refinements
1174void
1175rb_yjit_invalidate_all_method_lookup_assumptions(void)
1176{
1177 // It looks like Module#using actually doesn't need to invalidate all the
1178 // method caches, so we do nothing here for now.
1179}
1180
1181// Number of object shapes, which might be useful for investigating YJIT exit reasons.
1182 VALUE
1183rb_object_shape_count(void)
1184{
1185 // next_shape_id starts from 0, so it's the same as the count
1186 return ULONG2NUM((unsigned long)GET_SHAPE_TREE()->next_shape_id);
1187}
1188
1189// Assert that we have the VM lock. Relevant mostly for multi ractor situations.
1190// The GC takes the lock before calling us, and this asserts that it indeed happens.
1191void
1192rb_yjit_assert_holding_vm_lock(void)
1193{
1194 ASSERT_vm_locking();
1195}
1196
1197// The number of stack slots that vm_sendish() pops for send and invokesuper.
1198size_t
1199rb_yjit_sendish_sp_pops(const struct rb_callinfo *ci)
1200{
1201 return 1 - sp_inc_of_sendish(ci); // + 1 to ignore return value push
1202}
1203
1204// The number of stack slots that vm_sendish() pops for invokeblock.
1205size_t
1206rb_yjit_invokeblock_sp_pops(const struct rb_callinfo *ci)
1207{
1208 return 1 - sp_inc_of_invokeblock(ci); // + 1 to ignore return value push
1209}
1210
1211// Setup jit_return to avoid returning a non-Qundef value on a non-FINISH frame.
1212// See [jit_compile_exception] for details.
1213void
1214rb_yjit_set_exception_return(rb_control_frame_t *cfp, void *leave_exit, void *leave_exception)
1215{
1216 if (VM_FRAME_FINISHED_P(cfp)) {
1217 // If it's a FINISH frame, just normally exit with a non-Qundef value.
1218 cfp->jit_return = leave_exit;
1219 }
1220 else if (cfp->jit_return) {
1221 while (!VM_FRAME_FINISHED_P(cfp)) {
1222 if (cfp->jit_return == leave_exit) {
1223 // Unlike jit_exec(), leave_exit is not safe on a non-FINISH frame on
1224 // jit_exec_exception(). See [jit_exec] and [jit_exec_exception] for
1225 // details. Exit to the interpreter with Qundef to let it keep executing
1226 // other Ruby frames.
1227 cfp->jit_return = leave_exception;
1228 return;
1229 }
1230 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1231 }
1232 }
1233 else {
1234 // If the caller was not JIT code, exit to the interpreter with Qundef
1235 // to keep executing Ruby frames with the interpreter.
1236 cfp->jit_return = leave_exception;
1237 }
1238}
1239
1240// Primitives used by yjit.rb
1241 VALUE rb_yjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self);
1242 VALUE rb_yjit_print_stats_p(rb_execution_context_t *ec, VALUE self);
1243 VALUE rb_yjit_log_enabled_p(rb_execution_context_t *c, VALUE self);
1244 VALUE rb_yjit_print_log_p(rb_execution_context_t *c, VALUE self);
1245 VALUE rb_yjit_trace_exit_locations_enabled_p(rb_execution_context_t *ec, VALUE self);
1246 VALUE rb_yjit_get_stats(rb_execution_context_t *ec, VALUE self, VALUE key);
1247 VALUE rb_yjit_reset_stats_bang(rb_execution_context_t *ec, VALUE self);
1248 VALUE rb_yjit_get_log(rb_execution_context_t *ec, VALUE self);
1249 VALUE rb_yjit_disasm_iseq(rb_execution_context_t *ec, VALUE self, VALUE iseq);
1250 VALUE rb_yjit_insns_compiled(rb_execution_context_t *ec, VALUE self, VALUE iseq);
1251 VALUE rb_yjit_code_gc(rb_execution_context_t *ec, VALUE self);
1252 VALUE rb_yjit_simulate_oom_bang(rb_execution_context_t *ec, VALUE self);
1253 VALUE rb_yjit_get_exit_locations(rb_execution_context_t *ec, VALUE self);
1254 VALUE rb_yjit_enable(rb_execution_context_t *ec, VALUE self, VALUE gen_stats, VALUE print_stats, VALUE gen_compilation_log, VALUE print_compilation_log);
1255 VALUE rb_yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self);
1256
1257// Allow YJIT_C_BUILTIN macro to force --yjit-c-builtin
1258#ifdef YJIT_C_BUILTIN
1259static VALUE yjit_c_builtin_p(rb_execution_context_t *ec, VALUE self) { return Qtrue; }
1260#else
1261#define yjit_c_builtin_p rb_yjit_c_builtin_p
1262#endif
1263
1264// Preprocessed yjit.rb generated during build
1265#include "yjit.rbinc"
RUBY_ASSERT_ALWAYS
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
Definition assert.h:199
RUBY_ASSERT
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
debug.h
rb_profile_frame_full_label
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
Definition vm_backtrace.c:1975
rb_profile_frame_absolute_path
VALUE rb_profile_frame_absolute_path(VALUE frame)
Identical to rb_profile_frame_path(), except it tries to expand the returning path.
Definition vm_backtrace.c:1855
rb_profile_frame_path
VALUE rb_profile_frame_path(VALUE frame)
Queries the path of the passed backtrace.
Definition vm_backtrace.c:1823
rb_profile_frame_first_lineno
VALUE rb_profile_frame_first_lineno(VALUE frame)
Queries the first line of the method of the passed frame pointer.
Definition vm_backtrace.c:1884
RUBY_EVENT_C_CALL
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
Definition event.h:43
RUBY_EVENT_C_RETURN
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
Definition event.h:44
rb_event_flag_t
uint32_t rb_event_flag_t
Represents event(s).
Definition event.h:108
RB_FL_TEST
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
Definition fl_type.h:495
Qundef
#define Qundef
Old name of RUBY_Qundef.
Definition special_consts.h:62
INT2FIX
#define INT2FIX
Old name of RB_INT2FIX.
Definition long.h:48
ID2SYM
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
ULONG2NUM
#define ULONG2NUM
Old name of RB_ULONG2NUM.
Definition long.h:60
SIZET2NUM
#define SIZET2NUM
Old name of RB_SIZE2NUM.
Definition size_t.h:62
ZALLOC_N
#define ZALLOC_N
Old name of RB_ZALLOC_N.
Definition memory.h:401
T_HASH
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
FL_TEST_RAW
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:132
Qtrue
#define Qtrue
Old name of RUBY_Qtrue.
Definition special_consts.h:61
INT2NUM
#define INT2NUM
Old name of RB_INT2NUM.
Definition int.h:43
Qfalse
#define Qfalse
Old name of RUBY_Qfalse.
Definition special_consts.h:59
T_ARRAY
#define T_ARRAY
Old name of RUBY_T_ARRAY.
Definition value_type.h:56
NIL_P
#define NIL_P
Old name of RB_NIL_P.
Definition special_consts.h:55
rb_class_of
static VALUE rb_class_of(VALUE obj)
Object to class mapping function.
Definition globals.h:172
RB_ENCODING_GET
static int RB_ENCODING_GET(VALUE obj)
Just another name of rb_enc_get_index.
Definition encoding.h:195
rb_hash_new
VALUE rb_hash_new(void)
Creates a new, empty hash object.
Definition hash.c:1477
rb_str_cat
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
Definition string.c:3453
len
int len
Length of the buffer.
Definition io.h:8
MEMCPY
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
RARRAY_LEN
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:51
rb_array_len
static long rb_array_len(VALUE a)
Queries the length of the array.
Definition rarray.h:255
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition rarray.h:403
RARRAY_CONST_PTR
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:52
RSTRING_GETMEM
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
Definition rstring.h:450
errno
#define errno
Ractor-aware version of errno.
Definition ruby.h:388
RTEST
#define RTEST
This is an old name of RB_TEST.
Definition special_consts.h:51
USE_FLONUM
#define USE_FLONUM
Definition special_consts.h:45
RObject
Ruby's ordinal objects.
Definition robject.h:83
RObject::heap
struct RObject::@210145204263252121304200074116325373231002256127::@364327012272247144206277021107154033016101046306 heap
Object that use separated memory region for instance variables use this pattern.
RObject::ivptr
VALUE * ivptr
Pointer to a C array that holds instance variables.
Definition robject.h:97
RObject::iv_index_tbl
struct rb_id_table * iv_index_tbl
This is a table that holds instance variable name to index mapping.
Definition robject.h:107
RString
Ruby's String.
Definition rstring.h:196
iseq_callback_data
Definition yjit.c:1087
iseq_inline_constant_cache_entry
Definition vm_core.h:259
rb_builtin_function
Definition builtin.h:6
rb_call_data
Definition vm_callinfo.h:576
rb_callinfo_kwarg
Definition vm_callinfo.h:48
rb_callinfo
Definition vm_callinfo.h:65
rb_control_frame_struct
Definition vm_core.h:900
rb_iseq_constant_body::param
struct rb_iseq_constant_body::@000024342312237062266020177166377106262102236123 param
parameter information
rb_proc_t
Definition vm_core.h:1268
yjit_root_struct
Definition yjit.c:1169
ID
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
RB_TYPE_P
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
ruby_value_type
ruby_value_type
C-level type of an object.
Definition value_type.h:113