In Files

  • ast.c
  • ast.rb
  • mini_builtin.c
  • vm.c
  • yjit.rb

Files

Class/Module Index [+]

Quicksearch

RubyVM

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.

Constants

DEFAULT_PARAMS

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.

INSTRUCTION_NAMES

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

OPTS

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

Public Class Methods

each_builtin() click to toggle source
 
               static VALUE
each_builtin(VALUE self)
{
    st_foreach(loaded_builtin_table, each_builtin_i, 0);
    return Qnil;
}
            
keep_script_lines → true or false click to toggle source

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.

 
               static VALUE
vm_keep_script_lines(VALUE self)
{
    return RBOOL(ruby_vm_keep_script_lines);
}
            
keep_script_lines = true / false click to toggle source

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.

 
               static VALUE
vm_keep_script_lines_set(VALUE self, VALUE flags)
{
    ruby_vm_keep_script_lines = RTEST(flags);
    return flags;
}
            
mtbl(p1, p2) click to toggle source
 
               static VALUE
vm_mtbl(VALUE self, VALUE obj, VALUE sym)
{
    vm_mtbl_dump(CLASS_OF(obj), RTEST(sym) ? SYM2ID(sym) : 0);
    return Qnil;
}
            
mtbl2(p1, p2) click to toggle source
 
               static VALUE
vm_mtbl2(VALUE self, VALUE obj, VALUE sym)
{
    vm_mtbl_dump(obj, RTEST(sym) ? SYM2ID(sym) : 0);
    return Qnil;
}
            
stat → Hash click to toggle source
stat(hsh) → hsh
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.

 
               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;
}
            
There is an updated format of the API docs for this version here.