Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
|
#include "internal.h"
#include "ruby/vm.h"
#include "ruby/st.h"
#include "gc.h"
#include "vm_core.h"
#include "vm_debug.h"
#include "iseq.h"
#include "eval_intern.h"
#include "builtin.h"
#include "probes.h"
#include "probes_helper.h"
#include "mjit.h"
#include "vm_insnhelper.h"
#include "vm_exec.h"
#include "vm_insnhelper.c"
#include "vm_exec.c"
#include "vm_method.c"
#include "vm_eval.c"
#include "vm_call_iseq_optimized.inc"
Go to the source code of this file.
Macros | |
#define | vm_exec rb_vm_exec |
#define | PROCDEBUG 0 |
#define | ruby_vm_redefined_flag GET_VM()->redefined_flag |
#define | S(s) sym_##s = ID2SYM(rb_intern_const(#s)) |
#define | SET(name, attr) |
#define | OP(mid_, bop_) (mid = id##mid_, bop = BOP_##bop_, ruby_vm_redefined_flag[bop] = 0) |
#define | C(k) add_opt_method(rb_c##k, mid, bop) |
#define | SET(name) rb_hash_aset(result, ID2SYM(rb_intern(#name)), SIZET2NUM(vm->default_params.name)); |
#define | thread_data_type ruby_threadptr_data_type |
#define | REWIND_CFP(expr) |
#define C | ( | k | ) | add_opt_method(rb_c##k, mid, bop) |
#define OP | ( | mid_, | |
bop_ | |||
) | (mid = id##mid_, bop = BOP_##bop_, ruby_vm_redefined_flag[bop] = 0) |
#define REWIND_CFP | ( | expr | ) |
#define S | ( | s | ) | sym_##s = ID2SYM(rb_intern_const(#s)) |
#define SET | ( | name | ) | rb_hash_aset(result, ID2SYM(rb_intern(#name)), SIZET2NUM(vm->default_params.name)); |
#define SET | ( | name, | |
attr | |||
) |
#define thread_data_type ruby_threadptr_data_type |
#define vm_exec rb_vm_exec |
ALWAYS_INLINE | ( | static VALUE | invoke_block_from_c_procrb_execution_context_t *ec, const rb_proc_t *proc, VALUE self, int argc, const VALUE *argv, int kw_splat, VALUE passed_block_handler, int is_lambda, const rb_callable_method_entry_t *me | ) |
ALWAYS_INLINE | ( | static VALUE | invoke_iseq_block_from_crb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE self, int argc, const VALUE *argv, int kw_splat, VALUE passed_block_handler, const rb_cref_t *cref, int is_lambda, const rb_callable_method_entry_t *me | ) |
Definition at line 3303 of file vm.c.
References exit(), EXIT_FAILURE, fprintf(), MEMZERO, ruby_mimmalloc(), and stderr.
Referenced by ruby_setup().
Definition at line 3355 of file vm.c.
References GET_VM, rb_cObject, rb_define_singleton_method(), rb_obj_alloc(), rb_vm_top_self(), and rb_vm_struct::top_self.
Definition at line 2953 of file vm.c.
References CLASS_OF, klass, rb_cObject, rb_cRubyVM, rb_define_class(), rb_define_singleton_method(), rb_undef_alloc_func(), and rb_undef_method().
Definition at line 3326 of file vm.c.
References rb_vm_struct::defined_module_hash, rb_vm_struct::frozen_strings, GET_VM, rb_vm_struct::loading_table, rb_vm_struct::mark_object_ary, rb_vm_struct::objspace, rb_ary_tmp_new(), rb_fstring_hash_type, rb_objspace_gc_enable(), st_init_numtable(), st_init_strtable(), and st_init_table_with_size().
Referenced by ruby_setup().
References rb_insns_name(), RUBY_DTRACE_INSN, and RUBY_DTRACE_INSN_ENABLED.
NORETURN | ( | static void | vm_iter_breakrb_execution_context_t *ec, VALUE val | ) |
PUREFUNC | ( | static inline VALUE | VM_CF_BLOCK_HANDLERconst rb_control_frame_t *const cfp | ) |
Definition at line 1304 of file vm.c.
Referenced by rb_f_global_variables().
Definition at line 1310 of file vm.c.
Referenced by rb_reg_match2().
const VALUE * rb_binding_add_dynavars | ( | VALUE | bindval, |
rb_binding_t * | bind, | ||
int | dyncount, | ||
const ID * | dynvars | ||
) |
Definition at line 984 of file vm.c.
References path, and rb_binding_t::pathobj.
MJIT_FUNC_EXPORTED int rb_dtrace_setup | ( | rb_execution_context_t * | ec, |
VALUE | klass, | ||
ID | id, | ||
struct ruby_dtrace_method_hook_args * | args | ||
) |
Definition at line 392 of file vm.c.
References BUILTIN_TYPE, FALSE, FL_SINGLETON, FL_TEST, GET_EC, id__attached__, klass, name, NIL_P, rb_attr_get(), rb_class_path(), rb_ec_frame_method_id_and_class(), RB_TYPE_P, RBASIC, T_CLASS, T_ICLASS, and T_MODULE.
void rb_ec_clear_vm_stack | ( | rb_execution_context_t * | ec | ) |
Definition at line 2701 of file vm.c.
References rb_execution_context_struct::cfp, NULL, and rb_ec_set_vm_stack().
Referenced by rb_threadptr_root_fiber_terminate().
int rb_ec_frame_method_id_and_class | ( | const rb_execution_context_t * | ec, |
ID * | idp, | ||
ID * | called_idp, | ||
VALUE * | klassp | ||
) |
Definition at line 2200 of file vm.c.
References rb_execution_context_struct::cfp, and rb_vm_control_frame_id_and_class().
Referenced by rb_dtrace_setup(), and rb_frame_method_id_and_class().
void rb_ec_initialize_vm_stack | ( | rb_execution_context_t * | ec, |
VALUE * | stack, | ||
size_t | size | ||
) |
Definition at line 2685 of file vm.c.
References rb_execution_context_struct::cfp, rb_ec_set_vm_stack(), size, rb_execution_context_struct::vm_stack, and rb_execution_context_struct::vm_stack_size.
|
inline |
Definition at line 2678 of file vm.c.
References size, rb_execution_context_struct::vm_stack, and rb_execution_context_struct::vm_stack_size.
Referenced by rb_ec_clear_vm_stack(), and rb_ec_initialize_vm_stack().
void rb_execution_context_mark | ( | const rb_execution_context_t * | ec | ) |
Definition at line 2502 of file vm.c.
References rb_execution_context_struct::cfp, cfp, rb_control_frame_struct::ep, rb_gc_mark_vm_stack_values(), rb_control_frame_struct::sp, VM_ASSERT, rb_execution_context_struct::vm_stack, and rb_execution_context_struct::vm_stack_size.
Referenced by rb_fiber_mark_self().
void rb_execution_context_update | ( | const rb_execution_context_t * | ec | ) |
Definition at line 2474 of file vm.c.
References rb_control_frame_struct::block_code, rb_execution_context_struct::cfp, cfp, rb_control_frame_struct::ep, rb_control_frame_struct::iseq, rb_gc_location(), rb_control_frame_struct::self, VM_ASSERT, rb_execution_context_struct::vm_stack, and rb_execution_context_struct::vm_stack_size.
Referenced by rb_fiber_update_self().
void rb_fiber_mark_self | ( | rb_fiber_t * | fib | ) |
void rb_fiber_update_self | ( | rb_fiber_t * | fib | ) |
Definition at line 960 of file cont.c.
References rb_fiber_struct::cont, rb_execution_context_update(), rb_gc_location(), rb_context_struct::saved_ec, and rb_context_struct::self.
Definition at line 2206 of file vm.c.
References GET_EC, and rb_ec_frame_method_id_and_class().
VALUE rb_insn_operand_intern | ( | const rb_iseq_t * | iseq, |
VALUE | insn, | ||
int | op_no, | ||
VALUE | op, | ||
int | len, | ||
size_t | pos, | ||
VALUE * | pnop, | ||
VALUE | child | ||
) |
Definition at line 1316 of file vm.c.
Referenced by rb_io_print(), and rb_reg_match2().
rb_serial_t rb_next_class_serial | ( | void | ) |
Definition at line 358 of file vm.c.
References mjit_add_class_serial(), and NEXT_CLASS_SERIAL.
Definition at line 2657 of file vm.c.
References obj, Qfalse, Qtrue, rb_typeddata_is_kind_of(), and thread_data_type.
Definition at line 920 of file vm.c.
References GetProcPtr, and src.
Definition at line 1360 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, and rb_vm_get_ruby_level_next_cfp().
Referenced by rb_source_location_cstr().
MJIT_FUNC_EXPORTED const char * rb_source_location_cstr | ( | int * | pline | ) |
Definition at line 1376 of file vm.c.
References NIL_P, NULL, path, rb_source_location(), and RSTRING_PTR.
Referenced by rb_bug(), rb_bug_for_fatal_signal(), and rb_set_safe_level().
Definition at line 1331 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, rb_control_frame_struct::iseq, rb_iseq_path(), rb_vm_get_ruby_level_next_cfp(), and RSTRING_PTR.
Definition at line 1346 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, rb_vm_get_ruby_level_next_cfp(), and rb_vm_get_sourceline().
void rb_threadptr_root_fiber_release | ( | rb_thread_t * | th | ) |
Definition at line 1894 of file cont.c.
References rb_fiber_struct::cont, rb_thread_struct::ec, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, rb_thread_struct::root_fiber, rb_context_struct::self, rb_context_struct::type, and VM_ASSERT.
void rb_threadptr_root_fiber_setup | ( | rb_thread_t * | th | ) |
Definition at line 1879 of file cont.c.
References rb_fiber_struct::cont, errno, FIBER_CONTEXT, rb_execution_context_struct::fiber_ptr, MEMZERO, rb_bug(), ruby_mimmalloc(), rb_context_struct::saved_ec, strerror(), rb_execution_context_struct::thread_ptr, and rb_context_struct::type.
Definition at line 2312 of file vm.c.
References rb_vm_struct::defined_module_hash, GET_VM, st_insert(), and TRUE.
Referenced by rb_define_class(), rb_define_class_id_under(), and rb_define_module().
Definition at line 315 of file vm.c.
References rb_block::as, rb_block::captured, rb_captured_block::ep, obj, Qundef, and RB_OBJ_WRITTEN.
VALUE rb_vm_call_cfunc | ( | VALUE | recv, |
VALUE(*)(VALUE) | func, | ||
VALUE | arg, | ||
VALUE | block_handler, | ||
VALUE | filename | ||
) |
Definition at line 2212 of file vm.c.
References rb_execution_context_struct::cfp, GET_EC, iseq, Qnil, rb_iseq_new(), and reg_cfp.
Definition at line 1425 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, rb_eRuntimeError, rb_raise(), and rb_vm_get_ruby_level_next_cfp().
int rb_vm_cframe_empty_keyword_p | ( | const rb_control_frame_t * | cfp | ) |
Definition at line 109 of file vm.c.
Referenced by rb_empty_keyword_given_p().
int rb_vm_cframe_keyword_p | ( | const rb_control_frame_t * | cfp | ) |
Definition at line 102 of file vm.c.
Referenced by rb_keyword_given_p().
int rb_vm_control_frame_id_and_class | ( | const rb_control_frame_t * | cfp, |
ID * | idp, | ||
ID * | called_idp, | ||
VALUE * | klassp | ||
) |
Definition at line 2184 of file vm.c.
References me.
Referenced by rb_ec_frame_method_id_and_class().
Definition at line 1400 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, NULL, rb_vm_get_ruby_level_next_cfp(), and rb_control_frame_struct::self.
Referenced by rb_attr().
Definition at line 1391 of file vm.c.
References rb_execution_context_struct::cfp, cfp, GET_EC, and rb_vm_get_ruby_level_next_cfp().
VALUE rb_vm_frame_block_handler | ( | const rb_control_frame_t * | cfp | ) |
Definition at line 3394 of file vm.c.
References GET_VM.
Referenced by Init_String(), and rb_str_free().
rb_control_frame_t * rb_vm_get_binding_creatable_next_cfp | ( | const rb_execution_context_t * | ec, |
const rb_control_frame_t * | cfp | ||
) |
Definition at line 541 of file vm.c.
Referenced by rb_tracearg_binding(), rb_vm_make_binding(), and rb_vm_stack_to_heap().
MJIT_FUNC_EXPORTED rb_control_frame_t * rb_vm_get_ruby_level_next_cfp | ( | const rb_execution_context_t * | ec, |
const rb_control_frame_t * | cfp | ||
) |
Definition at line 553 of file vm.c.
Referenced by rb_source_location(), rb_sourcefile(), rb_sourceline(), rb_tracearg_parameters(), rb_vm_cbase(), rb_vm_cref_in_context(), rb_vm_cref_replace_with_duplicated_cref(), and rb_vm_make_binding().
Definition at line 386 of file vm.c.
References ruby_vm_const_missing_count.
Referenced by rb_const_missing().
MJIT_FUNC_EXPORTED VALUE rb_vm_invoke_proc | ( | rb_execution_context_t * | ec, |
rb_proc_t * | proc, | ||
int | argc, | ||
const VALUE * | argv, | ||
int | kw_splat, | ||
VALUE | passed_block_handler | ||
) |
Definition at line 1249 of file vm.c.
Referenced by rb_fiber_start(), rb_proc_call(), rb_proc_call_kw(), rb_proc_call_with_block(), and rb_proc_call_with_block_kw().
Definition at line 1510 of file vm.c.
References EC_JUMP_TAG, exc, GET_EC, NIL_P, Qundef, rb_exc_raise(), and rb_vm_make_jump_tag_but_local_jump().
VALUE rb_vm_make_binding | ( | const rb_execution_context_t * | ec, |
const rb_control_frame_t * | src_cfp | ||
) |
Definition at line 953 of file vm.c.
References cfp, rb_eRuntimeError, rb_raise(), rb_vm_get_binding_creatable_next_cfp(), and rb_vm_get_ruby_level_next_cfp().
Referenced by rb_binding_new(), and rb_tracearg_binding().
Definition at line 1478 of file vm.c.
References GET_EC, Qnil, Qundef, TAG_BREAK, TAG_NEXT, TAG_REDO, TAG_RETRY, and TAG_RETURN.
Referenced by rb_fiber_start(), and rb_vm_jump_tag_but_local_jump().
MJIT_FUNC_EXPORTED VALUE rb_vm_make_proc_lambda | ( | const rb_execution_context_t * | ec, |
const struct rb_captured_block * | captured, | ||
VALUE | klass, | ||
int8_t | is_lambda | ||
) |
Definition at line 2243 of file vm.c.
References rb_vm_struct::cmd, rb_vm_struct::coverages, rb_vm_struct::defined_module_hash, rb_vm_struct::expanded_load_path, rb_vm_struct::global_hooks, i, len, list_for_each, rb_vm_struct::living_threads, rb_vm_struct::load_path, rb_vm_struct::load_path_check_cache, rb_vm_struct::load_path_snapshot, rb_vm_struct::loaded_features, rb_vm_struct::loaded_features_snapshot, rb_vm_struct::loading_table, rb_vm_struct::mark_object_ary, mjit_mark(), rb_vm_struct::orig_progname, ptr, RARRAY_CONST_PTR, RARRAY_LEN, rb_gc_mark(), rb_gc_mark_values(), rb_hook_list_mark(), rb_mark_tbl(), RUBY_GC_INFO, RUBY_MARK_ENTER, RUBY_MARK_LEAVE, RUBY_MARK_UNLESS_NULL, RUBY_NSIG, rb_thread_struct::self, rb_vm_struct::thgroup_default, rb_vm_struct::top_self, and rb_vm_struct::trap_list.
MJIT_STATIC void rb_vm_pop_cfunc_frame | ( | void | ) |
void rb_vm_register_special_exception_str | ( | enum ruby_special_exceptions | sp, |
VALUE | cls, | ||
VALUE | mesg | ||
) |
Definition at line 2302 of file vm.c.
References exc, GET_VM, OBJ_FREEZE, rb_exc_new3, rb_gc_register_mark_object(), rb_obj_freeze(), and rb_vm_struct::special_exceptions.
void rb_vm_rewind_cfp | ( | rb_execution_context_t * | ec, |
rb_control_frame_t * | cfp | ||
) |
Definition at line 604 of file vm.c.
References rb_execution_context_struct::cfp, cfp, and printf().
Definition at line 3291 of file vm.c.
References cfp, rb_thread_struct::ec, GET_VM, rb_control_frame_struct::iseq, rb_iseq_pathobj_set(), rb_iseq_realpath(), rb_str_dup(), rb_execution_context_struct::vm_stack, and rb_execution_context_struct::vm_stack_size.
Referenced by ruby_set_script_name().
void rb_vm_stack_to_heap | ( | rb_execution_context_t * | ec | ) |
Definition at line 786 of file vm.c.
References rb_execution_context_struct::cfp, cfp, and rb_vm_get_binding_creatable_next_cfp().
Definition at line 3349 of file vm.c.
References GET_VM.
Referenced by Init_top_self(), and rb_eval_string_wrap().
Definition at line 2234 of file vm.c.
References rb_vm_struct::frozen_strings, ptr, and rb_gc_update_tbl_refs().
ruby_vm_at_exit registers a function func to be invoked when a VM passed away.
Functions registered this way runs in reverse order of registration, just like END {} block does. The difference is its timing to be triggered. ruby_vm_at_exit functions runs when a VM passed away, while END {} blocks runs just before a VM is passing away.
You cannot register a function to another VM than where you are in. So where to register is intuitive, omitted. OTOH the argument func cannot know which VM it is in because at the time of invocation, the VM has already died and there is no execution context. The VM itself is passed as the first argument to it.
[in] | func | the function to register. |
Definition at line 623 of file vm.c.
References ALLOC, rb_vm_struct::at_exit, rb_at_exit_list::func, GET_VM, and rb_at_exit_list::next.
Definition at line 2329 of file vm.c.
References rb_vm_struct::main_thread, rb_vm_struct::objspace, rb_fiber_reset_root_local_storage(), and RUBY_FREE_ENTER.
VALUE vm_exec | ( | rb_execution_context_t * | ec, |
int | mjit_enable_p | ||
) |
|
extern |
Definition at line 260 of file string.c.
Referenced by Init_vm_objects().
|
extern |
|
extern |
rb_execution_context_t* ruby_current_execution_context_ptr = NULL |
const rb_data_type_t ruby_threadptr_data_type |
rb_serial_t ruby_vm_class_serial = 1 |
VALUE ruby_vm_const_missing_count = 0 |
Definition at line 371 of file vm.c.
Referenced by rb_vm_inc_const_missing_count().
rb_event_flag_t ruby_vm_event_enabled_global_flags |
rb_event_flag_t ruby_vm_event_flags |
rb_serial_t ruby_vm_global_constant_state = 1 |
rb_serial_t ruby_vm_global_method_state = 1 |