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"
43STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
46STATIC_ASSERT(size_t_no_padding_bits,
sizeof(
size_t) ==
sizeof(uint64_t));
50STATIC_ASSERT(pointer_tagging_scheme,
USE_FLONUM);
72 VALUE frame_id = PTR2NUM(frame);
74 if (
RTEST(rb_hash_aref(hash, frame_id))) {
78 VALUE frame_info = rb_hash_new();
91 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"name")), name);
92 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"file")), file);
93 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"samples")),
INT2NUM(0));
94 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"total_samples")),
INT2NUM(0));
95 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"edges")), rb_hash_new());
96 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"lines")), rb_hash_new());
99 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"line")), line);
102 rb_hash_aset(hash, frame_id, frame_info);
112rb_yjit_exit_locations_dict(
VALUE *yjit_raw_samples,
int *yjit_line_samples,
int samples_len)
114 VALUE result = rb_hash_new();
117 VALUE frames = rb_hash_new();
122 while (idx < samples_len) {
123 int num = (int)yjit_raw_samples[idx];
124 int line_num = (int)yjit_line_samples[idx];
134 for (
int o = 0; o < num; o++) {
135 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
152 rb_hash_aset(result,
ID2SYM(rb_intern(
"raw")), raw_samples);
153 rb_hash_aset(result,
ID2SYM(rb_intern(
"lines")), line_samples);
154 rb_hash_aset(result,
ID2SYM(rb_intern(
"frames")), frames);
163 return ruby_vm_c_events_enabled > 0;
184 EXEC_EVENT_HOOK(ec,
RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
188 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
192 ec->cfp->sp[0] = return_value;
198rb_iseq_get_yjit_payload(
const rb_iseq_t *iseq)
202 return iseq->body->yjit_payload;
211rb_iseq_set_yjit_payload(
const rb_iseq_t *iseq,
void *payload)
216 iseq->body->yjit_payload = payload;
222typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
224ID rb_get_symbol_id(
VALUE namep);
230 GetProcPtr(recv, proc);
231 return rb_vm_invoke_proc(ec, proc, argc, argv, kw_splat, block_handler);
236invokebuiltin_delegate_leave_p(
const rb_iseq_t *iseq)
238 int insn1 = rb_vm_insn_addr2opcode((
void *)iseq->body->iseq_encoded[0]);
239 if ((
int)iseq->body->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
242 int insn2 = rb_vm_insn_addr2opcode((
void *)iseq->body->iseq_encoded[insn_len(insn1)]);
243 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
249rb_yjit_builtin_function(
const rb_iseq_t *iseq)
251 if (invokebuiltin_delegate_leave_p(iseq)) {
260rb_yjit_str_simple_append(
VALUE str1,
VALUE str2)
262 return rb_str_cat(str1, RSTRING_PTR(str2), RSTRING_LEN(str2));
276rb_yjit_rb_ary_subseq_length(
VALUE ary,
long beg)
285rb_yjit_ruby2_keywords_splat_p(
VALUE obj)
289 if (
len == 0)
return 0;
303 if (len < 0 || len > VM_ARGC_STACK_MAX)
return Qfalse;
323rb_yjit_splat_varg_cfunc(
VALUE *stack_splat_array)
325 VALUE splat_array = *stack_splat_array;
340rb_yjit_dump_iseq_loc(
const rb_iseq_t *iseq, uint32_t insn_idx)
344 VALUE path = rb_iseq_path(iseq);
346 fprintf(stderr,
"%s %.*s:%u\n", __func__, (
int)
len, ptr, rb_iseq_line_no(iseq, insn_idx));
351num_digits(
int integer)
354 while (integer /= 10) {
362rb_yjit_iseq_inspect(
const rb_iseq_t *iseq)
364 const char *label = RSTRING_PTR(iseq->body->location.label);
365 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
366 int lineno = iseq->body->location.code_location.beg_pos.lineno;
368 const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
370 snprintf(buf, size,
"%s@%s:%d", label, path, lineno);
380 RSTRUCT_SET(st, k, v);
385rb_ENCODING_GET(
VALUE obj)
393 return (ice->flags & IMEMO_CONST_CACHE_SHAREABLE) != 0;
399rb_yjit_obj_written(
VALUE old,
VALUE young,
const char *file,
int line)
401 rb_obj_written(old,
Qundef, young, file, line);
412 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
415 iseq->body->jit_exception = (rb_jit_func_t)code_ptr;
418 iseq->body->jit_entry = (rb_jit_func_t)code_ptr;
430rb_yjit_invalidate_all_method_lookup_assumptions(
void)
438rb_object_shape_count(
void)
441 return ULONG2NUM((
unsigned long)rb_shapes_count());
445rb_yjit_shape_obj_too_complex_p(
VALUE obj)
447 return rb_shape_obj_too_complex_p(obj);
451rb_yjit_shape_capacity(shape_id_t shape_id)
453 return RSHAPE_CAPACITY(shape_id);
457rb_yjit_shape_index(shape_id_t shape_id)
459 return RSHAPE_INDEX(shape_id);
464rb_yjit_sendish_sp_pops(
const struct rb_callinfo *ci)
466 return 1 - sp_inc_of_sendish(ci);
471rb_yjit_invokeblock_sp_pops(
const struct rb_callinfo *ci)
473 return 1 - sp_inc_of_invokeblock(ci);
479 return cme->def->body.bmethod.defined_ractor_id;
485rb_yjit_set_exception_return(
rb_control_frame_t *cfp,
void *leave_exit,
void *leave_exception)
487 if (VM_FRAME_FINISHED_P(cfp)) {
489 cfp->jit_return = leave_exit;
491 else if (cfp->jit_return) {
492 while (!VM_FRAME_FINISHED_P(cfp)) {
493 if (cfp->jit_return == leave_exit) {
498 cfp->jit_return = leave_exception;
501 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
507 cfp->jit_return = leave_exception;
515rb_vm_instruction_size(
void)
517 return VM_INSTRUCTION_SIZE;
541#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_RETURN
Return from a method, written in C.
#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.
#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.