Ruby  2.0.0p195(2013-05-14revision40734)
vm_core.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  vm_core.h -
4 
5  $Author: nagachika $
6  created at: 04/01/01 19:41:38 JST
7 
8  Copyright (C) 2004-2007 Koichi Sasada
9 
10 **********************************************************************/
11 
12 #ifndef RUBY_VM_CORE_H
13 #define RUBY_VM_CORE_H
14 
15 #define RUBY_VM_THREAD_MODEL 2
16 
17 #include "ruby/ruby.h"
18 #include "ruby/st.h"
19 
20 #include "node.h"
21 #include "vm_debug.h"
22 #include "vm_opts.h"
23 #include "id.h"
24 #include "method.h"
25 #include "ruby_atomic.h"
26 
27 #if defined(_WIN32)
28 #include "thread_win32.h"
29 #elif defined(HAVE_PTHREAD_H)
30 #include "thread_pthread.h"
31 #else
32 #error "unsupported thread type"
33 #endif
34 
35 #ifndef ENABLE_VM_OBJSPACE
36 #ifdef _WIN32
37 /*
38  * TODO: object space independent st_table.
39  * socklist needs st_table in rb_w32_sysinit(), before object space
40  * initialization.
41  * It is too early now to change st_hash_type, since it breaks binary
42  * compatibility.
43  */
44 #define ENABLE_VM_OBJSPACE 0
45 #else
46 #define ENABLE_VM_OBJSPACE 1
47 #endif
48 #endif
49 
50 #include <setjmp.h>
51 #include <signal.h>
52 
53 #ifndef NSIG
54 # define NSIG (_SIGMAX + 1) /* For QNX */
55 #endif
56 
57 #define RUBY_NSIG NSIG
58 
59 #ifdef HAVE_STDARG_PROTOTYPES
60 #include <stdarg.h>
61 #define va_init_list(a,b) va_start((a),(b))
62 #else
63 #include <varargs.h>
64 #define va_init_list(a,b) va_start((a))
65 #endif
66 
67 #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
68 #define USE_SIGALTSTACK
69 #endif
70 
71 /*****************/
72 /* configuration */
73 /*****************/
74 
75 /* gcc ver. check */
76 #if defined(__GNUC__) && __GNUC__ >= 2
77 
78 #if OPT_TOKEN_THREADED_CODE
79 #if OPT_DIRECT_THREADED_CODE
80 #undef OPT_DIRECT_THREADED_CODE
81 #endif
82 #endif
83 
84 #else /* defined(__GNUC__) && __GNUC__ >= 2 */
85 
86 /* disable threaded code options */
87 #if OPT_DIRECT_THREADED_CODE
88 #undef OPT_DIRECT_THREADED_CODE
89 #endif
90 #if OPT_TOKEN_THREADED_CODE
91 #undef OPT_TOKEN_THREADED_CODE
92 #endif
93 #endif
94 
95 #ifdef __native_client__
96 #undef OPT_DIRECT_THREADED_CODE
97 #endif
98 
99 /* call threaded code */
100 #if OPT_CALL_THREADED_CODE
101 #if OPT_DIRECT_THREADED_CODE
102 #undef OPT_DIRECT_THREADED_CODE
103 #endif /* OPT_DIRECT_THREADED_CODE */
104 #if OPT_STACK_CACHING
105 #undef OPT_STACK_CACHING
106 #endif /* OPT_STACK_CACHING */
107 #endif /* OPT_CALL_THREADED_CODE */
108 
109 /* likely */
110 #if __GNUC__ >= 3
111 #define LIKELY(x) (__builtin_expect((x), 1))
112 #define UNLIKELY(x) (__builtin_expect((x), 0))
113 #else /* __GNUC__ >= 3 */
114 #define LIKELY(x) (x)
115 #define UNLIKELY(x) (x)
116 #endif /* __GNUC__ >= 3 */
117 
118 #if __GNUC__ >= 3
119 #define UNINITIALIZED_VAR(x) x = x
120 #else
121 #define UNINITIALIZED_VAR(x) x
122 #endif
123 
124 typedef unsigned long rb_num_t;
125 
126 /* iseq data type */
127 
129 
131 
135  union {
137  long index;
138  } ic_value;
139 };
140 
141 /* to avoid warning */
142 struct rb_thread_struct;
144 
145 /* rb_call_info_t contains calling information including inline cache */
146 typedef struct rb_call_info_struct {
147  /* fixed at compile time */
152 
153  /* inline cache: keys */
156 
157  /* inline cache: values */
160 
161  /* temporary values for method calling */
162  int argc;
165  union {
166  int opt_pc; /* used by iseq */
167  long index; /* used by ivar */
168  int missing_reason; /* used by method_missing */
169  int inc_sp; /* used by cfunc */
170  } aux;
171 
172  VALUE (*call)(struct rb_thread_struct *th, struct rb_control_frame_struct *cfp, struct rb_call_info_struct *ci);
174 
175 #if 1
176 #define GetCoreDataFromValue(obj, type, ptr) do { \
177  (ptr) = (type*)DATA_PTR(obj); \
178 } while (0)
179 #else
180 #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
181 #endif
182 
183 #define GetISeqPtr(obj, ptr) \
184  GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
185 
186 typedef struct rb_iseq_location_struct {
191  size_t first_lineno;
193 
194 struct rb_iseq_struct;
195 
197  /***************/
198  /* static data */
199  /***************/
200 
201  enum iseq_type {
211  } type; /* instruction sequence type */
212 
214 
215  VALUE *iseq; /* iseq (insn number and operands) */
216  VALUE *iseq_encoded; /* encoded iseq */
217  unsigned long iseq_size;
218  VALUE mark_ary; /* Array: includes operands which should be GC marked */
219  VALUE coverage; /* coverage array */
220 
221  /* insn info, must be freed */
224 
225  ID *local_table; /* must free */
227 
228  /* sizeof(vars) + 1 */
230 
232  int ic_size;
233 
236 
264  int argc;
266  int arg_rest;
268  int arg_opts;
271  int arg_size;
274  int arg_keyword_check; /* if this is true, raise an ArgumentError when unknown keyword argument is passed */
277 
278  size_t stack_max; /* for stack overflow check */
279 
280  /* catch table */
283 
284  /* for child iseq */
287 
288  /****************/
289  /* dynamic data */
290  /****************/
291 
292  VALUE self;
293  VALUE orig; /* non-NULL if its data have origin */
294 
295  /* block inlining */
296  /*
297  * NODE *node;
298  * void *special_block_builder;
299  * void *cached_special_block_builder;
300  * VALUE cached_special_block;
301  */
302 
303  /* klass/module nest information stack (cref) */
306 
307  /* misc */
308  ID defined_method_id; /* for define_method */
310 
311  /* used at compile time */
313 };
314 
321 };
322 
323 #define GetVMPtr(obj, ptr) \
324  GetCoreDataFromValue((obj), rb_vm_t, (ptr))
325 
326 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
327 struct rb_objspace;
328 void rb_objspace_free(struct rb_objspace *);
329 #endif
330 
331 typedef struct rb_hook_list_struct {
336 
337 typedef struct rb_vm_struct {
338  VALUE self;
339 
342 
345 
348 
349  int running;
352  volatile int sleeper;
353 
354  /* object management */
356 
358 
359  /* load */
369 
370  /* signal */
371  struct {
373  int safe;
374  } trap_list[RUBY_NSIG];
375 
376  /* hook */
378 
380 
383 
385 
386 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
388 #endif
389 
390  /*
391  * @shyouhei notes that this is not for storing normal Ruby
392  * objects so do *NOT* mark this when you GC.
393  */
394  struct RArray at_exit;
395 
397 
398  /* params */
399  struct { /* size in byte */
404  } default_params;
405 } rb_vm_t;
406 
407 /* default values */
408 
409 #define RUBY_VM_SIZE_ALIGN 4096
410 
411 #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
412 #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
413 #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
414 #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
415 
416 #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
417 #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
418 #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
419 #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
420 
421 #ifndef VM_DEBUG_BP_CHECK
422 #define VM_DEBUG_BP_CHECK 0
423 #endif
424 
425 typedef struct rb_control_frame_struct {
426  VALUE *pc; /* cfp[0] */
427  VALUE *sp; /* cfp[1] */
428  rb_iseq_t *iseq; /* cfp[2] */
429  VALUE flag; /* cfp[3] */
430  VALUE self; /* cfp[4] / block[0] */
431  VALUE klass; /* cfp[5] / block[1] */
432  VALUE *ep; /* cfp[6] / block[2] */
433  rb_iseq_t *block_iseq; /* cfp[7] / block[3] */
434  VALUE proc; /* cfp[8] / block[4] */
435  const rb_method_entry_t *me;/* cfp[9] */
436 
437 #if VM_DEBUG_BP_CHECK
438  VALUE *bp_check; /* cfp[10] */
439 #endif
441 
442 typedef struct rb_block_struct {
443  VALUE self; /* share with method frame if it's only block */
444  VALUE klass; /* share with method frame if it's only block */
445  VALUE *ep; /* share with method frame if it's only block */
448 } rb_block_t;
449 
451 
452 #define GetThreadPtr(obj, ptr) \
453  TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
454 
460 };
461 
462 typedef RUBY_JMP_BUF rb_jmpbuf_t;
463 
464 struct rb_vm_tag {
468  struct rb_vm_tag *prev;
469 };
470 
473 };
474 
477  void *arg;
478 };
479 
480 struct rb_mutex_struct;
481 
482 struct rb_thread_struct;
483 typedef struct rb_thread_list_struct{
487 
488 
489 typedef struct rb_thread_struct {
490  VALUE self;
492 
493  /* execution information */
494  VALUE *stack; /* must free, must mark */
495  size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
499  VALUE last_status; /* $? */
500 
501  /* passing state */
502  int state;
503 
505 
506  /* for rb_iterate */
508 
509  /* for bmethod */
511 
512  /* for cfunc */
514 
515  /* for load(true) */
518 
519  /* eval env */
521 
524 
525  /* thread control */
528  int to_kill;
529  int priority;
530 
533 
536 
537  /* temporary place of errinfo */
539 
540  /* temporary place of retval on OPT_CALL_THREADED_CODE */
541 #if OPT_CALL_THREADED_CODE
542  VALUE retval;
543 #endif
544 
545  /* async errinfo queue */
549 
551  unsigned long interrupt_mask;
556 
557  struct rb_vm_tag *tag;
559 
567 
573 
574  /* storage */
576 
578 
582 
583  /* for GC */
587 #ifdef __ia64
588  VALUE *machine_register_stack_start;
589  VALUE *machine_register_stack_end;
590  size_t machine_register_stack_maxsize;
591 #endif
592  jmp_buf machine_regs;
594 
595  /* statistics data for profiler */
597 
598  /* tracer */
600  struct rb_trace_arg_struct *trace_arg; /* trace information */
601 
602  /* fiber */
606 
607  /* misc */
610 #ifdef USE_SIGALTSTACK
611  void *altstack;
612 #endif
613  unsigned long running_time_us;
614 } rb_thread_t;
615 
616 typedef enum {
620  /* 0x03..0x06 is reserved */
623 
624 #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
625 #define VM_DEFINECLASS_FLAG_SCOPED 0x08
626 #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
627 #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
628 #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
629  ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
630 
631 /* iseq.c */
632 #if defined __GNUC__ && __GNUC__ >= 4
633 #pragma GCC visibility push(default)
634 #endif
635 
636 /* node -> iseq */
637 VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
638 VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent);
639 VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path);
642 
643 /* src -> iseq */
644 VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
645 VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block);
646 VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
647 
649 int rb_iseq_disasm_insn(VALUE str, VALUE *iseqval, size_t pos, rb_iseq_t *iseq, VALUE child);
650 const char *ruby_node_name(int node);
651 int rb_iseq_first_lineno(const rb_iseq_t *iseq);
652 
657 #if defined __GNUC__ && __GNUC__ >= 4
658 #pragma GCC visibility pop
659 #endif
660 
661 #define GetProcPtr(obj, ptr) \
662  GetCoreDataFromValue((obj), rb_proc_t, (ptr))
663 
664 typedef struct {
666 
667  VALUE envval; /* for GC mark */
672 } rb_proc_t;
673 
674 #define GetEnvPtr(obj, ptr) \
675  GetCoreDataFromValue((obj), rb_env_t, (ptr))
676 
677 typedef struct {
679  int env_size;
681  VALUE prev_envval; /* for GC mark */
683 } rb_env_t;
684 
685 #define GetBindingPtr(obj, ptr) \
686  GetCoreDataFromValue((obj), rb_binding_t, (ptr))
687 
688 typedef struct {
691  unsigned short first_lineno;
692 } rb_binding_t;
693 
694 /* used by compile time and send insn */
695 
700 };
701 
702 #define VM_CHECKMATCH_TYPE_MASK 0x03
703 #define VM_CHECKMATCH_ARRAY 0x04
704 
705 #define VM_CALL_ARGS_SPLAT (0x01 << 1) /* m(*args) */
706 #define VM_CALL_ARGS_BLOCKARG (0x01 << 2) /* m(&block) */
707 #define VM_CALL_FCALL (0x01 << 3) /* m(...) */
708 #define VM_CALL_VCALL (0x01 << 4) /* m */
709 #define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
710 #define VM_CALL_SUPER (0x01 << 6) /* super */
711 #define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
712 #define VM_CALL_ARGS_SKIP_SETUP (0x01 << 8) /* (flag & (SPLAT|BLOCKARG)) && blockiseq == 0 */
713 
718 };
719 
720 #define VM_FRAME_MAGIC_METHOD 0x11
721 #define VM_FRAME_MAGIC_BLOCK 0x21
722 #define VM_FRAME_MAGIC_CLASS 0x31
723 #define VM_FRAME_MAGIC_TOP 0x41
724 #define VM_FRAME_MAGIC_CFUNC 0x61
725 #define VM_FRAME_MAGIC_PROC 0x71
726 #define VM_FRAME_MAGIC_IFUNC 0x81
727 #define VM_FRAME_MAGIC_EVAL 0x91
728 #define VM_FRAME_MAGIC_LAMBDA 0xa1
729 #define VM_FRAME_MAGIC_MASK_BITS 8
730 #define VM_FRAME_MAGIC_MASK (~(~0<<VM_FRAME_MAGIC_MASK_BITS))
731 
732 #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
733 
734 /* other frame flag */
735 #define VM_FRAME_FLAG_PASSED 0x0100
736 #define VM_FRAME_FLAG_FINISH 0x0200
737 #define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
738 
739 #define RUBYVM_CFUNC_FRAME_P(cfp) \
740  (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
741 
742 /* inline cache */
743 typedef struct iseq_inline_cache_entry *IC;
745 
746 void rb_vm_change_state(void);
747 
748 typedef VALUE CDHASH;
749 
750 #ifndef FUNC_FASTCALL
751 #define FUNC_FASTCALL(x) x
752 #endif
753 
754 typedef rb_control_frame_t *
756 
757 #define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
758 #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
759 #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
760 
761 /*
762  * block frame:
763  * ep[ 0]: prev frame
764  * ep[-1]: CREF (for *_eval)
765  *
766  * method frame:
767  * ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG)
768  */
769 
770 #define VM_ENVVAL_BLOCK_PTR_FLAG 0x02
771 #define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG)
772 #define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG)
773 #define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v))
774 #define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v)))
775 
776 #define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0]))
777 #define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0]))
778 #define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0])
779 
782 
783 #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
784 #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
785 #define RUBY_VM_END_CONTROL_FRAME(th) \
786  ((rb_control_frame_t *)((th)->stack + (th)->stack_size))
787 #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
788  ((void *)(ecfp) > (void *)(cfp))
789 #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
790  (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
791 
792 #define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE)
793 #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
794  ((ptr) && !RUBY_VM_IFUNC_P(ptr))
795 
796 #define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
797 #define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
798  ((rb_control_frame_t *)((VALUE *)(b) - 4))
799 /* magic number `4' is depend on rb_control_frame_t layout. */
800 
801 /* VM related object allocate functions */
803 VALUE rb_proc_alloc(VALUE klass);
804 
805 /* for debug */
809 
810 #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
811 #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
812 void rb_vm_bugreport(void);
813 
814 /* functions about thread/vm execution */
815 #if defined __GNUC__ && __GNUC__ >= 4
816 #pragma GCC visibility push(default)
817 #endif
818 VALUE rb_iseq_eval(VALUE iseqval);
819 VALUE rb_iseq_eval_main(VALUE iseqval);
820 #if defined __GNUC__ && __GNUC__ >= 4
821 #pragma GCC visibility pop
822 #endif
823 int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
824 
826  int argc, const VALUE *argv, const rb_block_t *blockptr);
827 VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
831 void rb_vm_gvl_destroy(rb_vm_t *vm);
832 VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
833  const VALUE *argv, const rb_method_entry_t *me,
834  VALUE defined_class);
837 
842 
843 int ruby_thread_has_gvl_p(void);
844 typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
848 VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
851 int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
852 
854 
856 
857 #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
858 
859 #define CHECK_VM_STACK_OVERFLOW(cfp, margin) do \
860  if ((VALUE *)((char *)(((VALUE *)(cfp)->sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \
861  vm_stackoverflow(); \
862  } \
863 while (0)
864 
865 /* for thread */
866 
867 #if RUBY_VM_THREAD_MODEL == 2
869 extern rb_vm_t *ruby_current_vm;
871 
872 #define GET_VM() ruby_current_vm
873 
874 #ifndef OPT_CALL_CFUNC_WITHOUT_FRAME
875 #define OPT_CALL_CFUNC_WITHOUT_FRAME 0
876 #endif
877 
878 static inline rb_thread_t *
880 {
882 #if OPT_CALL_CFUNC_WITHOUT_FRAME
883  if (UNLIKELY(th->passed_ci != 0)) {
884  void vm_call_cfunc_push_frame(rb_thread_t *th);
885  vm_call_cfunc_push_frame(th);
886  }
887 #endif
888  return th;
889 }
890 
891 #define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
892 #define rb_thread_set_current(th) do { \
893  if ((th)->vm->running_thread != (th)) { \
894  (th)->running_time_us = 0; \
895  } \
896  rb_thread_set_current_raw(th); \
897  (th)->vm->running_thread = (th); \
898 } while (0)
899 
900 #else
901 #error "unsupported thread model"
902 #endif
903 
904 enum {
909 };
910 
911 #define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK)
912 #define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, PENDING_INTERRUPT_MASK)
913 #define RUBY_VM_SET_FINALIZER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, FINALIZER_INTERRUPT_MASK)
914 #define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK)
915 #define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
916 #define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask)
917 
918 int rb_signal_buff_size(void);
919 void rb_signal_exec(rb_thread_t *th, int sig);
921 void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
929 
932 
933 #define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
934  if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
935  th->pending_interrupt_queue_checked = 0; \
936  RUBY_VM_SET_INTERRUPT(th); \
937  rb_threadptr_execute_interrupts(th, 1); \
938  } \
939  else if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
940  rb_threadptr_execute_interrupts(th, 1); \
941  } \
942  } while (0)
943 
944 #define RUBY_VM_CHECK_INTS(th) do { \
945  if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
946  rb_threadptr_execute_interrupts(th, 0); \
947  } \
948 } while (0)
949 
950 /* tracer */
955  VALUE self;
959 
961 
962  /* calc from cfp */
963  int lineno;
965 };
966 
967 void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
969 
970 #define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
971  if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
972  if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
973  struct rb_trace_arg_struct trace_arg; \
974  trace_arg.event = (flag_); \
975  trace_arg.th = (th_); \
976  trace_arg.cfp = (trace_arg.th)->cfp; \
977  trace_arg.self = (self_); \
978  trace_arg.id = (id_); \
979  trace_arg.klass = (klass_); \
980  trace_arg.data = (data_); \
981  trace_arg.path = Qundef; \
982  trace_arg.klass_solved = 0; \
983  if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
984  else rb_threadptr_exec_event_hooks(&trace_arg); \
985  } \
986  } \
987 } while (0)
988 
989 #define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
990  EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
991 
992 #define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
993  EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
994 
995 #if defined __GNUC__ && __GNUC__ >= 4
996 #pragma GCC visibility push(default)
997 #endif
998 
1000 
1001 extern VALUE rb_get_coverages(void);
1002 extern void rb_set_coverages(VALUE);
1003 extern void rb_reset_coverages(void);
1004 
1005 #if defined __GNUC__ && __GNUC__ >= 4
1006 #pragma GCC visibility pop
1007 #endif
1008 
1009 #endif /* RUBY_VM_CORE_H */
1010