Ruby
2.0.0p195(2013-05-14revision40734)
Main Page
Modules
Data Structures
Files
File List
Globals
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
128
struct
iseq_compile_data_ensure_node_stack
;
129
130
typedef
struct
rb_compile_option_struct
rb_compile_option_t
;
131
132
struct
iseq_inline_cache_entry
{
133
VALUE
ic_vmstat
;
134
VALUE
ic_class
;
135
union
{
136
VALUE
value
;
137
long
index
;
138
}
ic_value
;
139
};
140
141
/* to avoid warning */
142
struct
rb_thread_struct
;
143
struct
rb_control_frame_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 */
148
ID
mid
;
149
VALUE
flag
;
150
int
orig_argc
;
151
rb_iseq_t
*
blockiseq
;
152
153
/* inline cache: keys */
154
VALUE
vmstat
;
155
VALUE
klass
;
156
157
/* inline cache: values */
158
const
rb_method_entry_t
*
me
;
159
VALUE
defined_class
;
160
161
/* temporary values for method calling */
162
int
argc
;
163
struct
rb_block_struct
*
blockptr
;
164
VALUE
recv
;
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);
173
}
rb_call_info_t
;
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
{
187
VALUE
path
;
188
VALUE
absolute_path
;
189
VALUE
base_label
;
190
VALUE
label
;
191
size_t
first_lineno
;
192
}
rb_iseq_location_t
;
193
194
struct
rb_iseq_struct
;
195
196
struct
rb_iseq_struct
{
197
/***************/
198
/* static data */
199
/***************/
200
201
enum
iseq_type
{
202
ISEQ_TYPE_TOP
,
203
ISEQ_TYPE_METHOD
,
204
ISEQ_TYPE_BLOCK
,
205
ISEQ_TYPE_CLASS
,
206
ISEQ_TYPE_RESCUE
,
207
ISEQ_TYPE_ENSURE
,
208
ISEQ_TYPE_EVAL
,
209
ISEQ_TYPE_MAIN
,
210
ISEQ_TYPE_DEFINED_GUARD
211
}
type
;
/* instruction sequence type */
212
213
rb_iseq_location_t
location
;
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 */
222
struct
iseq_line_info_entry
*
line_info_table
;
223
size_t
line_info_size
;
224
225
ID
*
local_table
;
/* must free */
226
int
local_table_size
;
227
228
/* sizeof(vars) + 1 */
229
int
local_size
;
230
231
struct
iseq_inline_cache_entry
*
ic_entries
;
232
int
ic_size
;
233
234
rb_call_info_t
*
callinfo_entries
;
235
int
callinfo_size
;
236
264
int
argc
;
265
int
arg_simple
;
266
int
arg_rest
;
267
int
arg_block
;
268
int
arg_opts
;
269
int
arg_post_len
;
270
int
arg_post_start
;
271
int
arg_size
;
272
VALUE
*
arg_opt_table
;
273
int
arg_keyword
;
274
int
arg_keyword_check
;
/* if this is true, raise an ArgumentError when unknown keyword argument is passed */
275
int
arg_keywords
;
276
ID
*
arg_keyword_table
;
277
278
size_t
stack_max
;
/* for stack overflow check */
279
280
/* catch table */
281
struct
iseq_catch_table_entry
*
catch_table
;
282
int
catch_table_size
;
283
284
/* for child iseq */
285
struct
rb_iseq_struct
*
parent_iseq
;
286
struct
rb_iseq_struct
*
local_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) */
304
NODE
*
cref_stack
;
305
VALUE
klass
;
306
307
/* misc */
308
ID
defined_method_id
;
/* for define_method */
309
rb_num_t
flip_cnt
;
310
311
/* used at compile time */
312
struct
iseq_compile_data
*
compile_data
;
313
};
314
315
enum
ruby_special_exceptions
{
316
ruby_error_reenter
,
317
ruby_error_nomemory
,
318
ruby_error_sysstack
,
319
ruby_error_closed_stream
,
320
ruby_special_error_count
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
{
332
struct
rb_event_hook_struct
*
hooks
;
333
rb_event_flag_t
events
;
334
int
need_clean
;
335
}
rb_hook_list_t
;
336
337
typedef
struct
rb_vm_struct
{
338
VALUE
self
;
339
340
rb_global_vm_lock_t
gvl
;
341
rb_thread_lock_t
thread_destruct_lock
;
342
343
struct
rb_thread_struct
*
main_thread
;
344
struct
rb_thread_struct
*
running_thread
;
345
346
st_table
*
living_threads
;
347
VALUE
thgroup_default
;
348
349
int
running
;
350
int
thread_abort_on_exception
;
351
int
trace_running
;
352
volatile
int
sleeper
;
353
354
/* object management */
355
VALUE
mark_object_ary
;
356
357
VALUE
special_exceptions
[
ruby_special_error_count
];
358
359
/* load */
360
VALUE
top_self
;
361
VALUE
load_path
;
362
VALUE
load_path_snapshot
;
363
VALUE
load_path_check_cache
;
364
VALUE
expanded_load_path
;
365
VALUE
loaded_features
;
366
VALUE
loaded_features_snapshot
;
367
struct
st_table
*
loaded_features_index
;
368
struct
st_table
*
loading_table
;
369
370
/* signal */
371
struct
{
372
VALUE
cmd
;
373
int
safe
;
374
}
trap_list
[
RUBY_NSIG
];
375
376
/* hook */
377
rb_hook_list_t
event_hooks
;
378
379
int
src_encoding_index
;
380
381
VALUE
verbose
,
debug
,
progname
;
382
VALUE
coverages
;
383
384
struct
unlinked_method_entry_list_entry
*
unlinked_method_entry_list
;
385
386
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
387
struct
rb_objspace
*
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
396
VALUE
*
defined_strings
;
397
398
/* params */
399
struct
{
/* size in byte */
400
size_t
thread_vm_stack_size
;
401
size_t
thread_machine_stack_size
;
402
size_t
fiber_vm_stack_size
;
403
size_t
fiber_machine_stack_size
;
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
440
}
rb_control_frame_t
;
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 */
446
rb_iseq_t
*
iseq
;
447
VALUE
proc
;
448
}
rb_block_t
;
449
450
extern
const
rb_data_type_t
ruby_threadptr_data_type
;
451
452
#define GetThreadPtr(obj, ptr) \
453
TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
454
455
enum
rb_thread_status
{
456
THREAD_RUNNABLE
,
457
THREAD_STOPPED
,
458
THREAD_STOPPED_FOREVER
,
459
THREAD_KILLED
460
};
461
462
typedef
RUBY_JMP_BUF
rb_jmpbuf_t
;
463
464
struct
rb_vm_tag
{
465
rb_jmpbuf_t
buf
;
466
VALUE
tag
;
467
VALUE
retval
;
468
struct
rb_vm_tag
*
prev
;
469
};
470
471
struct
rb_vm_protect_tag
{
472
struct
rb_vm_protect_tag
*
prev
;
473
};
474
475
struct
rb_unblock_callback
{
476
rb_unblock_function_t
*
func
;
477
void
*
arg
;
478
};
479
480
struct
rb_mutex_struct
;
481
482
struct
rb_thread_struct
;
483
typedef
struct
rb_thread_list_struct
{
484
struct
rb_thread_list_struct
*
next
;
485
struct
rb_thread_struct
*
th
;
486
}
rb_thread_list_t
;
487
488
489
typedef
struct
rb_thread_struct
{
490
VALUE
self
;
491
rb_vm_t
*
vm
;
492
493
/* execution information */
494
VALUE
*
stack
;
/* must free, must mark */
495
size_t
stack_size
;
/* size in word (byte size / sizeof(VALUE)) */
496
rb_control_frame_t
*
cfp
;
497
int
safe_level
;
498
int
raised_flag
;
499
VALUE
last_status
;
/* $? */
500
501
/* passing state */
502
int
state
;
503
504
int
waiting_fd
;
505
506
/* for rb_iterate */
507
const
rb_block_t
*
passed_block
;
508
509
/* for bmethod */
510
const
rb_method_entry_t
*
passed_me
;
511
512
/* for cfunc */
513
rb_call_info_t
*
passed_ci
;
514
515
/* for load(true) */
516
VALUE
top_self
;
517
VALUE
top_wrapper
;
518
519
/* eval env */
520
rb_block_t
*
base_block
;
521
522
VALUE
*
root_lep
;
523
VALUE
root_svar
;
524
525
/* thread control */
526
rb_thread_id_t
thread_id
;
527
enum
rb_thread_status
status
;
528
int
to_kill
;
529
int
priority
;
530
531
native_thread_data_t
native_thread_data
;
532
void
*
blocking_region_buffer
;
533
534
VALUE
thgroup
;
535
VALUE
value
;
536
537
/* temporary place of errinfo */
538
VALUE
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 */
546
VALUE
pending_interrupt_queue
;
547
int
pending_interrupt_queue_checked
;
548
VALUE
pending_interrupt_mask_stack
;
549
550
rb_atomic_t
interrupt_flag
;
551
unsigned
long
interrupt_mask
;
552
rb_thread_lock_t
interrupt_lock
;
553
struct
rb_unblock_callback
unblock
;
554
VALUE
locking_mutex
;
555
struct
rb_mutex_struct
*
keeping_mutexes
;
556
557
struct
rb_vm_tag
*
tag
;
558
struct
rb_vm_protect_tag
*
protect_tag
;
559
566
int
parse_in_eval
;
567
572
int
mild_compile_error
;
573
574
/* storage */
575
st_table
*
local_storage
;
576
577
rb_thread_list_t
*
join_list
;
578
579
VALUE
first_proc
;
580
VALUE
first_args
;
581
VALUE
(*
first_func
)(
ANYARGS
);
582
583
/* for GC */
584
VALUE
*
machine_stack_start
;
585
VALUE
*
machine_stack_end
;
586
size_t
machine_stack_maxsize
;
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
;
593
int
mark_stack_len
;
594
595
/* statistics data for profiler */
596
VALUE
stat_insn_usage
;
597
598
/* tracer */
599
rb_hook_list_t
event_hooks
;
600
struct
rb_trace_arg_struct
*
trace_arg
;
/* trace information */
601
602
/* fiber */
603
VALUE
fiber
;
604
VALUE
root_fiber
;
605
rb_jmpbuf_t
root_jmpbuf
;
606
607
/* misc */
608
int
method_missing_reason
;
609
int
abort_on_exception
;
610
#ifdef USE_SIGALTSTACK
611
void
*altstack;
612
#endif
613
unsigned
long
running_time_us
;
614
}
rb_thread_t
;
615
616
typedef
enum
{
617
VM_DEFINECLASS_TYPE_CLASS
= 0x00,
618
VM_DEFINECLASS_TYPE_SINGLETON_CLASS
= 0x01,
619
VM_DEFINECLASS_TYPE_MODULE
= 0x02,
620
/* 0x03..0x06 is reserved */
621
VM_DEFINECLASS_TYPE_MASK
= 0x07,
622
}
rb_vm_defineclass_type_t
;
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);
640
VALUE
rb_iseq_new_with_bopt
(
NODE
*,
VALUE
,
VALUE
,
VALUE
,
VALUE
,
VALUE
,
enum
iseq_type,
VALUE
);
641
VALUE
rb_iseq_new_with_opt
(
NODE
*,
VALUE
,
VALUE
,
VALUE
,
VALUE
,
VALUE
,
enum
iseq_type,
const
rb_compile_option_t
*);
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
648
VALUE
rb_iseq_disasm
(
VALUE
self
);
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
653
RUBY_EXTERN
VALUE
rb_cISeq
;
654
RUBY_EXTERN
VALUE
rb_cRubyVM
;
655
RUBY_EXTERN
VALUE
rb_cEnv
;
656
RUBY_EXTERN
VALUE
rb_mRubyVMFrozenCore
;
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
{
665
rb_block_t
block
;
666
667
VALUE
envval
;
/* for GC mark */
668
VALUE
blockprocval
;
669
int
safe_level
;
670
int
is_from_method
;
671
int
is_lambda
;
672
}
rb_proc_t
;
673
674
#define GetEnvPtr(obj, ptr) \
675
GetCoreDataFromValue((obj), rb_env_t, (ptr))
676
677
typedef
struct
{
678
VALUE
*
env
;
679
int
env_size
;
680
int
local_size
;
681
VALUE
prev_envval
;
/* for GC mark */
682
rb_block_t
block
;
683
}
rb_env_t
;
684
685
#define GetBindingPtr(obj, ptr) \
686
GetCoreDataFromValue((obj), rb_binding_t, (ptr))
687
688
typedef
struct
{
689
VALUE
env
;
690
VALUE
path
;
691
unsigned
short
first_lineno
;
692
}
rb_binding_t
;
693
694
/* used by compile time and send insn */
695
696
enum
vm_check_match_type
{
697
VM_CHECKMATCH_TYPE_WHEN
= 1,
698
VM_CHECKMATCH_TYPE_CASE
= 2,
699
VM_CHECKMATCH_TYPE_RESCUE
= 3
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
714
enum
vm_special_object_type
{
715
VM_SPECIAL_OBJECT_VMCORE
= 1,
716
VM_SPECIAL_OBJECT_CBASE
,
717
VM_SPECIAL_OBJECT_CONST_BASE
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
;
744
typedef
rb_call_info_t
*
CALL_INFO
;
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
*
755
(
FUNC_FASTCALL
(*
rb_insn_func_t
))(
rb_thread_t
*,
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
780
VALUE
*
rb_vm_ep_local_ep
(
VALUE
*ep);
781
rb_block_t
*
rb_vm_control_frame_block_ptr
(
rb_control_frame_t
*cfp);
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 */
802
VALUE
rb_thread_alloc
(
VALUE
klass);
803
VALUE
rb_proc_alloc
(
VALUE
klass);
804
805
/* for debug */
806
extern
void
rb_vmdebug_stack_dump_raw
(
rb_thread_t
*,
rb_control_frame_t
*);
807
extern
void
rb_vmdebug_debug_print_pre
(
rb_thread_t
*th,
rb_control_frame_t
*cfp);
808
extern
void
rb_vmdebug_debug_print_post
(
rb_thread_t
*th,
rb_control_frame_t
*cfp);
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
825
VALUE
rb_vm_invoke_proc
(
rb_thread_t
*th,
rb_proc_t
*proc,
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);
828
VALUE
rb_vm_make_env_object
(
rb_thread_t
*th,
rb_control_frame_t
*cfp);
829
VALUE
rb_binding_new_with_cfp
(
rb_thread_t
*th,
const
rb_control_frame_t
*src_cfp);
830
void
rb_vm_inc_const_missing_count
(
void
);
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);
835
void
rb_unlink_method_entry
(
rb_method_entry_t
*me);
836
void
rb_gc_mark_unlinked_live_method_entries
(
void
*pvm);
837
838
void
rb_thread_start_timer_thread
(
void
);
839
void
rb_thread_stop_timer_thread
(
int
);
840
void
rb_thread_reset_timer_thread
(
void
);
841
void
rb_thread_wakeup_timer_thread
(
void
);
842
843
int
ruby_thread_has_gvl_p
(
void
);
844
typedef
int
rb_backtrace_iter_func
(
void
*,
VALUE
,
int
,
VALUE
);
845
rb_control_frame_t
*
rb_vm_get_ruby_level_next_cfp
(
rb_thread_t
*th,
const
rb_control_frame_t
*cfp);
846
rb_control_frame_t
*
rb_vm_get_binding_creatable_next_cfp
(
rb_thread_t
*th,
const
rb_control_frame_t
*cfp);
847
int
rb_vm_get_sourceline
(
const
rb_control_frame_t
*);
848
VALUE
rb_name_err_mesg_new
(
VALUE
obj,
VALUE
mesg,
VALUE
recv,
VALUE
method);
849
void
rb_vm_stack_to_heap
(
rb_thread_t
*th);
850
void
ruby_thread_init_stack
(
rb_thread_t
*th);
851
int
rb_vm_control_frame_id_and_class
(
const
rb_control_frame_t
*cfp,
ID
*idp,
VALUE
*klassp);
852
853
void
rb_gc_mark_machine_stack
(
rb_thread_t
*th);
854
855
int
rb_autoloading_value
(
VALUE
mod
,
ID
id
,
VALUE
*
value
);
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
868
extern
rb_thread_t
*
ruby_current_thread
;
869
extern
rb_vm_t
*
ruby_current_vm
;
870
extern
rb_event_flag_t
ruby_vm_event_flags
;
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
*
879
GET_THREAD
(
void
)
880
{
881
rb_thread_t
*th =
ruby_current_thread
;
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
{
905
TIMER_INTERRUPT_MASK
= 0x01,
906
PENDING_INTERRUPT_MASK
= 0x02,
907
FINALIZER_INTERRUPT_MASK
= 0x04,
908
TRAP_INTERRUPT_MASK
= 0x08
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);
920
void
rb_threadptr_check_signal
(
rb_thread_t
*mth);
921
void
rb_threadptr_signal_raise
(
rb_thread_t
*th,
int
sig);
922
void
rb_threadptr_signal_exit
(
rb_thread_t
*th);
923
void
rb_threadptr_execute_interrupts
(
rb_thread_t
*,
int
);
924
void
rb_threadptr_interrupt
(
rb_thread_t
*th);
925
void
rb_threadptr_unlock_all_locking_mutexes
(
rb_thread_t
*th);
926
void
rb_threadptr_pending_interrupt_clear
(
rb_thread_t
*th);
927
void
rb_threadptr_pending_interrupt_enque
(
rb_thread_t
*th,
VALUE
v
);
928
int
rb_threadptr_pending_interrupt_active_p
(
rb_thread_t
*th);
929
930
void
rb_thread_lock_unlock
(
rb_thread_lock_t
*);
931
void
rb_thread_lock_destroy
(
rb_thread_lock_t
*);
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 */
951
struct
rb_trace_arg_struct
{
952
rb_event_flag_t
event
;
953
rb_thread_t
*
th
;
954
rb_control_frame_t
*
cfp
;
955
VALUE
self
;
956
ID
id
;
957
VALUE
klass
;
958
VALUE
data
;
959
960
int
klass_solved
;
961
962
/* calc from cfp */
963
int
lineno
;
964
VALUE
path
;
965
};
966
967
void
rb_threadptr_exec_event_hooks
(
struct
rb_trace_arg_struct
*trace_arg);
968
void
rb_threadptr_exec_event_hooks_and_pop_frame
(
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
999
int
rb_thread_check_trap_pending
(
void
);
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
Generated by
1.8.3.1