Class: RubyVM
Overview
The RubyVM module only exists on MRI. RubyVM
is not defined in other Ruby implementations such as JRuby and TruffleRuby.
The RubyVM module provides some access to MRI internals. This module is for very limited purposes, such as debugging, prototyping, and research. Normal users must not use it. This module is not portable between Ruby implementations.
Defined Under Namespace
Modules: AbstractSyntaxTree Classes: InstructionSequence, Shape
Constant Summary collapse
- OPTS =
RubyVM::OPTS An Array of VM build options. This constant is MRI specific.
:
- INSTRUCTION_NAMES =
RubyVM::INSTRUCTION_NAMES A list of bytecode instruction names in MRI. This constant is MRI specific.
:
- DEFAULT_PARAMS =
RubyVM::DEFAULT_PARAMS This constant exposes the VM’s default parameters. Note that changing these values does not affect VM execution. Specification is not stable and you should not depend on this value. Of course, this constant is MRI specific.
:
Class Method Summary collapse
-
.each_builtin ⇒ Object
:nodoc:.
-
.keep_script_lines ⇒ Boolean
Return current
keep_script_lines
status. -
.keep_script_lines=(true) ⇒ Object
It set
keep_script_lines
flag. -
.mtbl(obj, sym) ⇒ Object
:nodoc:.
-
.mtbl2(obj, sym) ⇒ Object
:nodoc:.
-
.NSDR ⇒ Object
:nodoc:.
- .reset_debug_counters ⇒ Object
-
.SDR ⇒ Object
:nodoc:.
- .show_debug_counters ⇒ Object
-
.stat(*args) ⇒ Object
Returns a Hash containing implementation-dependent counters inside the VM.
- .USAGE_ANALYSIS_INSN_CLEAR ⇒ Object
- .USAGE_ANALYSIS_INSN_RUNNING ⇒ Object
- .USAGE_ANALYSIS_INSN_START ⇒ Object
- .USAGE_ANALYSIS_INSN_STOP ⇒ Object
- .USAGE_ANALYSIS_OPERAND_CLEAR ⇒ Object
- .USAGE_ANALYSIS_OPERAND_RUNNING ⇒ Object
- .USAGE_ANALYSIS_OPERAND_START ⇒ Object
- .USAGE_ANALYSIS_OPERAND_STOP ⇒ Object
- .USAGE_ANALYSIS_REGISTER_CLEAR ⇒ Object
- .USAGE_ANALYSIS_REGISTER_RUNNING ⇒ Object
- .USAGE_ANALYSIS_REGISTER_START ⇒ Object
- .USAGE_ANALYSIS_REGISTER_STOP ⇒ Object
Class Method Details
.each_builtin ⇒ Object
:nodoc:
83 84 85 86 87 88 |
# File 'miniinit.c', line 83
static VALUE
each_builtin(VALUE self)
{
st_foreach(loaded_builtin_table, each_builtin_i, 0);
return Qnil;
}
|
.keep_script_lines ⇒ Boolean
Return current keep_script_lines
status. Now it only returns true
of false
, but it can return other objects in future.
Note that this is an API for ruby internal use, debugging, and research. Do not use this for any other purpose. The compatibility is not guaranteed.
3899 3900 3901 3902 3903 |
# File 'vm.c', line 3899
static VALUE
vm_keep_script_lines(VALUE self)
{
return RBOOL(ruby_vm_keep_script_lines);
}
|
.keep_script_lines=(true) ⇒ Object
It set keep_script_lines
flag. If the flag is set, all loaded scripts are recorded in a interpreter process.
Note that this is an API for ruby internal use, debugging, and research. Do not use this for any other purpose. The compatibility is not guaranteed.
3916 3917 3918 3919 3920 3921 |
# File 'vm.c', line 3916
static VALUE
vm_keep_script_lines_set(VALUE self, VALUE flags)
{
ruby_vm_keep_script_lines = RTEST(flags);
return flags;
}
|
.mtbl(obj, sym) ⇒ Object
:nodoc:
3873 3874 3875 3876 3877 3878 |
# File 'vm.c', line 3873
static VALUE
vm_mtbl(VALUE self, VALUE obj, VALUE sym)
{
vm_mtbl_dump(CLASS_OF(obj), RTEST(sym) ? SYM2ID(sym) : 0);
return Qnil;
}
|
.mtbl2(obj, sym) ⇒ Object
:nodoc:
3881 3882 3883 3884 3885 3886 |
# File 'vm.c', line 3881
static VALUE
vm_mtbl2(VALUE self, VALUE obj, VALUE sym)
{
vm_mtbl_dump(obj, RTEST(sym) ? SYM2ID(sym) : 0);
return Qnil;
}
|
.NSDR ⇒ Object
:nodoc:
3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 |
# File 'vm.c', line 3809
static VALUE
nsdr(VALUE self)
{
VALUE ary = rb_ary_new();
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#define MAX_NATIVE_TRACE 1024
static void *trace[MAX_NATIVE_TRACE];
int n = (int)backtrace(trace, MAX_NATIVE_TRACE);
char **syms = backtrace_symbols(trace, n);
int i;
if (syms == 0) {
rb_memerror();
}
for (i=0; i<n; i++) {
rb_ary_push(ary, rb_str_new2(syms[i]));
}
free(syms); /* OK */
#endif
return ary;
}
|
.reset_debug_counters ⇒ Object
.SDR ⇒ Object
:nodoc:
3801 3802 3803 3804 3805 3806 |
# File 'vm.c', line 3801
static VALUE
sdr(VALUE self)
{
rb_vm_bugreport(NULL, stderr);
return Qnil;
}
|
.show_debug_counters ⇒ Object
.stat ⇒ Hash .stat(hsh) ⇒ Hash .stat(Symbol) ⇒ Numeric
Returns a Hash containing implementation-dependent counters inside the VM.
This hash includes information about method/constant caches:
{
:constant_cache_invalidations=>2,
:constant_cache_misses=>14,
:global_cvar_state=>27
}
If USE_DEBUG_COUNTER
is enabled, debug counters will be included.
The contents of the hash are implementation specific and may be changed in the future.
This method is only expected to work on C Ruby.
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
# File 'vm.c', line 691
static VALUE
vm_stat(int argc, VALUE *argv, VALUE self)
{
static VALUE sym_constant_cache_invalidations, sym_constant_cache_misses, sym_global_cvar_state, sym_next_shape_id;
static VALUE sym_shape_cache_size;
VALUE arg = Qnil;
VALUE hash = Qnil, key = Qnil;
if (rb_check_arity(argc, 0, 1) == 1) {
arg = argv[0];
if (SYMBOL_P(arg))
key = arg;
else if (RB_TYPE_P(arg, T_HASH))
hash = arg;
else
rb_raise(rb_eTypeError, "non-hash or symbol given");
}
else {
hash = rb_hash_new();
}
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
S(constant_cache_invalidations);
S(constant_cache_misses);
S(global_cvar_state);
S(next_shape_id);
S(shape_cache_size);
#undef S
#define SET(name, attr) \
if (key == sym_##name) \
return SERIALT2NUM(attr); \
else if (hash != Qnil) \
rb_hash_aset(hash, sym_##name, SERIALT2NUM(attr));
SET(constant_cache_invalidations, ruby_vm_constant_cache_invalidations);
SET(constant_cache_misses, ruby_vm_constant_cache_misses);
SET(global_cvar_state, ruby_vm_global_cvar_state);
SET(next_shape_id, (rb_serial_t)GET_SHAPE_TREE()->next_shape_id);
SET(shape_cache_size, (rb_serial_t)GET_SHAPE_TREE()->cache_size);
#undef SET
#if USE_DEBUG_COUNTER
ruby_debug_counter_show_at_exit(FALSE);
for (size_t i = 0; i < RB_DEBUG_COUNTER_MAX; i++) {
const VALUE name = rb_sym_intern_ascii_cstr(rb_debug_counter_names[i]);
const VALUE boxed_value = SIZET2NUM(rb_debug_counter[i]);
if (key == name) {
return boxed_value;
}
else if (hash != Qnil) {
rb_hash_aset(hash, name, boxed_value);
}
}
#endif
if (!NIL_P(key)) { /* matched key should return above */
rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key));
}
return hash;
}
|
.USAGE_ANALYSIS_INSN_CLEAR ⇒ Object
3843 |
# File 'vm.c', line 3843 static VALUE usage_analysis_insn_clear(VALUE self); |
.USAGE_ANALYSIS_INSN_RUNNING ⇒ Object
3840 |
# File 'vm.c', line 3840 static VALUE usage_analysis_insn_running(VALUE self); |
.USAGE_ANALYSIS_INSN_START ⇒ Object
3834 |
# File 'vm.c', line 3834 static VALUE usage_analysis_insn_start(VALUE self); |
.USAGE_ANALYSIS_INSN_STOP ⇒ Object
3837 |
# File 'vm.c', line 3837 static VALUE usage_analysis_insn_stop(VALUE self); |
.USAGE_ANALYSIS_OPERAND_CLEAR ⇒ Object
3844 |
# File 'vm.c', line 3844 static VALUE usage_analysis_operand_clear(VALUE self); |
.USAGE_ANALYSIS_OPERAND_RUNNING ⇒ Object
3841 |
# File 'vm.c', line 3841 static VALUE usage_analysis_operand_running(VALUE self); |
.USAGE_ANALYSIS_OPERAND_START ⇒ Object
3835 |
# File 'vm.c', line 3835 static VALUE usage_analysis_operand_start(VALUE self); |
.USAGE_ANALYSIS_OPERAND_STOP ⇒ Object
3838 |
# File 'vm.c', line 3838 static VALUE usage_analysis_operand_stop(VALUE self); |
.USAGE_ANALYSIS_REGISTER_CLEAR ⇒ Object
3845 |
# File 'vm.c', line 3845 static VALUE usage_analysis_register_clear(VALUE self); |
.USAGE_ANALYSIS_REGISTER_RUNNING ⇒ Object
3842 |
# File 'vm.c', line 3842 static VALUE usage_analysis_register_running(VALUE self); |
.USAGE_ANALYSIS_REGISTER_START ⇒ Object
3836 |
# File 'vm.c', line 3836 static VALUE usage_analysis_register_start(VALUE self); |
.USAGE_ANALYSIS_REGISTER_STOP ⇒ Object
3839 |
# File 'vm.c', line 3839 static VALUE usage_analysis_register_stop(VALUE self); |