Class: RubyVM

Inherits:
Object show all
Defined in:
vm.c,
vm.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.

Defined Under Namespace

Modules: AbstractSyntaxTree, MJIT Classes: InstructionSequence

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

Class Method Details

.each_builtinObject



63
64
65
66
67
68
# File 'mini_builtin.c', line 63

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

.NSDRObject

:nodoc:



2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
# File 'vm.c', line 2893

static VALUE
nsdr(VALUE self)
{
    VALUE ary = rb_ary_new();
#if 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_countersObject

.SDRObject

:nodoc:



2885
2886
2887
2888
2889
2890
# File 'vm.c', line 2885

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

.show_debug_countersObject

.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_method_state=>251,
  :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.

Overloads:



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'vm.c', line 449

static VALUE
vm_stat(int argc, VALUE *argv, VALUE self)
{
    static VALUE sym_global_method_state, sym_global_constant_state, sym_class_serial;
    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_method_state == 0) {
#define S(s) sym_##s = ID2SYM(rb_intern_const(#s))
	S(global_method_state);
	S(global_constant_state);
	S(class_serial);
#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_method_state, ruby_vm_global_method_state);
    SET(global_constant_state, ruby_vm_global_constant_state);
    SET(class_serial, ruby_vm_class_serial);
#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_CLEARObject



2927
# File 'vm.c', line 2927

static VALUE usage_analysis_insn_clear(VALUE self);

.USAGE_ANALYSIS_INSN_RUNNINGObject



2924
# File 'vm.c', line 2924

static VALUE usage_analysis_insn_running(VALUE self);

.USAGE_ANALYSIS_INSN_STARTObject



2918
# File 'vm.c', line 2918

static VALUE usage_analysis_insn_start(VALUE self);

.USAGE_ANALYSIS_INSN_STOPObject



2921
# File 'vm.c', line 2921

static VALUE usage_analysis_insn_stop(VALUE self);

.USAGE_ANALYSIS_OPERAND_CLEARObject



2928
# File 'vm.c', line 2928

static VALUE usage_analysis_operand_clear(VALUE self);

.USAGE_ANALYSIS_OPERAND_RUNNINGObject



2925
# File 'vm.c', line 2925

static VALUE usage_analysis_operand_running(VALUE self);

.USAGE_ANALYSIS_OPERAND_STARTObject



2919
# File 'vm.c', line 2919

static VALUE usage_analysis_operand_start(VALUE self);

.USAGE_ANALYSIS_OPERAND_STOPObject



2922
# File 'vm.c', line 2922

static VALUE usage_analysis_operand_stop(VALUE self);

.USAGE_ANALYSIS_REGISTER_CLEARObject



2929
# File 'vm.c', line 2929

static VALUE usage_analysis_register_clear(VALUE self);

.USAGE_ANALYSIS_REGISTER_RUNNINGObject



2926
# File 'vm.c', line 2926

static VALUE usage_analysis_register_running(VALUE self);

.USAGE_ANALYSIS_REGISTER_STARTObject



2920
# File 'vm.c', line 2920

static VALUE usage_analysis_register_start(VALUE self);

.USAGE_ANALYSIS_REGISTER_STOPObject



2923
# File 'vm.c', line 2923

static VALUE usage_analysis_register_stop(VALUE self);