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"
20#include "vm_callinfo.h"
23#include "insns_info.inc"
26#include "vm_insnhelper.h"
28#include "probes_helper.h"
31#include "internal/cont.h"
43 RUBY_OFFSET_RSTRING_LEN = offsetof(
struct RString,
len)
48STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
51STATIC_ASSERT(size_t_no_padding_bits,
sizeof(
size_t) ==
sizeof(uint64_t));
55STATIC_ASSERT(pointer_tagging_scheme,
USE_FLONUM);
73rb_yjit_array_len(
VALUE a)
78# define PTR2NUM(x) (rb_int2inum((intptr_t)(void *)(x)))
85 VALUE frame_id = PTR2NUM(frame);
87 if (
RTEST(rb_hash_aref(hash, frame_id))) {
91 VALUE frame_info = rb_hash_new();
104 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"name")), name);
105 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"file")), file);
106 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"samples")),
INT2NUM(0));
107 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"total_samples")),
INT2NUM(0));
108 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"edges")), rb_hash_new());
109 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"lines")), rb_hash_new());
112 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"line")), line);
115 rb_hash_aset(hash, frame_id, frame_info);
125rb_yjit_exit_locations_dict(
VALUE *yjit_raw_samples,
int *yjit_line_samples,
int samples_len)
127 VALUE result = rb_hash_new();
130 VALUE frames = rb_hash_new();
135 while (idx < samples_len) {
136 int num = (int)yjit_raw_samples[idx];
137 int line_num = (int)yjit_line_samples[idx];
147 for (
int o = 0; o < num; o++) {
148 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
165 rb_hash_aset(result,
ID2SYM(rb_intern(
"raw")), raw_samples);
166 rb_hash_aset(result,
ID2SYM(rb_intern(
"lines")), line_samples);
167 rb_hash_aset(result,
ID2SYM(rb_intern(
"frames")), frames);
177 if (rb_multi_ractor_p()) {
178 tracing_events = ruby_vm_event_enabled_global_flags;
184 tracing_events = rb_ec_ractor_hooks(ec)->events;
208 EXEC_EVENT_HOOK(ec,
RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
212 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
216 ec->cfp->sp[0] = return_value;
222rb_iseq_get_yjit_payload(
const rb_iseq_t *iseq)
226 return iseq->body->yjit_payload;
235rb_iseq_set_yjit_payload(
const rb_iseq_t *iseq,
void *payload)
240 iseq->body->yjit_payload = payload;
244rb_yjit_get_proc_ptr(
VALUE procv)
247 GetProcPtr(procv, proc);
254typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
256ID rb_get_symbol_id(
VALUE namep);
262 return def->body.bmethod.proc;
269 GetProcPtr(recv, proc);
270 return rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, block_handler);
274rb_yjit_iseq_builtin_attrs(
const rb_iseq_t *iseq)
276 return iseq->body->builtin_attrs;
281invokebuiltin_delegate_leave_p(
const rb_iseq_t *iseq)
283 int insn1 = rb_vm_insn_addr2opcode((
void *)iseq->body->iseq_encoded[0]);
284 if ((
int)iseq->body->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
287 int insn2 = rb_vm_insn_addr2opcode((
void *)iseq->body->iseq_encoded[insn_len(insn1)]);
288 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
294rb_yjit_builtin_function(
const rb_iseq_t *iseq)
296 if (invokebuiltin_delegate_leave_p(iseq)) {
305rb_yjit_str_simple_append(
VALUE str1,
VALUE str2)
307 return rb_str_cat(str1, RSTRING_PTR(str2), RSTRING_LEN(str2));
314rb_yarv_str_eql_internal(
VALUE str1,
VALUE str2)
317 return rb_str_eql_internal(str1, str2);
329rb_yjit_rb_ary_subseq_length(
VALUE ary,
long beg)
338 return rb_fix_div_fix(recv, obj);
344 return rb_fix_mod_fix(recv, obj);
350rb_yjit_ruby2_keywords_splat_p(
VALUE obj)
354 if (
len == 0)
return 0;
368 if (len < 0 || len > VM_ARGC_STACK_MAX)
return Qfalse;
388rb_yjit_splat_varg_cfunc(
VALUE *stack_splat_array)
390 VALUE splat_array = *stack_splat_array;
405rb_yjit_dump_iseq_loc(
const rb_iseq_t *iseq, uint32_t insn_idx)
409 VALUE path = rb_iseq_path(iseq);
411 fprintf(stderr,
"%s %.*s:%u\n", __func__, (
int)
len, ptr, rb_iseq_line_no(iseq, insn_idx));
416num_digits(
int integer)
419 while (integer /= 10) {
427rb_yjit_iseq_inspect(
const rb_iseq_t *iseq)
429 const char *label = RSTRING_PTR(iseq->body->location.label);
430 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
431 int lineno = iseq->body->location.code_location.beg_pos.lineno;
433 const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
435 snprintf(buf, size,
"%s@%s:%d", label, path, lineno);
445 RSTRUCT_SET(st, k, v);
450rb_ENCODING_GET(
VALUE obj)
458 return (ice->flags & IMEMO_CONST_CACHE_SHAREABLE) != 0;
464rb_yjit_obj_written(
VALUE old,
VALUE young,
const char *file,
int line)
466 rb_obj_written(old,
Qundef, young, file, line);
477 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
480 iseq->body->jit_exception = (rb_jit_func_t)code_ptr;
483 iseq->body->jit_entry = (rb_jit_func_t)code_ptr;
495rb_yjit_invalidate_all_method_lookup_assumptions(
void)
503rb_object_shape_count(
void)
506 return ULONG2NUM((
unsigned long)rb_shapes_count());
510rb_yjit_shape_obj_too_complex_p(
VALUE obj)
512 return rb_shape_obj_too_complex_p(obj);
516rb_yjit_shape_capacity(shape_id_t shape_id)
518 return RSHAPE_CAPACITY(shape_id);
522rb_yjit_shape_index(shape_id_t shape_id)
524 return RSHAPE_INDEX(shape_id);
529rb_yjit_sendish_sp_pops(
const struct rb_callinfo *ci)
531 return 1 - sp_inc_of_sendish(ci);
536rb_yjit_invokeblock_sp_pops(
const struct rb_callinfo *ci)
538 return 1 - sp_inc_of_invokeblock(ci);
544rb_yjit_set_exception_return(
rb_control_frame_t *cfp,
void *leave_exit,
void *leave_exception)
546 if (VM_FRAME_FINISHED_P(cfp)) {
548 cfp->jit_return = leave_exit;
550 else if (cfp->jit_return) {
551 while (!VM_FRAME_FINISHED_P(cfp)) {
552 if (cfp->jit_return == leave_exit) {
557 cfp->jit_return = leave_exception;
560 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
566 cfp->jit_return = leave_exception;
591#define yjit_c_builtin_p rb_yjit_c_builtin_p
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
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_CALL
A method, written in C, is called.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
uint32_t rb_event_flag_t
Represents event(s).
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define SIZET2NUM
Old name of RB_SIZE2NUM.
#define ZALLOC_N
Old name of RB_ZALLOC_N.
#define T_HASH
Old name of RUBY_T_HASH.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
static int RB_ENCODING_GET(VALUE obj)
Just another name of rb_enc_get_index.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Obtains a part of the passed array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
int len
Length of the buffer.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RARRAY_LEN
Just another name of rb_array_len.
static long rb_array_len(VALUE a)
Queries the length of the array.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
#define RTEST
This is an old name of RB_TEST.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.