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"
32#include "internal/jit.h"
44STATIC_ASSERT(64b_size_t, SIZE_MAX == UINT64_MAX);
47STATIC_ASSERT(size_t_no_padding_bits,
sizeof(
size_t) ==
sizeof(uint64_t));
51STATIC_ASSERT(pointer_tagging_scheme,
USE_FLONUM);
53enum yjit_bindgen_constants {
56 YJIT_ISEQ_TRANSLATED = ISEQ_TRANSLATED,
79 VALUE frame_id = PTR2NUM(frame);
81 if (
RTEST(rb_hash_aref(hash, frame_id))) {
85 VALUE frame_info = rb_hash_new();
98 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"name")), name);
99 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"file")), file);
100 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"samples")),
INT2NUM(0));
101 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"total_samples")),
INT2NUM(0));
102 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"edges")), rb_hash_new());
103 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"lines")), rb_hash_new());
106 rb_hash_aset(frame_info,
ID2SYM(rb_intern(
"line")), line);
109 rb_hash_aset(hash, frame_id, frame_info);
119rb_yjit_exit_locations_dict(
VALUE *yjit_raw_samples,
int *yjit_line_samples,
int samples_len)
121 VALUE result = rb_hash_new();
124 VALUE frames = rb_hash_new();
129 while (idx < samples_len) {
130 int num = (int)yjit_raw_samples[idx];
131 int line_num = (int)yjit_line_samples[idx];
141 for (
int o = 0; o < num; o++) {
142 rb_yjit_add_frame(frames, yjit_raw_samples[idx]);
159 rb_hash_aset(result,
ID2SYM(rb_intern(
"raw")), raw_samples);
160 rb_hash_aset(result,
ID2SYM(rb_intern(
"lines")), line_samples);
161 rb_hash_aset(result,
ID2SYM(rb_intern(
"frames")), frames);
170 return ruby_vm_c_events_enabled > 0;
191 EXEC_EVENT_HOOK(ec,
RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, return_value);
195 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
199 ec->cfp->sp[0] = return_value;
206typedef struct rb_iseq_param_keyword rb_seq_param_keyword_struct;
208ID rb_get_symbol_id(
VALUE namep);
212invokebuiltin_delegate_leave_p(
const rb_iseq_t *iseq)
214 int insn1 = rb_vm_insn_addr2opcode((
void *)ISEQ_BODY(iseq)->iseq_encoded[0]);
215 if ((
int)ISEQ_BODY(iseq)->iseq_size != insn_len(insn1) + insn_len(BIN(leave))) {
218 int insn2 = rb_vm_insn_addr2opcode((
void *)ISEQ_BODY(iseq)->iseq_encoded[insn_len(insn1)]);
219 return (insn1 == BIN(opt_invokebuiltin_delegate) || insn1 == BIN(opt_invokebuiltin_delegate_leave)) &&
225rb_yjit_builtin_function(
const rb_iseq_t *iseq)
227 if (invokebuiltin_delegate_leave_p(iseq)) {
246rb_yjit_rb_ary_subseq_length(
VALUE ary,
long beg)
260 if (len < 0 || len > VM_ARGC_STACK_MAX)
return Qfalse;
280rb_yjit_splat_varg_cfunc(
VALUE *stack_splat_array)
282 VALUE splat_array = *stack_splat_array;
297rb_yjit_dump_iseq_loc(
const rb_iseq_t *iseq, uint32_t insn_idx)
301 VALUE path = rb_iseq_path(iseq);
303 fprintf(stderr,
"%s %.*s:%u\n", __func__, (
int)
len, ptr, rb_iseq_line_no(iseq, insn_idx));
308num_digits(
int integer)
311 while (integer /= 10) {
319rb_yjit_iseq_inspect(
const rb_iseq_t *iseq)
321 const char *label = RSTRING_PTR(ISEQ_BODY(iseq)->location.label);
322 const char *path = RSTRING_PTR(rb_iseq_path(iseq));
323 int lineno = ISEQ_BODY(iseq)->location.code_location.beg_pos.lineno;
325 const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
327 snprintf(buf, size,
"%s@%s:%d", label, path, lineno);
342rb_ENCODING_GET(
VALUE obj)
350rb_yjit_obj_written(
VALUE old,
VALUE young,
const char *file,
int line)
352 rb_obj_written(old,
Qundef, young, file, line);
363 uintptr_t code_ptr = (uintptr_t)rb_yjit_iseq_gen_entry_point(iseq, ec, jit_exception);
366 ISEQ_BODY(iseq)->jit_exception = (rb_jit_func_t)code_ptr;
369 ISEQ_BODY(iseq)->jit_entry = (rb_jit_func_t)code_ptr;
381rb_yjit_invalidate_all_method_lookup_assumptions(
void)
389rb_object_shape_count(
void)
392 return ULONG2NUM((
unsigned long)rb_shapes_count());
396rb_yjit_shape_obj_complex_p(
VALUE obj)
398 return rb_obj_shape_complex_p(obj);
402rb_yjit_shape_obj_embedded_p(
VALUE obj)
404 return rb_obj_shape_embedded_p(obj);
408rb_yjit_shape_capacity(shape_id_t shape_id)
410 return RSHAPE_CAPACITY(shape_id);
414rb_yjit_shape_index(shape_id_t shape_id)
416 return RSHAPE_INDEX(shape_id);
421rb_yjit_sendish_sp_pops(
const struct rb_callinfo *ci)
423 return 1 - sp_inc_of_sendish(ci);
428rb_yjit_invokeblock_sp_pops(
const struct rb_callinfo *ci)
430 return 1 - sp_inc_of_invokeblock(ci);
436 return cme->def->body.bmethod.defined_ractor_id;
442rb_yjit_set_exception_return(
rb_control_frame_t *cfp,
void *leave_exit,
void *leave_exception)
444 if (VM_FRAME_FINISHED_P(cfp)) {
446 cfp->jit_return = leave_exit;
448 else if (cfp->jit_return) {
449 while (!VM_FRAME_FINISHED_P(cfp)) {
450 if (cfp->jit_return == leave_exit) {
455 cfp->jit_return = leave_exception;
458 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
464 cfp->jit_return = leave_exception;
472rb_vm_instruction_size(
void)
474 return VM_INSTRUCTION_SIZE;
478yjit_cdhash_all_fixnum_i(st_data_t key, st_data_t _val, st_data_t data)
481 *((
bool *)data) =
false;
488rb_yjit_cdhash_all_fixnum_p(
VALUE cdhash)
490 bool all_fixnum =
true;
491 st_foreach(rb_imemo_cdhash_tbl(cdhash), yjit_cdhash_all_fixnum_i, (st_data_t)&all_fixnum);
496rb_yjit_cdhash_lookup(
VALUE cdhash, st_data_t key, st_data_t *val)
498 return st_lookup(rb_imemo_cdhash_tbl(cdhash), key, val);
522#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.
#define FIXNUM_P
Old name of RB_FIXNUM_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.
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.
static VALUE RSTRUCT_SET(VALUE st, int k, VALUE v)
Resembles Struct#[]=.
#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.