123456789_123456789_123456789_123456789_123456789_

Class: RubyVM

Relationships & Source Files
Namespace Children
Modules:
Classes:
Inherits: Object
Defined in: vm.c,
mini_builtin.c

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.

Constant Summary

  • 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.

    # File 'vm.c', line 3720
    :
  • INSTRUCTION_NAMES =

    A list of bytecode instruction names in MRI. This constant is MRI specific.

    # File 'vm.c', line 3712
    :
  • OPTS =

    An Array of VM build options. This constant is MRI specific.

    # File 'vm.c', line 3682
    :

Class Attribute Summary

Class Method Summary

Class Attribute Details

.keep_script_linesBoolean (rw)

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.

[ GitHub ]

  
# File 'vm.c', line 3408

static VALUE
vm_keep_script_lines(VALUE self)
{
    return RBOOL(ruby_vm_keep_script_lines);
}

.keep_script_lines=(true / false) (rw)

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.

[ GitHub ]

  
# File 'vm.c', line 3425

static VALUE
vm_keep_script_lines_set(VALUE self, VALUE flags)
{
    ruby_vm_keep_script_lines = RTEST(flags);
    return flags;
}

Class Method Details

.each_builtin

[ GitHub ]

  
# File 'mini_builtin.c', line 77

static VALUE
each_builtin(VALUE self)
{
    st_foreach(loaded_builtin_table, each_builtin_i, 0);
    return Qnil;
}

.mtbl(obj, sym)

[ GitHub ]

  
# File 'vm.c', line 3383

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)

[ GitHub ]

  
# File 'vm.c', line 3390

static VALUE
vm_mtbl2(VALUE self, VALUE obj, VALUE sym)
{
    vm_mtbl_dump(obj, RTEST(sym) ? SYM2ID(sym) : 0);
    return Qnil;
}

NSDR

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 3320

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

[ GitHub ]

SDR

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 3312

static VALUE
sdr(VALUE self)
{
    rb_vm_bugreport(NULL);
    return Qnil;
}

.show_debug_counters

[ GitHub ]

.statHash .stat(hsh) ⇒ Hash .stat(Symbol) ⇒ Numeric

Returns a ::Hash containing implementation-dependent counters inside the VM.

This hash includes information about method/constant cache serials:

{
  :global_constant_state=>481,
  :class_serial=>9029
}

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.

[ GitHub ]

  
# File 'vm.c', line 520

static VALUE
vm_stat(int argc, VALUE *argv, VALUE self)
{
    static VALUE sym_global_constant_state, sym_class_serial, sym_global_cvar_state;
    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();
    }

    if (sym_global_constant_state == 0) {
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
	S(global_constant_state);
	S(class_serial);
	S(global_cvar_state);
#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(global_constant_state, ruby_vm_global_constant_state);
    SET(class_serial, ruby_vm_class_serial);
    SET(global_cvar_state, ruby_vm_global_cvar_state);
#undef SET

    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

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4099

static VALUE
usage_analysis_insn_clear(VALUE self)
{
  ID usage_hash;
  ID bigram_hash;
  VALUE uh;
  VALUE bh;

  CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
  CONST_ID(bigram_hash, "USAGE_ANALYSIS_INSN_BIGRAM");
  uh = rb_const_get(rb_cRubyVM, usage_hash);
  bh = rb_const_get(rb_cRubyVM, bigram_hash);
  rb_hash_clear(uh);
  rb_hash_clear(bh);

  return Qtrue;
}

USAGE_ANALYSIS_INSN_RUNNING

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4078

static VALUE
usage_analysis_insn_running(VALUE self)
{
  return RBOOL(ruby_vm_collect_usage_func_insn != 0);
}

USAGE_ANALYSIS_INSN_START

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4030

static VALUE
usage_analysis_insn_start(VALUE self)
{
    ruby_vm_collect_usage_func_insn = vm_analysis_insn;
    return Qnil;
}

USAGE_ANALYSIS_INSN_STOP

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4054

static VALUE
usage_analysis_insn_stop(VALUE self)
{
    ruby_vm_collect_usage_func_insn = 0;
    return Qnil;
}

USAGE_ANALYSIS_OPERAND_CLEAR

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4118

static VALUE
usage_analysis_operand_clear(VALUE self)
{
  ID usage_hash;
  VALUE uh;

  CONST_ID(usage_hash, "USAGE_ANALYSIS_INSN");
  uh = rb_const_get(rb_cRubyVM, usage_hash);
  rb_hash_clear(uh);

  return Qtrue;
}

USAGE_ANALYSIS_OPERAND_RUNNING

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4085

static VALUE
usage_analysis_operand_running(VALUE self)
{
  return RBOOL(ruby_vm_collect_usage_func_operand != 0);
}

USAGE_ANALYSIS_OPERAND_START

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4038

static VALUE
usage_analysis_operand_start(VALUE self)
{
    ruby_vm_collect_usage_func_operand = vm_analysis_operand;
    return Qnil;
}

USAGE_ANALYSIS_OPERAND_STOP

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4062

static VALUE
usage_analysis_operand_stop(VALUE self)
{
    ruby_vm_collect_usage_func_operand = 0;
    return Qnil;
}

USAGE_ANALYSIS_REGISTER_CLEAR

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4132

static VALUE
usage_analysis_register_clear(VALUE self)
{
  ID usage_hash;
  VALUE uh;

  CONST_ID(usage_hash, "USAGE_ANALYSIS_REGS");
  uh = rb_const_get(rb_cRubyVM, usage_hash);
  rb_hash_clear(uh);

  return Qtrue;
}

USAGE_ANALYSIS_REGISTER_RUNNING

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4092

static VALUE
usage_analysis_register_running(VALUE self)
{
  return RBOOL(ruby_vm_collect_usage_func_register != 0);
}

USAGE_ANALYSIS_REGISTER_START

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4046

static VALUE
usage_analysis_register_start(VALUE self)
{
    ruby_vm_collect_usage_func_register = vm_analysis_register;
    return Qnil;
}

USAGE_ANALYSIS_REGISTER_STOP

This method is for internal use only.
[ GitHub ]

  
# File 'vm.c', line 4070

static VALUE
usage_analysis_register_stop(VALUE self)
{
    ruby_vm_collect_usage_func_register = 0;
    return Qnil;
}