Ruby 1.9.3p327(2012-11-10revision37606)
vm_core.h
Go to the documentation of this file.
00001 /**********************************************************************
00002 
00003   vm_core.h -
00004 
00005   $Author: naruse $
00006   created at: 04/01/01 19:41:38 JST
00007 
00008   Copyright (C) 2004-2007 Koichi Sasada
00009 
00010 **********************************************************************/
00011 
00012 #ifndef RUBY_VM_CORE_H
00013 #define RUBY_VM_CORE_H
00014 
00015 #define RUBY_VM_THREAD_MODEL 2
00016 
00017 #include "ruby/ruby.h"
00018 #include "ruby/st.h"
00019 
00020 #include "node.h"
00021 #include "debug.h"
00022 #include "vm_opts.h"
00023 #include "id.h"
00024 #include "method.h"
00025 #include "atomic.h"
00026 
00027 #if   defined(_WIN32)
00028 #include "thread_win32.h"
00029 #elif defined(HAVE_PTHREAD_H)
00030 #include "thread_pthread.h"
00031 #else
00032 #error "unsupported thread type"
00033 #endif
00034 
00035 #ifndef ENABLE_VM_OBJSPACE
00036 #ifdef _WIN32
00037 /*
00038  * TODO: object space independent st_table.
00039  * socklist needs st_table in rb_w32_sysinit(), before object space
00040  * initialization.
00041  * It is too early now to change st_hash_type, since it breaks binary
00042  * compatibility.
00043  */
00044 #define ENABLE_VM_OBJSPACE 0
00045 #else
00046 #define ENABLE_VM_OBJSPACE 1
00047 #endif
00048 #endif
00049 
00050 #include <setjmp.h>
00051 #include <signal.h>
00052 
00053 #ifndef NSIG
00054 # define NSIG (_SIGMAX + 1)      /* For QNX */
00055 #endif
00056 
00057 #define RUBY_NSIG NSIG
00058 
00059 #ifdef HAVE_STDARG_PROTOTYPES
00060 #include <stdarg.h>
00061 #define va_init_list(a,b) va_start((a),(b))
00062 #else
00063 #include <varargs.h>
00064 #define va_init_list(a,b) va_start((a))
00065 #endif
00066 
00067 #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
00068 #define USE_SIGALTSTACK
00069 #endif
00070 
00071 /*****************/
00072 /* configuration */
00073 /*****************/
00074 
00075 /* gcc ver. check */
00076 #if defined(__GNUC__) && __GNUC__ >= 2
00077 
00078 #if OPT_TOKEN_THREADED_CODE
00079 #if OPT_DIRECT_THREADED_CODE
00080 #undef OPT_DIRECT_THREADED_CODE
00081 #endif
00082 #endif
00083 
00084 #else /* defined(__GNUC__) && __GNUC__ >= 2 */
00085 
00086 /* disable threaded code options */
00087 #if OPT_DIRECT_THREADED_CODE
00088 #undef OPT_DIRECT_THREADED_CODE
00089 #endif
00090 #if OPT_TOKEN_THREADED_CODE
00091 #undef OPT_TOKEN_THREADED_CODE
00092 #endif
00093 #endif
00094 
00095 /* call threaded code */
00096 #if    OPT_CALL_THREADED_CODE
00097 #if    OPT_DIRECT_THREADED_CODE
00098 #undef OPT_DIRECT_THREADED_CODE
00099 #endif /* OPT_DIRECT_THREADED_CODE */
00100 #if    OPT_STACK_CACHING
00101 #undef OPT_STACK_CACHING
00102 #endif /* OPT_STACK_CACHING */
00103 #endif /* OPT_CALL_THREADED_CODE */
00104 
00105 /* likely */
00106 #if __GNUC__ >= 3
00107 #define LIKELY(x)   (__builtin_expect((x), 1))
00108 #define UNLIKELY(x) (__builtin_expect((x), 0))
00109 #else /* __GNUC__ >= 3 */
00110 #define LIKELY(x)   (x)
00111 #define UNLIKELY(x) (x)
00112 #endif /* __GNUC__ >= 3 */
00113 
00114 #if __GNUC__ >= 3
00115 #define UNINITIALIZED_VAR(x) x = x
00116 #else
00117 #define UNINITIALIZED_VAR(x) x
00118 #endif
00119 
00120 typedef unsigned long rb_num_t;
00121 
00122 /* iseq data type */
00123 
00124 struct iseq_compile_data_ensure_node_stack;
00125 
00126 typedef struct rb_compile_option_struct rb_compile_option_t;
00127 
00128 struct iseq_inline_cache_entry {
00129     VALUE ic_vmstat;
00130     VALUE ic_class;
00131     union {
00132         VALUE value;
00133         rb_method_entry_t *method;
00134         long index;
00135     } ic_value;
00136 };
00137 
00138 #if 1
00139 #define GetCoreDataFromValue(obj, type, ptr) do { \
00140     (ptr) = (type*)DATA_PTR(obj); \
00141 } while (0)
00142 #else
00143 #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
00144 #endif
00145 
00146 #define GetISeqPtr(obj, ptr) \
00147   GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
00148 
00149 struct rb_iseq_struct;
00150 
00151 struct rb_iseq_struct {
00152     /***************/
00153     /* static data */
00154     /***************/
00155 
00156     enum iseq_type {
00157         ISEQ_TYPE_TOP,
00158         ISEQ_TYPE_METHOD,
00159         ISEQ_TYPE_BLOCK,
00160         ISEQ_TYPE_CLASS,
00161         ISEQ_TYPE_RESCUE,
00162         ISEQ_TYPE_ENSURE,
00163         ISEQ_TYPE_EVAL,
00164         ISEQ_TYPE_MAIN,
00165         ISEQ_TYPE_DEFINED_GUARD
00166     } type;              /* instruction sequence type */
00167 
00168     VALUE name;          /* String: iseq name */
00169     VALUE filename;      /* file information where this sequence from */
00170     VALUE filepath;      /* real file path or nil */
00171     VALUE *iseq;         /* iseq (insn number and operands) */
00172     VALUE *iseq_encoded; /* encoded iseq */
00173     unsigned long iseq_size;
00174     VALUE mark_ary;     /* Array: includes operands which should be GC marked */
00175     VALUE coverage;     /* coverage array */
00176     unsigned short line_no;
00177 
00178     /* insn info, must be freed */
00179     struct iseq_insn_info_entry *insn_info_table;
00180     size_t insn_info_size;
00181 
00182     ID *local_table;            /* must free */
00183     int local_table_size;
00184 
00185     /* method, class frame: sizeof(vars) + 1, block frame: sizeof(vars) */
00186     int local_size;
00187 
00188     struct iseq_inline_cache_entry *ic_entries;
00189     int ic_size;
00190 
00214     int argc;
00215     int arg_simple;
00216     int arg_rest;
00217     int arg_block;
00218     int arg_opts;
00219     int arg_post_len;
00220     int arg_post_start;
00221     int arg_size;
00222     VALUE *arg_opt_table;
00223 
00224     size_t stack_max; /* for stack overflow check */
00225 
00226     /* catch table */
00227     struct iseq_catch_table_entry *catch_table;
00228     int catch_table_size;
00229 
00230     /* for child iseq */
00231     struct rb_iseq_struct *parent_iseq;
00232     struct rb_iseq_struct *local_iseq;
00233 
00234     /****************/
00235     /* dynamic data */
00236     /****************/
00237 
00238     VALUE self;
00239     VALUE orig;                 /* non-NULL if its data have origin */
00240 
00241     /* block inlining */
00242     /*
00243      * NODE *node;
00244      * void *special_block_builder;
00245      * void *cached_special_block_builder;
00246      * VALUE cached_special_block;
00247      */
00248 
00249     /* klass/module nest information stack (cref) */
00250     NODE *cref_stack;
00251     VALUE klass;
00252 
00253     /* misc */
00254     ID defined_method_id;       /* for define_method */
00255 
00256     /* used at compile time */
00257     struct iseq_compile_data *compile_data;
00258 };
00259 
00260 enum ruby_special_exceptions {
00261     ruby_error_reenter,
00262     ruby_error_nomemory,
00263     ruby_error_sysstack,
00264     ruby_error_closed_stream,
00265     ruby_special_error_count
00266 };
00267 
00268 #define GetVMPtr(obj, ptr) \
00269   GetCoreDataFromValue((obj), rb_vm_t, (ptr))
00270 
00271 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
00272 struct rb_objspace;
00273 void rb_objspace_free(struct rb_objspace *);
00274 #endif
00275 
00276 typedef struct rb_vm_struct {
00277     VALUE self;
00278 
00279     rb_global_vm_lock_t gvl;
00280 
00281     struct rb_thread_struct *main_thread;
00282     struct rb_thread_struct *running_thread;
00283 
00284     st_table *living_threads;
00285     VALUE thgroup_default;
00286 
00287     int running;
00288     int inhibit_thread_creation;
00289     int thread_abort_on_exception;
00290     unsigned long trace_flag;
00291     volatile int sleeper;
00292 
00293     /* object management */
00294     VALUE mark_object_ary;
00295 
00296     VALUE special_exceptions[ruby_special_error_count];
00297 
00298     /* load */
00299     VALUE top_self;
00300     VALUE load_path;
00301     VALUE loaded_features;
00302     struct st_table *loading_table;
00303 
00304     /* signal */
00305     struct {
00306         VALUE cmd;
00307         int safe;
00308     } trap_list[RUBY_NSIG];
00309 
00310     /* hook */
00311     rb_event_hook_t *event_hooks;
00312 
00313     int src_encoding_index;
00314 
00315     VALUE verbose, debug, progname;
00316     VALUE coverages;
00317 
00318     struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
00319 
00320 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
00321     struct rb_objspace *objspace;
00322 #endif
00323 
00324     /*
00325      * @shyouhei notes that this is not for storing normal Ruby
00326      * objects so do *NOT* mark this when you GC.
00327      */
00328     struct RArray at_exit;
00329 } rb_vm_t;
00330 
00331 typedef struct {
00332     VALUE *pc;                  /* cfp[0] */
00333     VALUE *sp;                  /* cfp[1] */
00334     VALUE *bp;                  /* cfp[2] */
00335     rb_iseq_t *iseq;            /* cfp[3] */
00336     VALUE flag;                 /* cfp[4] */
00337     VALUE self;                 /* cfp[5] / block[0] */
00338     VALUE *lfp;                 /* cfp[6] / block[1] */
00339     VALUE *dfp;                 /* cfp[7] / block[2] */
00340     rb_iseq_t *block_iseq;      /* cfp[8] / block[3] */
00341     VALUE proc;                 /* cfp[9] / block[4] */
00342     const rb_method_entry_t *me;/* cfp[10] */
00343 } rb_control_frame_t;
00344 
00345 typedef struct rb_block_struct {
00346     VALUE self;                 /* share with method frame if it's only block */
00347     VALUE *lfp;                 /* share with method frame if it's only block */
00348     VALUE *dfp;                 /* share with method frame if it's only block */
00349     rb_iseq_t *iseq;
00350     VALUE proc;
00351 } rb_block_t;
00352 
00353 extern const rb_data_type_t ruby_threadptr_data_type;
00354 
00355 #define GetThreadPtr(obj, ptr) \
00356     TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
00357 
00358 enum rb_thread_status {
00359     THREAD_TO_KILL,
00360     THREAD_RUNNABLE,
00361     THREAD_STOPPED,
00362     THREAD_STOPPED_FOREVER,
00363     THREAD_KILLED
00364 };
00365 
00366 typedef RUBY_JMP_BUF rb_jmpbuf_t;
00367 
00368 struct rb_vm_tag {
00369     rb_jmpbuf_t buf;
00370     VALUE tag;
00371     VALUE retval;
00372     struct rb_vm_tag *prev;
00373 };
00374 
00375 struct rb_vm_protect_tag {
00376     struct rb_vm_protect_tag *prev;
00377 };
00378 
00379 struct rb_unblock_callback {
00380     rb_unblock_function_t *func;
00381     void *arg;
00382 };
00383 
00384 struct rb_mutex_struct;
00385 
00386 #ifdef SIGSTKSZ
00387 #define ALT_STACK_SIZE (SIGSTKSZ*2)
00388 #else
00389 #define ALT_STACK_SIZE (4*1024)
00390 #endif
00391 
00392 typedef struct rb_thread_struct {
00393     VALUE self;
00394     rb_vm_t *vm;
00395 
00396     /* execution information */
00397     VALUE *stack;               /* must free, must mark */
00398     unsigned long stack_size;
00399     rb_control_frame_t *cfp;
00400     int safe_level;
00401     int raised_flag;
00402     VALUE last_status; /* $? */
00403 
00404     /* passing state */
00405     int state;
00406 
00407     int waiting_fd;
00408 
00409     /* for rb_iterate */
00410     const rb_block_t *passed_block;
00411 
00412     /* for bmethod */
00413     const rb_method_entry_t *passed_me;
00414 
00415     /* for load(true) */
00416     VALUE top_self;
00417     VALUE top_wrapper;
00418 
00419     /* eval env */
00420     rb_block_t *base_block;
00421 
00422     VALUE *local_lfp;
00423     VALUE local_svar;
00424 
00425     /* thread control */
00426     rb_thread_id_t thread_id;
00427     enum rb_thread_status status;
00428     int priority;
00429 
00430     native_thread_data_t native_thread_data;
00431     void *blocking_region_buffer;
00432 
00433     VALUE thgroup;
00434     VALUE value;
00435 
00436     VALUE errinfo;
00437     VALUE thrown_errinfo;
00438 
00439     rb_atomic_t interrupt_flag;
00440     rb_thread_lock_t interrupt_lock;
00441     struct rb_unblock_callback unblock;
00442     VALUE locking_mutex;
00443     struct rb_mutex_struct *keeping_mutexes;
00444 
00445     struct rb_vm_tag *tag;
00446     struct rb_vm_protect_tag *protect_tag;
00447 
00448     int parse_in_eval;
00449     int mild_compile_error;
00450 
00451     /* storage */
00452     st_table *local_storage;
00453 
00454     struct rb_thread_struct *join_list_next;
00455     struct rb_thread_struct *join_list_head;
00456 
00457     VALUE first_proc;
00458     VALUE first_args;
00459     VALUE (*first_func)(ANYARGS);
00460 
00461     /* for GC */
00462     VALUE *machine_stack_start;
00463     VALUE *machine_stack_end;
00464     size_t machine_stack_maxsize;
00465 #ifdef __ia64
00466     VALUE *machine_register_stack_start;
00467     VALUE *machine_register_stack_end;
00468     size_t machine_register_stack_maxsize;
00469 #endif
00470     jmp_buf machine_regs;
00471     int mark_stack_len;
00472 
00473     /* statistics data for profiler */
00474     VALUE stat_insn_usage;
00475 
00476     /* tracer */
00477     rb_event_hook_t *event_hooks;
00478     rb_event_flag_t event_flags;
00479     int tracing;
00480 
00481     /* fiber */
00482     VALUE fiber;
00483     VALUE root_fiber;
00484     rb_jmpbuf_t root_jmpbuf;
00485 
00486     /* misc */
00487     int method_missing_reason;
00488     int abort_on_exception;
00489 #ifdef USE_SIGALTSTACK
00490     void *altstack;
00491 #endif
00492     unsigned long running_time_us;
00493 } rb_thread_t;
00494 
00495 /* iseq.c */
00496 #if defined __GNUC__ && __GNUC__ >= 4
00497 #pragma GCC visibility push(default)
00498 #endif
00499 VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
00500 VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE filename, VALUE filepath, VALUE parent);
00501 VALUE rb_iseq_new_main(NODE *node, VALUE filename, VALUE filepath);
00502 VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, VALUE);
00503 VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
00504 VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
00505 VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt);
00506 VALUE rb_iseq_disasm(VALUE self);
00507 int rb_iseq_disasm_insn(VALUE str, VALUE *iseqval, size_t pos, rb_iseq_t *iseq, VALUE child);
00508 const char *ruby_node_name(int node);
00509 int rb_iseq_first_lineno(rb_iseq_t *iseq);
00510 
00511 RUBY_EXTERN VALUE rb_cISeq;
00512 RUBY_EXTERN VALUE rb_cRubyVM;
00513 RUBY_EXTERN VALUE rb_cEnv;
00514 RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
00515 #if defined __GNUC__ && __GNUC__ >= 4
00516 #pragma GCC visibility pop
00517 #endif
00518 
00519 /* each thread has this size stack : 128KB */
00520 #define RUBY_VM_THREAD_STACK_SIZE (128 * 1024)
00521 
00522 #define GetProcPtr(obj, ptr) \
00523   GetCoreDataFromValue((obj), rb_proc_t, (ptr))
00524 
00525 typedef struct {
00526     rb_block_t block;
00527 
00528     VALUE envval;               /* for GC mark */
00529     VALUE blockprocval;
00530     int safe_level;
00531     int is_from_method;
00532     int is_lambda;
00533 } rb_proc_t;
00534 
00535 #define GetEnvPtr(obj, ptr) \
00536   GetCoreDataFromValue((obj), rb_env_t, (ptr))
00537 
00538 typedef struct {
00539     VALUE *env;
00540     int env_size;
00541     int local_size;
00542     VALUE prev_envval;          /* for GC mark */
00543     rb_block_t block;
00544 } rb_env_t;
00545 
00546 #define GetBindingPtr(obj, ptr) \
00547   GetCoreDataFromValue((obj), rb_binding_t, (ptr))
00548 
00549 typedef struct {
00550     VALUE env;
00551     VALUE filename;
00552     unsigned short line_no;
00553 } rb_binding_t;
00554 
00555 /* used by compile time and send insn */
00556 #define VM_CALL_ARGS_SPLAT_BIT     (0x01 << 1)
00557 #define VM_CALL_ARGS_BLOCKARG_BIT  (0x01 << 2)
00558 #define VM_CALL_FCALL_BIT          (0x01 << 3)
00559 #define VM_CALL_VCALL_BIT          (0x01 << 4)
00560 #define VM_CALL_TAILCALL_BIT       (0x01 << 5)
00561 #define VM_CALL_TAILRECURSION_BIT  (0x01 << 6)
00562 #define VM_CALL_SUPER_BIT          (0x01 << 7)
00563 #define VM_CALL_OPT_SEND_BIT       (0x01 << 8)
00564 
00565 enum vm_special_object_type {
00566     VM_SPECIAL_OBJECT_VMCORE = 1,
00567     VM_SPECIAL_OBJECT_CBASE,
00568     VM_SPECIAL_OBJECT_CONST_BASE
00569 };
00570 
00571 #define VM_FRAME_MAGIC_METHOD 0x11
00572 #define VM_FRAME_MAGIC_BLOCK  0x21
00573 #define VM_FRAME_MAGIC_CLASS  0x31
00574 #define VM_FRAME_MAGIC_TOP    0x41
00575 #define VM_FRAME_MAGIC_FINISH 0x51
00576 #define VM_FRAME_MAGIC_CFUNC  0x61
00577 #define VM_FRAME_MAGIC_PROC   0x71
00578 #define VM_FRAME_MAGIC_IFUNC  0x81
00579 #define VM_FRAME_MAGIC_EVAL   0x91
00580 #define VM_FRAME_MAGIC_LAMBDA 0xa1
00581 #define VM_FRAME_MAGIC_MASK_BITS   8
00582 #define VM_FRAME_MAGIC_MASK   (~(~0<<VM_FRAME_MAGIC_MASK_BITS))
00583 
00584 #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
00585 
00586 /* other frame flag */
00587 #define VM_FRAME_FLAG_PASSED 0x0100
00588 
00589 #define RUBYVM_CFUNC_FRAME_P(cfp) \
00590   (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
00591 
00592 /* inline cache */
00593 typedef struct iseq_inline_cache_entry *IC;
00594 
00595 void rb_vm_change_state(void);
00596 
00597 typedef VALUE CDHASH;
00598 
00599 #ifndef FUNC_FASTCALL
00600 #define FUNC_FASTCALL(x) x
00601 #endif
00602 
00603 typedef rb_control_frame_t *
00604   (FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
00605 
00606 #define GC_GUARDED_PTR(p)     ((VALUE)((VALUE)(p) | 0x01))
00607 #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
00608 #define GC_GUARDED_PTR_P(p)   (((VALUE)(p)) & 0x01)
00609 
00610 #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
00611 #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
00612 #define RUBY_VM_END_CONTROL_FRAME(th) \
00613   ((rb_control_frame_t *)((th)->stack + (th)->stack_size))
00614 #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
00615   ((void *)(ecfp) > (void *)(cfp))
00616 #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
00617   (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
00618 
00619 #define RUBY_VM_IFUNC_P(ptr)        (BUILTIN_TYPE(ptr) == T_NODE)
00620 #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
00621   ((ptr) && !RUBY_VM_IFUNC_P(ptr))
00622 
00623 #define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
00624 #define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
00625   ((rb_control_frame_t *)((VALUE *)(b) - 5))
00626 
00627 /* VM related object allocate functions */
00628 VALUE rb_thread_alloc(VALUE klass);
00629 VALUE rb_proc_alloc(VALUE klass);
00630 
00631 /* for debug */
00632 extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
00633 #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
00634 #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
00635 void rb_vm_bugreport(void);
00636 
00637 /* functions about thread/vm execution */
00638 #if defined __GNUC__ && __GNUC__ >= 4
00639 #pragma GCC visibility push(default)
00640 #endif
00641 VALUE rb_iseq_eval(VALUE iseqval);
00642 VALUE rb_iseq_eval_main(VALUE iseqval);
00643 void rb_enable_interrupt(void);
00644 void rb_disable_interrupt(void);
00645 #if defined __GNUC__ && __GNUC__ >= 4
00646 #pragma GCC visibility pop
00647 #endif
00648 int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
00649 
00650 VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
00651                         int argc, const VALUE *argv, const rb_block_t *blockptr);
00652 VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
00653 VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
00654 void rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th);
00655 void rb_vm_inc_const_missing_count(void);
00656 void rb_vm_gvl_destroy(rb_vm_t *vm);
00657 VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
00658                  const VALUE *argv, const rb_method_entry_t *me);
00659 void rb_unlink_method_entry(rb_method_entry_t *me);
00660 void rb_gc_mark_unlinked_live_method_entries(void *pvm);
00661 
00662 void rb_thread_start_timer_thread(void);
00663 void rb_thread_stop_timer_thread(int);
00664 void rb_thread_reset_timer_thread(void);
00665 void rb_thread_wakeup_timer_thread(void);
00666 
00667 int ruby_thread_has_gvl_p(void);
00668 VALUE rb_make_backtrace(void);
00669 typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
00670 int rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg);
00671 rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
00672 int rb_vm_get_sourceline(const rb_control_frame_t *);
00673 VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
00674 void rb_vm_stack_to_heap(rb_thread_t *th);
00675 void ruby_thread_init_stack(rb_thread_t *th);
00676 
00677 NOINLINE(void rb_gc_save_machine_context(rb_thread_t *));
00678 void rb_gc_mark_machine_stack(rb_thread_t *th);
00679 
00680 #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
00681 
00682 /* for thread */
00683 
00684 #if RUBY_VM_THREAD_MODEL == 2
00685 RUBY_EXTERN rb_thread_t *ruby_current_thread;
00686 extern rb_vm_t *ruby_current_vm;
00687 
00688 #define GET_VM() ruby_current_vm
00689 #define GET_THREAD() ruby_current_thread
00690 #define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
00691 #define rb_thread_set_current(th) do { \
00692     if ((th)->vm->running_thread != (th)) { \
00693         (th)->vm->running_thread->running_time_us = 0; \
00694     } \
00695     rb_thread_set_current_raw(th); \
00696     (th)->vm->running_thread = (th); \
00697 } while (0)
00698 
00699 #else
00700 #error "unsupported thread model"
00701 #endif
00702 
00703 #define RUBY_VM_SET_TIMER_INTERRUPT(th)         ATOMIC_OR((th)->interrupt_flag, 0x01)
00704 #define RUBY_VM_SET_INTERRUPT(th)               ATOMIC_OR((th)->interrupt_flag, 0x02)
00705 #define RUBY_VM_SET_FINALIZER_INTERRUPT(th)     ATOMIC_OR((th)->interrupt_flag, 0x04)
00706 #define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & 0x02)
00707 
00708 int rb_signal_buff_size(void);
00709 void rb_signal_exec(rb_thread_t *th, int sig);
00710 void rb_threadptr_check_signal(rb_thread_t *mth);
00711 void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
00712 void rb_threadptr_signal_exit(rb_thread_t *th);
00713 void rb_threadptr_execute_interrupts(rb_thread_t *);
00714 void rb_threadptr_interrupt(rb_thread_t *th);
00715 void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
00716 
00717 void rb_thread_lock_unlock(rb_thread_lock_t *);
00718 void rb_thread_lock_destroy(rb_thread_lock_t *);
00719 
00720 #define RUBY_VM_CHECK_INTS_TH(th) do { \
00721     if (UNLIKELY((th)->interrupt_flag)) { \
00722         rb_threadptr_execute_interrupts(th); \
00723     } \
00724 } while (0)
00725 
00726 #define RUBY_VM_CHECK_INTS() \
00727   RUBY_VM_CHECK_INTS_TH(GET_THREAD())
00728 
00729 /* tracer */
00730 void
00731 rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass);
00732 
00733 #define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
00734     rb_event_flag_t wait_event__ = (th)->event_flags; \
00735     if (UNLIKELY(wait_event__)) { \
00736         if (wait_event__ & ((flag) | RUBY_EVENT_VM)) { \
00737             rb_threadptr_exec_event_hooks((th), (flag), (self), (id), (klass)); \
00738         } \
00739     } \
00740 } while (0)
00741 
00742 #if defined __GNUC__ && __GNUC__ >= 4
00743 #pragma GCC visibility push(default)
00744 #endif
00745 
00746 int rb_thread_check_trap_pending(void);
00747 
00748 extern VALUE rb_get_coverages(void);
00749 extern void rb_set_coverages(VALUE);
00750 extern void rb_reset_coverages(void);
00751 
00752 #if defined __GNUC__ && __GNUC__ >= 4
00753 #pragma GCC visibility pop
00754 #endif
00755 
00756 #endif /* RUBY_VM_CORE_H */
00757