2006-12-31 10:02:22 -05:00
|
|
|
/**********************************************************************
|
|
|
|
|
2008-12-09 02:17:10 -05:00
|
|
|
vm_core.h -
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: 04/01/01 19:41:38 JST
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
Copyright (C) 2004-2007 Koichi Sasada
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2008-01-18 03:56:11 -05:00
|
|
|
#ifndef RUBY_VM_CORE_H
|
|
|
|
#define RUBY_VM_CORE_H
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
#define RUBY_VM_THREAD_MODEL 2
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/st.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* include/ruby/node.h, node.h: move node.h from include path.
This change stop to install node.h beacuase of saving ABI
(node.h will be changed. Extensions should not depends on
this file).
* blockinlining.c, class.c, compile.c, debug.h, enum.c,
gc.c, iseq.c, parse.y, ruby.c, signal.c, variable.c,
vm.c, vm_core.h, vm_dump.c: ditto.
* ext/ripper/depend: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 15:52:31 -04:00
|
|
|
#include "node.h"
|
2012-11-20 07:57:49 -05:00
|
|
|
#include "vm_debug.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
#include "vm_opts.h"
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
#include "id.h"
|
2009-07-15 10:59:41 -04:00
|
|
|
#include "method.h"
|
2012-11-09 11:05:07 -05:00
|
|
|
#include "ruby_atomic.h"
|
vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table. I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:
1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
(0002 patch in Feature 9632 will introduce a secondary list
for waiting FDs)
This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.
vm_thread_close 1.762
* vm_core.h (rb_vm_t): list_head and counter for living_threads
(rb_thread_t): vmlt_node for living_threads linkage
(rb_vm_living_threads_init): new function wrapper
(rb_vm_living_threads_insert): ditto
(rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
[ruby-core:61871][Feature 9632 (part 1)]
Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 19:48:51 -04:00
|
|
|
#include "ccan/list/list.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2014-05-14 06:55:38 -04:00
|
|
|
#include "ruby/thread_native.h"
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include "thread_win32.h"
|
|
|
|
#elif defined(HAVE_PTHREAD_H)
|
|
|
|
#include "thread_pthread.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-18 03:29:17 -04:00
|
|
|
#ifndef ENABLE_VM_OBJSPACE
|
2009-09-19 04:46:48 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
/*
|
2010-08-02 11:53:48 -04:00
|
|
|
* TODO: object space independent st_table.
|
2009-09-19 04:46:48 -04:00
|
|
|
* socklist needs st_table in rb_w32_sysinit(), before object space
|
|
|
|
* initialization.
|
|
|
|
* It is too early now to change st_hash_type, since it breaks binary
|
|
|
|
* compatibility.
|
|
|
|
*/
|
|
|
|
#define ENABLE_VM_OBJSPACE 0
|
|
|
|
#else
|
2009-09-18 03:29:17 -04:00
|
|
|
#define ENABLE_VM_OBJSPACE 1
|
|
|
|
#endif
|
2009-09-19 04:46:48 -04:00
|
|
|
#endif
|
2009-09-18 03:29:17 -04:00
|
|
|
|
2008-09-23 18:43:53 -04:00
|
|
|
#include <setjmp.h>
|
2006-12-31 10:02:22 -05:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#ifndef NSIG
|
2008-10-04 09:42:00 -04:00
|
|
|
# define NSIG (_SIGMAX + 1) /* For QNX */
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RUBY_NSIG NSIG
|
|
|
|
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 03:49:45 -04:00
|
|
|
#ifdef HAVE_STDARG_PROTOTYPES
|
|
|
|
#include <stdarg.h>
|
2011-01-21 10:54:58 -05:00
|
|
|
#define va_init_list(a,b) va_start((a),(b))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 03:49:45 -04:00
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
2011-01-21 10:54:58 -05:00
|
|
|
#define va_init_list(a,b) va_start((a))
|
* include/ruby/node.h, vm_core.h: move definition of
RUBY_VM_METHOD_NODE to node.h.
* class.c, common.mk: remove useless inclusion.
* compile.h, iseq.h, vm_core.h: rename compile.h to iseq.h.
move some definitions from vm_core.h to iseq.h.
* compile.c, iseq.c, vm.c: ditto.
* eval.c, compile.c: move some functions for parser
from eval.c to compile.c.
* eval_intern.h, vm_core.h: move va_init_list() macro to
vm_core.h.
* iseq.c (rb_iseq_new_top, rb_iseq_first_lineno): added.
* load.c, ruby.c: use rb_iseq_new_top() instead of
rb_iseq_new() with ISEQ_TYPE_TOP constant directly.
* proc.c: use rb_iseq_first_lineno() instead of accessing
iseq structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 03:49:45 -04:00
|
|
|
#endif
|
|
|
|
|
2010-05-13 12:20:26 -04:00
|
|
|
#if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
|
|
|
|
#define USE_SIGALTSTACK
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/*****************/
|
|
|
|
/* configuration */
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
/* gcc ver. check */
|
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 2
|
|
|
|
|
|
|
|
#if OPT_TOKEN_THREADED_CODE
|
|
|
|
#if OPT_DIRECT_THREADED_CODE
|
|
|
|
#undef OPT_DIRECT_THREADED_CODE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* defined(__GNUC__) && __GNUC__ >= 2 */
|
|
|
|
|
|
|
|
/* disable threaded code options */
|
|
|
|
#if OPT_DIRECT_THREADED_CODE
|
|
|
|
#undef OPT_DIRECT_THREADED_CODE
|
|
|
|
#endif
|
|
|
|
#if OPT_TOKEN_THREADED_CODE
|
|
|
|
#undef OPT_TOKEN_THREADED_CODE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 22:48:59 -04:00
|
|
|
#ifdef __native_client__
|
|
|
|
#undef OPT_DIRECT_THREADED_CODE
|
|
|
|
#endif
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* call threaded code */
|
|
|
|
#if OPT_CALL_THREADED_CODE
|
|
|
|
#if OPT_DIRECT_THREADED_CODE
|
|
|
|
#undef OPT_DIRECT_THREADED_CODE
|
|
|
|
#endif /* OPT_DIRECT_THREADED_CODE */
|
|
|
|
#if OPT_STACK_CACHING
|
|
|
|
#undef OPT_STACK_CACHING
|
|
|
|
#endif /* OPT_STACK_CACHING */
|
|
|
|
#endif /* OPT_CALL_THREADED_CODE */
|
|
|
|
|
2008-05-22 23:23:08 -04:00
|
|
|
typedef unsigned long rb_num_t;
|
|
|
|
|
2009-07-15 10:59:41 -04:00
|
|
|
/* iseq data type */
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
struct iseq_compile_data_ensure_node_stack;
|
|
|
|
|
2010-10-30 21:42:54 -04:00
|
|
|
typedef struct rb_compile_option_struct rb_compile_option_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2013-08-20 13:41:13 -04:00
|
|
|
|
2009-07-13 05:30:23 -04:00
|
|
|
struct iseq_inline_cache_entry {
|
2013-11-08 22:46:48 -05:00
|
|
|
rb_serial_t ic_serial;
|
2009-09-12 13:16:27 -04:00
|
|
|
union {
|
2013-08-20 13:41:13 -04:00
|
|
|
size_t index;
|
2009-09-12 13:16:27 -04:00
|
|
|
VALUE value;
|
|
|
|
} ic_value;
|
2009-07-13 05:30:23 -04:00
|
|
|
};
|
|
|
|
|
2013-08-20 13:41:13 -04:00
|
|
|
union iseq_inline_storage_entry {
|
|
|
|
struct {
|
|
|
|
struct rb_thread_struct *running_thread;
|
|
|
|
VALUE value;
|
|
|
|
} once;
|
|
|
|
struct iseq_inline_cache_entry cache;
|
|
|
|
};
|
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
/* to avoid warning */
|
|
|
|
struct rb_thread_struct;
|
|
|
|
struct rb_control_frame_struct;
|
|
|
|
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 13:02:55 -05:00
|
|
|
typedef struct rb_call_info_kw_arg_struct {
|
|
|
|
int keyword_len;
|
|
|
|
ID keywords[1];
|
|
|
|
} rb_call_info_kw_arg_t;
|
|
|
|
|
2012-10-09 01:33:54 -04:00
|
|
|
/* rb_call_info_t contains calling information including inline cache */
|
|
|
|
typedef struct rb_call_info_struct {
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
/* fixed at compile time */
|
|
|
|
ID mid;
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 13:02:55 -05:00
|
|
|
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:32:44 -04:00
|
|
|
unsigned int flag;
|
2014-07-13 03:46:46 -04:00
|
|
|
int orig_argc;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:32:44 -04:00
|
|
|
rb_iseq_t *blockiseq;
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 13:02:55 -05:00
|
|
|
rb_call_info_kw_arg_t *kw_arg;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
|
2012-10-09 01:33:54 -04:00
|
|
|
/* inline cache: keys */
|
2013-12-09 05:51:02 -05:00
|
|
|
rb_serial_t method_state;
|
2013-11-08 22:34:49 -05:00
|
|
|
rb_serial_t class_serial;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
VALUE klass;
|
2012-10-09 01:33:54 -04:00
|
|
|
|
|
|
|
/* inline cache: values */
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
const rb_method_entry_t *me;
|
2012-10-09 01:33:54 -04:00
|
|
|
VALUE defined_class;
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
|
|
|
|
/* temporary values for method calling */
|
|
|
|
struct rb_block_struct *blockptr;
|
|
|
|
VALUE recv;
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:32:44 -04:00
|
|
|
int argc;
|
2012-10-16 13:07:23 -04:00
|
|
|
union {
|
|
|
|
int opt_pc; /* used by iseq */
|
rb_call_info_t: shrink to 96 bytes from 104 bytes on 64-bit
This keeps ci->flag and ci->aux.index consistent across 32-bit
and 64-bit platforms.
ci->flag: VM_CALL_* flags only use 9 bits, currently
ci->aux.index: 2 billion ivars per class should be enough for anybody
This saves around 50K allocations on "valgrind ruby -e exit" on x86-64
before:
total heap usage: 48,122 allocs, 19,253 frees, 8,099,197 bytes allocated
after:
total heap usage: 48,069 allocs, 19,214 frees, 8,047,266 bytes allocated
* vm_core.h (rb_call_info_t): ci->flag becomes 32-bit unsigned int
ci->index becomes a 32-bit signed int (from signed long).
Reorder for better packing on 64-bit, giving an 8 byte reduction
from 104 to 96 bytes for each ci.
* compile.c (new_callinfo, setup_args, iseq_compile_each,
iseq_build_from_ary_body): adjust for type changes
* vm_insnhelper.c (vm_getivar): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:32:44 -04:00
|
|
|
int index; /* used by ivar */
|
2012-10-17 03:12:40 -04:00
|
|
|
int missing_reason; /* used by method_missing */
|
* vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'.
This optimization makes all cfunc method calls `frameless', which
is fster than ordinal cfunc method call.
If `frame' is needed (for example, it calls another method with
`rb_funcall()'), then build a frame. In other words, this
optimization delays frame building.
However, to delay the frame building, we need additional overheads:
(1) Store the last call information.
(2) Check the delayed frame buidling before the frame is needed.
(3) Overhead to build a delayed frame.
rb_thread_t::passed_ci is storage of delayed cfunc call information.
(1) is lightweight because it is only 1 assignment to `passed_ci'.
To achieve (2), we modify GET_THREAD() to check `passed_ci' every
time. It causes 10% overhead on my envrionment.
This optimization only works for cfunc methods which do not need
their `frame'.
After evaluation on my environment, this optimization does not
effective every time. Because of this evaluation results, this
optimization is disabled at default.
* vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour
of VM internals. I will extend this feature.
* vm_method.c, method.h: change parameters of the `invoker' function.
Receive `func' pointer as the first parameter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 00:22:31 -04:00
|
|
|
int inc_sp; /* used by cfunc */
|
2012-10-16 13:07:23 -04:00
|
|
|
} aux;
|
2012-10-14 15:58:59 -04:00
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
VALUE (*call)(struct rb_thread_struct *th, struct rb_control_frame_struct *cfp, struct rb_call_info_struct *ci);
|
2012-10-09 01:33:54 -04:00
|
|
|
} rb_call_info_t;
|
|
|
|
|
2007-06-24 14:40:13 -04:00
|
|
|
#if 1
|
|
|
|
#define GetCoreDataFromValue(obj, type, ptr) do { \
|
2011-01-21 10:54:58 -05:00
|
|
|
(ptr) = (type*)DATA_PTR(obj); \
|
2007-06-24 14:40:13 -04:00
|
|
|
} while (0)
|
|
|
|
#else
|
2011-01-21 10:54:58 -05:00
|
|
|
#define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
|
2007-06-24 14:40:13 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GetISeqPtr(obj, ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-06-03 22:49:37 -04:00
|
|
|
typedef struct rb_iseq_location_struct {
|
2013-06-19 02:26:01 -04:00
|
|
|
const VALUE path;
|
|
|
|
const VALUE absolute_path;
|
|
|
|
const VALUE base_label;
|
|
|
|
const VALUE label;
|
2014-08-24 22:24:10 -04:00
|
|
|
VALUE first_lineno; /* TODO: may be unsigned short */
|
2012-06-03 22:49:37 -04:00
|
|
|
} rb_iseq_location_t;
|
2012-05-22 04:31:38 -04:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_iseq_struct;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_iseq_struct {
|
2007-06-30 14:04:35 -04:00
|
|
|
/***************/
|
|
|
|
/* static data */
|
|
|
|
/***************/
|
|
|
|
|
2010-10-30 21:42:54 -04:00
|
|
|
enum iseq_type {
|
|
|
|
ISEQ_TYPE_TOP,
|
|
|
|
ISEQ_TYPE_METHOD,
|
|
|
|
ISEQ_TYPE_BLOCK,
|
|
|
|
ISEQ_TYPE_CLASS,
|
|
|
|
ISEQ_TYPE_RESCUE,
|
|
|
|
ISEQ_TYPE_ENSURE,
|
|
|
|
ISEQ_TYPE_EVAL,
|
|
|
|
ISEQ_TYPE_MAIN,
|
2010-12-09 21:42:06 -05:00
|
|
|
ISEQ_TYPE_DEFINED_GUARD
|
2010-10-30 21:42:54 -04:00
|
|
|
} type; /* instruction sequence type */
|
2014-07-16 07:04:01 -04:00
|
|
|
#if defined(WORDS_BIGENDIAN) && (SIZEOF_VALUE > SIZEOF_INT)
|
|
|
|
char dummy[SIZEOF_VALUE - SIZEOF_INT]; /* [Bug #10037][ruby-core:63721] */
|
|
|
|
#endif
|
2014-07-16 07:46:06 -04:00
|
|
|
int stack_max; /* for stack overflow check */
|
2010-10-30 21:42:54 -04:00
|
|
|
|
2012-06-03 22:49:37 -04:00
|
|
|
rb_iseq_location_t location;
|
2012-05-22 04:31:38 -04:00
|
|
|
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:14:07 -04:00
|
|
|
VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
|
2014-07-26 03:30:26 -04:00
|
|
|
unsigned int iseq_size;
|
|
|
|
unsigned int line_info_size;
|
|
|
|
|
2013-06-19 02:26:01 -04:00
|
|
|
const VALUE mark_ary; /* Array: includes operands which should be GC marked */
|
|
|
|
const VALUE coverage; /* coverage array */
|
2012-05-22 09:20:52 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* insn info, must be freed */
|
2011-08-24 02:31:15 -04:00
|
|
|
struct iseq_line_info_entry *line_info_table;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-02-24 20:34:33 -05:00
|
|
|
ID *local_table; /* must free */
|
|
|
|
int local_table_size;
|
|
|
|
|
2013-01-24 22:03:50 -05:00
|
|
|
/* sizeof(vars) + 1 */
|
2008-12-09 02:17:10 -05:00
|
|
|
int local_size;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2013-08-20 13:41:13 -04:00
|
|
|
union iseq_inline_storage_entry *is_entries;
|
|
|
|
int is_size;
|
2009-07-13 05:30:23 -04:00
|
|
|
|
2012-10-09 01:33:54 -04:00
|
|
|
int callinfo_size;
|
2014-07-14 03:42:13 -04:00
|
|
|
rb_call_info_t *callinfo_entries;
|
2012-10-09 01:33:54 -04:00
|
|
|
|
2007-04-24 23:50:00 -04:00
|
|
|
/**
|
2014-11-02 18:14:21 -05:00
|
|
|
* parameter information
|
2007-04-24 23:50:00 -04:00
|
|
|
*
|
2007-06-30 14:04:35 -04:00
|
|
|
* def m(a1, a2, ..., aM, # mandatory
|
2010-08-02 11:53:48 -04:00
|
|
|
* b1=(...), b2=(...), ..., bN=(...), # optional
|
2007-06-30 14:04:35 -04:00
|
|
|
* *c, # rest
|
|
|
|
* d1, d2, ..., dO, # post
|
2012-12-11 16:44:49 -05:00
|
|
|
* e1:(...), e2:(...), ..., eK:(...), # keyword
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 13:02:55 -05:00
|
|
|
* **f, # keyword_rest
|
2012-12-11 16:44:49 -05:00
|
|
|
* &g) # block
|
2007-04-24 23:50:00 -04:00
|
|
|
* =>
|
|
|
|
*
|
2014-11-02 18:14:21 -05:00
|
|
|
* lead_num = M
|
2014-11-02 23:43:07 -05:00
|
|
|
* opt_num = N
|
2014-11-02 18:14:21 -05:00
|
|
|
* rest_start = M+N
|
|
|
|
* post_start = M+N+(*1)
|
|
|
|
* post_num = O
|
|
|
|
* keyword_num = K
|
|
|
|
* block_start = M+N+(*1)+O+K
|
|
|
|
* keyword_bits = M+N+(*1)+O+K+(&1)
|
|
|
|
* size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
|
2007-04-24 23:50:00 -04:00
|
|
|
*/
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2014-11-02 18:14:21 -05:00
|
|
|
struct {
|
|
|
|
struct {
|
|
|
|
unsigned int has_lead : 1;
|
|
|
|
unsigned int has_opt : 1;
|
|
|
|
unsigned int has_rest : 1;
|
|
|
|
unsigned int has_post : 1;
|
|
|
|
unsigned int has_kw : 1;
|
|
|
|
unsigned int has_kwrest : 1;
|
|
|
|
unsigned int has_block : 1;
|
|
|
|
|
|
|
|
unsigned int ambiguous_param0 : 1; /* {|a|} */
|
|
|
|
} flags;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
int lead_num;
|
|
|
|
int opt_num;
|
|
|
|
int rest_start;
|
|
|
|
int post_start;
|
|
|
|
int post_num;
|
|
|
|
int block_start;
|
|
|
|
|
2014-11-02 23:43:07 -05:00
|
|
|
VALUE *opt_table; /* (opt_num + 1) entries. */
|
|
|
|
/* opt_num and opt_table:
|
|
|
|
*
|
|
|
|
* def foo o1=e1, o2=e2, ..., oN=eN
|
|
|
|
* #=>
|
|
|
|
* # prologue code
|
|
|
|
* A1: e1
|
|
|
|
* A2: e2
|
|
|
|
* ...
|
|
|
|
* AN: eN
|
|
|
|
* AL: body
|
|
|
|
* opt_num = N
|
|
|
|
* opt_table = [A1, A2, ..., AN, AL]
|
|
|
|
*/
|
2014-11-02 18:14:21 -05:00
|
|
|
|
|
|
|
struct rb_iseq_param_keyword {
|
|
|
|
int num;
|
|
|
|
int required_num;
|
|
|
|
int bits_start;
|
|
|
|
int rest_start;
|
|
|
|
ID *table;
|
|
|
|
VALUE *default_values;
|
|
|
|
} *keyword;
|
|
|
|
} param;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* catch table */
|
2014-07-14 03:06:26 -04:00
|
|
|
struct iseq_catch_table *catch_table;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* for child iseq */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_iseq_struct *parent_iseq;
|
|
|
|
struct rb_iseq_struct *local_iseq;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-06-30 14:04:35 -04:00
|
|
|
/****************/
|
|
|
|
/* dynamic data */
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
VALUE self;
|
2013-06-19 02:26:01 -04:00
|
|
|
const VALUE orig; /* non-NULL if its data have origin */
|
2007-06-30 14:04:35 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* block inlining */
|
2008-12-09 02:17:10 -05:00
|
|
|
/*
|
2007-12-24 21:17:16 -05:00
|
|
|
* NODE *node;
|
|
|
|
* void *special_block_builder;
|
|
|
|
* void *cached_special_block_builder;
|
|
|
|
* VALUE cached_special_block;
|
|
|
|
*/
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-06-30 14:04:35 -04:00
|
|
|
/* klass/module nest information stack (cref) */
|
2013-06-19 02:26:01 -04:00
|
|
|
NODE * const cref_stack;
|
|
|
|
const VALUE klass;
|
2007-06-30 14:04:35 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* misc */
|
|
|
|
ID defined_method_id; /* for define_method */
|
2013-01-08 00:41:44 -05:00
|
|
|
rb_num_t flip_cnt;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
|
2007-06-30 14:04:35 -04:00
|
|
|
/* used at compile time */
|
2006-12-31 10:02:22 -05:00
|
|
|
struct iseq_compile_data *compile_data;
|
compile: translate iseq in-place
running "ruby -rpp -e 'pp GC.stat'", a reduction in
malloc usage is shown:
before:
:malloc_increase=>118784,
:oldmalloc_increase=>1178736,
after:
:malloc_increase=>99832,
:oldmalloc_increase=>1031976,
For "ruby -e exit", valgrind reports over 300K reduction in
overall allocations (and unnecessary memory copies).
before:
total heap usage: 49,622 allocs, 20,492 frees, 8,697,493 bytes allocated
after:
total heap usage: 48,935 allocs, 19,805 frees, 8,373,773 bytes allocated
(numbers from x86-64)
v2 changes based on ko1 recommendations [ruby-core:64883]:
- squashed in-place direct thread translation to avoid alloc+copy
- renamed rb_iseq_untranslate_threaded_code to rb_iseq_original_iseq,
cache new iseq->iseq_original field.
* compile.c (rb_iseq_translate_threaded_code): modify in-place w/o copy
(rb_vm_addr2insn): new function for debug
(rb_iseq_original_iseq): ditto
(iseq_set_sequence): assign iseq_encoded directly
[Feature #10185]
* vm_core (rb_iseq_t): move original ->iseq to bottom
* iseq.c (iseq_free, iseq_free): adjust for new layout
(rb_iseq_disasm): use original iseq for dump
(iseq_data_to_ary): ditto
(rb_iseq_line_trace_each): ditto
(rb_iseq_build_for_ruby2cext): use iseq_encoded directly
* vm_dump.c (rb_vmdebug_debug_print_pre): use original iseq
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-10 02:14:07 -04:00
|
|
|
|
|
|
|
/* original iseq, before encoding
|
|
|
|
* used for debug/dump (TODO: union with compile_data) */
|
|
|
|
VALUE *iseq;
|
2006-12-31 10:02:22 -05:00
|
|
|
};
|
|
|
|
|
2008-06-15 05:17:06 -04:00
|
|
|
enum ruby_special_exceptions {
|
|
|
|
ruby_error_reenter,
|
|
|
|
ruby_error_nomemory,
|
|
|
|
ruby_error_sysstack,
|
2011-02-12 00:44:23 -05:00
|
|
|
ruby_error_closed_stream,
|
2008-06-15 05:17:06 -04:00
|
|
|
ruby_special_error_count
|
|
|
|
};
|
|
|
|
|
2014-07-17 21:53:18 -04:00
|
|
|
enum ruby_basic_operators {
|
|
|
|
BOP_PLUS,
|
|
|
|
BOP_MINUS,
|
|
|
|
BOP_MULT,
|
|
|
|
BOP_DIV,
|
|
|
|
BOP_MOD,
|
|
|
|
BOP_EQ,
|
|
|
|
BOP_EQQ,
|
|
|
|
BOP_LT,
|
|
|
|
BOP_LE,
|
|
|
|
BOP_LTLT,
|
|
|
|
BOP_AREF,
|
|
|
|
BOP_ASET,
|
|
|
|
BOP_LENGTH,
|
|
|
|
BOP_SIZE,
|
|
|
|
BOP_EMPTY_P,
|
|
|
|
BOP_SUCC,
|
|
|
|
BOP_GT,
|
|
|
|
BOP_GE,
|
|
|
|
BOP_NOT,
|
|
|
|
BOP_NEQ,
|
|
|
|
BOP_MATCH,
|
|
|
|
BOP_FREEZE,
|
|
|
|
|
|
|
|
BOP_LAST_
|
|
|
|
};
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define GetVMPtr(obj, ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
GetCoreDataFromValue((obj), rb_vm_t, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2009-09-18 03:29:17 -04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
|
|
|
struct rb_objspace;
|
|
|
|
void rb_objspace_free(struct rb_objspace *);
|
|
|
|
#endif
|
|
|
|
|
2012-08-16 07:41:24 -04:00
|
|
|
typedef struct rb_hook_list_struct {
|
|
|
|
struct rb_event_hook_struct *hooks;
|
|
|
|
rb_event_flag_t events;
|
|
|
|
int need_clean;
|
|
|
|
} rb_hook_list_t;
|
|
|
|
|
2008-10-21 16:59:23 -04:00
|
|
|
typedef struct rb_vm_struct {
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE self;
|
|
|
|
|
2010-11-27 15:15:59 -05:00
|
|
|
rb_global_vm_lock_t gvl;
|
2013-07-23 05:53:14 -04:00
|
|
|
rb_nativethread_lock_t thread_destruct_lock;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_thread_struct *main_thread;
|
|
|
|
struct rb_thread_struct *running_thread;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table. I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:
1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
(0002 patch in Feature 9632 will introduce a secondary list
for waiting FDs)
This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.
vm_thread_close 1.762
* vm_core.h (rb_vm_t): list_head and counter for living_threads
(rb_thread_t): vmlt_node for living_threads linkage
(rb_vm_living_threads_init): new function wrapper
(rb_vm_living_threads_insert): ditto
(rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
[ruby-core:61871][Feature 9632 (part 1)]
Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 19:48:51 -04:00
|
|
|
struct list_head living_threads;
|
|
|
|
size_t living_thread_num;
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE thgroup_default;
|
|
|
|
|
* eval_method.c: renamed from vm_method.c. "vm_method.c" is included
by "vm.c".
* vm_eval.c: added. Some codes are moved from "eval.c"
* common.mk: fix for above changes.
* compile.c: make a vm_eval(0)
* eval.c, eval_error.c, eval_intern.h, eval_jump.c, proc.c, vm.c,
id.c, id.h, vm_core.h, vm_dump.c, vm_evalbody.c, vm_insnhelper.c,
blockinlining.c: fix for above changes. and do some refactoring.
this changes improve rb_yield() performance.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-24 13:50:17 -04:00
|
|
|
int running;
|
2006-12-31 10:02:22 -05:00
|
|
|
int thread_abort_on_exception;
|
2012-10-21 06:14:26 -04:00
|
|
|
int trace_running;
|
2008-06-12 09:01:38 -04:00
|
|
|
volatile int sleeper;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* object management */
|
|
|
|
VALUE mark_object_ary;
|
|
|
|
|
2014-09-11 06:53:48 -04:00
|
|
|
const VALUE special_exceptions[ruby_special_error_count];
|
2008-06-15 05:17:06 -04:00
|
|
|
|
2007-02-13 21:19:02 -05:00
|
|
|
/* load */
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
VALUE top_self;
|
2008-04-30 05:03:03 -04:00
|
|
|
VALUE load_path;
|
2012-11-05 10:27:05 -05:00
|
|
|
VALUE load_path_snapshot;
|
2012-11-05 10:27:08 -05:00
|
|
|
VALUE load_path_check_cache;
|
2012-11-05 10:27:05 -05:00
|
|
|
VALUE expanded_load_path;
|
2007-02-13 21:19:02 -05:00
|
|
|
VALUE loaded_features;
|
2012-11-05 10:27:01 -05:00
|
|
|
VALUE loaded_features_snapshot;
|
2013-03-22 04:38:51 -04:00
|
|
|
struct st_table *loaded_features_index;
|
2007-05-03 09:19:11 -04:00
|
|
|
struct st_table *loading_table;
|
2008-12-09 02:17:10 -05:00
|
|
|
|
2007-02-13 21:19:02 -05:00
|
|
|
/* signal */
|
2014-07-16 06:16:34 -04:00
|
|
|
struct {
|
|
|
|
VALUE cmd;
|
|
|
|
int safe;
|
|
|
|
} trap_list[RUBY_NSIG];
|
2007-04-19 06:37:08 -04:00
|
|
|
|
|
|
|
/* hook */
|
2012-08-16 07:41:24 -04:00
|
|
|
rb_hook_list_t event_hooks;
|
2008-04-26 23:20:35 -04:00
|
|
|
|
2013-11-15 12:15:31 -05:00
|
|
|
/* relation table of ensure - rollback for callcc */
|
|
|
|
struct st_table *ensure_rollback_table;
|
|
|
|
|
2013-10-10 00:56:32 -04:00
|
|
|
/* postponed_job */
|
|
|
|
struct rb_postponed_job_struct *postponed_job_buffer;
|
|
|
|
int postponed_job_index;
|
2013-05-26 17:30:44 -04:00
|
|
|
|
2008-06-09 00:20:07 -04:00
|
|
|
int src_encoding_index;
|
|
|
|
|
2013-08-07 10:12:08 -04:00
|
|
|
VALUE verbose, debug, orig_progname, progname;
|
2008-07-03 08:55:12 -04:00
|
|
|
VALUE coverages;
|
2008-06-09 01:18:03 -04:00
|
|
|
|
2010-05-05 13:51:21 -04:00
|
|
|
struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
|
|
|
|
|
2013-10-11 14:27:18 -04:00
|
|
|
VALUE defined_module_hash;
|
|
|
|
|
2008-04-26 23:20:35 -04:00
|
|
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
|
|
|
struct rb_objspace *objspace;
|
|
|
|
#endif
|
2010-12-02 06:06:32 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @shyouhei notes that this is not for storing normal Ruby
|
|
|
|
* objects so do *NOT* mark this when you GC.
|
|
|
|
*/
|
|
|
|
struct RArray at_exit;
|
2012-09-24 04:36:53 -04:00
|
|
|
|
|
|
|
VALUE *defined_strings;
|
2014-08-29 02:30:03 -04:00
|
|
|
st_table *frozen_strings;
|
2012-12-19 17:29:18 -05:00
|
|
|
|
|
|
|
/* params */
|
|
|
|
struct { /* size in byte */
|
|
|
|
size_t thread_vm_stack_size;
|
|
|
|
size_t thread_machine_stack_size;
|
|
|
|
size_t fiber_vm_stack_size;
|
|
|
|
size_t fiber_machine_stack_size;
|
|
|
|
} default_params;
|
2014-07-17 21:53:18 -04:00
|
|
|
|
|
|
|
short redefined_flag[BOP_LAST_];
|
2008-10-21 16:59:23 -04:00
|
|
|
} rb_vm_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-12-19 17:29:18 -05:00
|
|
|
/* default values */
|
|
|
|
|
|
|
|
#define RUBY_VM_SIZE_ALIGN 4096
|
|
|
|
|
2012-12-25 02:29:36 -05:00
|
|
|
#define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
|
2012-12-19 17:29:18 -05:00
|
|
|
#define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
|
|
|
|
#define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
|
|
|
|
#define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
|
|
|
|
|
|
|
|
#define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
|
|
|
|
#define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
|
|
|
|
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
|
|
|
|
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
|
|
|
|
|
2014-07-17 21:53:18 -04:00
|
|
|
/* optimize insn */
|
|
|
|
#define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
|
|
|
|
#define FLOAT_REDEFINED_OP_FLAG (1 << 1)
|
|
|
|
#define STRING_REDEFINED_OP_FLAG (1 << 2)
|
|
|
|
#define ARRAY_REDEFINED_OP_FLAG (1 << 3)
|
|
|
|
#define HASH_REDEFINED_OP_FLAG (1 << 4)
|
|
|
|
#define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
|
|
|
|
#define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
|
|
|
|
#define TIME_REDEFINED_OP_FLAG (1 << 7)
|
|
|
|
#define REGEXP_REDEFINED_OP_FLAG (1 << 8)
|
|
|
|
|
|
|
|
#define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((GET_VM()->redefined_flag[(op)]&(klass)) == 0))
|
|
|
|
|
2012-09-28 00:05:36 -04:00
|
|
|
#ifndef VM_DEBUG_BP_CHECK
|
2013-01-10 08:03:39 -05:00
|
|
|
#define VM_DEBUG_BP_CHECK 0
|
2012-09-28 00:05:36 -04:00
|
|
|
#endif
|
|
|
|
|
2014-09-04 04:50:31 -04:00
|
|
|
#ifndef VM_DEBUG_VERIFY_METHOD_CACHE
|
|
|
|
#define VM_DEBUG_VERIFY_METHOD_CACHE 0
|
|
|
|
#endif
|
|
|
|
|
* insns.def (send, invokesuper, invokeblock, opt_*), vm_core.h:
use only a `ci' (rb_call_info_t) parameter instead of using
parameters such as `op_id', 'op_argc', `blockiseq' and flag.
These information are stored in rb_call_info_t at the compile
time.
This technique simplifies parameter passings at related
function calls (~10% speedups for simple mehtod invocation at
my machine).
`rb_call_info_t' also has new function pointer variable `call'.
This `call' variable enables to customize method (block)
invocation process for each place. However, it always call
`vm_call_general()' at this changes.
`rb_call_info_t' also has temporary variables for method
(block) invocation.
* vm_core.h, compile.c, insns.def: introduce VM_CALL_ARGS_SKIP_SETUP
VM_CALL macro. This flag indicates that this call can skip
caller_setup (block arg and splat arg).
* compile.c: catch up above changes.
* iseq.c: catch up above changes (especially for TS_CALLINFO).
* tool/instruction.rb: catch up above chagnes.
* vm_insnhelper.c, vm_insnhelper.h: ditto. Macros and functions
parameters are changed.
* vm_eval.c (vm_call0): ditto (it will be rewriten soon).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-14 12:59:05 -04:00
|
|
|
typedef struct rb_control_frame_struct {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
VALUE *pc; /* cfp[0] */
|
|
|
|
VALUE *sp; /* cfp[1] */
|
2012-09-28 00:05:36 -04:00
|
|
|
rb_iseq_t *iseq; /* cfp[2] */
|
|
|
|
VALUE flag; /* cfp[3] */
|
|
|
|
VALUE self; /* cfp[4] / block[0] */
|
|
|
|
VALUE klass; /* cfp[5] / block[1] */
|
|
|
|
VALUE *ep; /* cfp[6] / block[2] */
|
|
|
|
rb_iseq_t *block_iseq; /* cfp[7] / block[3] */
|
|
|
|
VALUE proc; /* cfp[8] / block[4] */
|
|
|
|
const rb_method_entry_t *me;/* cfp[9] */
|
|
|
|
|
|
|
|
#if VM_DEBUG_BP_CHECK
|
|
|
|
VALUE *bp_check; /* cfp[10] */
|
|
|
|
#endif
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
} rb_control_frame_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-06-09 11:52:51 -04:00
|
|
|
typedef struct rb_block_struct {
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE self; /* share with method frame if it's only block */
|
2012-08-02 07:08:44 -04:00
|
|
|
VALUE klass; /* share with method frame if it's only block */
|
2012-06-10 23:14:59 -04:00
|
|
|
VALUE *ep; /* share with method frame if it's only block */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_iseq_t *iseq;
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE proc;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
} rb_block_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2011-08-16 05:56:56 -04:00
|
|
|
extern const rb_data_type_t ruby_threadptr_data_type;
|
2011-02-04 11:05:40 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define GetThreadPtr(obj, ptr) \
|
2011-08-16 05:56:56 -04:00
|
|
|
TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
enum rb_thread_status {
|
2006-12-31 10:02:22 -05:00
|
|
|
THREAD_RUNNABLE,
|
|
|
|
THREAD_STOPPED,
|
2008-06-12 09:01:38 -04:00
|
|
|
THREAD_STOPPED_FOREVER,
|
2008-07-01 04:27:58 -04:00
|
|
|
THREAD_KILLED
|
2006-12-31 10:02:22 -05:00
|
|
|
};
|
|
|
|
|
2008-03-31 13:58:41 -04:00
|
|
|
typedef RUBY_JMP_BUF rb_jmpbuf_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2013-05-18 02:49:19 -04:00
|
|
|
/*
|
|
|
|
the members which are written in TH_PUSH_TAG() should be placed at
|
|
|
|
the beginning and the end, so that entire region is accessible.
|
|
|
|
*/
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_vm_tag {
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE tag;
|
|
|
|
VALUE retval;
|
2013-05-18 02:49:19 -04:00
|
|
|
rb_jmpbuf_t buf;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_vm_tag *prev;
|
2006-12-31 10:02:22 -05:00
|
|
|
};
|
|
|
|
|
2010-01-25 13:22:58 -05:00
|
|
|
struct rb_vm_protect_tag {
|
|
|
|
struct rb_vm_protect_tag *prev;
|
|
|
|
};
|
|
|
|
|
2008-05-29 21:52:38 -04:00
|
|
|
struct rb_unblock_callback {
|
|
|
|
rb_unblock_function_t *func;
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
2008-07-27 11:20:01 -04:00
|
|
|
struct rb_mutex_struct;
|
|
|
|
|
2012-11-28 07:34:15 -05:00
|
|
|
struct rb_thread_struct;
|
|
|
|
typedef struct rb_thread_list_struct{
|
|
|
|
struct rb_thread_list_struct *next;
|
|
|
|
struct rb_thread_struct *th;
|
|
|
|
} rb_thread_list_t;
|
|
|
|
|
|
|
|
|
2013-11-15 12:15:31 -05:00
|
|
|
typedef struct rb_ensure_entry {
|
|
|
|
VALUE marker;
|
|
|
|
VALUE (*e_proc)(ANYARGS);
|
|
|
|
VALUE data2;
|
|
|
|
} rb_ensure_entry_t;
|
|
|
|
|
|
|
|
typedef struct rb_ensure_list {
|
|
|
|
struct rb_ensure_list *next;
|
|
|
|
struct rb_ensure_entry entry;
|
|
|
|
} rb_ensure_list_t;
|
|
|
|
|
2014-06-11 04:38:09 -04:00
|
|
|
typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
|
|
|
|
|
2014-10-15 18:35:08 -04:00
|
|
|
typedef struct rb_fiber_struct rb_fiber_t;
|
|
|
|
|
2010-10-30 21:42:54 -04:00
|
|
|
typedef struct rb_thread_struct {
|
vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table. I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:
1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
(0002 patch in Feature 9632 will introduce a secondary list
for waiting FDs)
This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.
vm_thread_close 1.762
* vm_core.h (rb_vm_t): list_head and counter for living_threads
(rb_thread_t): vmlt_node for living_threads linkage
(rb_vm_living_threads_init): new function wrapper
(rb_vm_living_threads_insert): ditto
(rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
[ruby-core:61871][Feature 9632 (part 1)]
Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 19:48:51 -04:00
|
|
|
struct list_node vmlt_node;
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE self;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_vm_t *vm;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* execution information */
|
|
|
|
VALUE *stack; /* must free, must mark */
|
2012-12-19 17:29:18 -05:00
|
|
|
size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_control_frame_t *cfp;
|
2006-12-31 10:02:22 -05:00
|
|
|
int safe_level;
|
|
|
|
int raised_flag;
|
2008-07-09 23:10:00 -04:00
|
|
|
VALUE last_status; /* $? */
|
2008-12-09 02:17:10 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* passing state */
|
|
|
|
int state;
|
|
|
|
|
2011-02-12 00:44:23 -05:00
|
|
|
int waiting_fd;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* for rb_iterate */
|
2009-07-15 10:59:41 -04:00
|
|
|
const rb_block_t *passed_block;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2010-05-05 13:51:21 -04:00
|
|
|
/* for bmethod */
|
2014-04-30 05:08:10 -04:00
|
|
|
const rb_method_entry_t *passed_bmethod_me;
|
2010-05-05 13:51:21 -04:00
|
|
|
|
* vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'.
This optimization makes all cfunc method calls `frameless', which
is fster than ordinal cfunc method call.
If `frame' is needed (for example, it calls another method with
`rb_funcall()'), then build a frame. In other words, this
optimization delays frame building.
However, to delay the frame building, we need additional overheads:
(1) Store the last call information.
(2) Check the delayed frame buidling before the frame is needed.
(3) Overhead to build a delayed frame.
rb_thread_t::passed_ci is storage of delayed cfunc call information.
(1) is lightweight because it is only 1 assignment to `passed_ci'.
To achieve (2), we modify GET_THREAD() to check `passed_ci' every
time. It causes 10% overhead on my envrionment.
This optimization only works for cfunc methods which do not need
their `frame'.
After evaluation on my environment, this optimization does not
effective every time. Because of this evaluation results, this
optimization is disabled at default.
* vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour
of VM internals. I will extend this feature.
* vm_method.c, method.h: change parameters of the `invoker' function.
Receive `func' pointer as the first parameter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 00:22:31 -04:00
|
|
|
/* for cfunc */
|
|
|
|
rb_call_info_t *passed_ci;
|
|
|
|
|
2007-02-25 11:29:26 -05:00
|
|
|
/* for load(true) */
|
|
|
|
VALUE top_self;
|
|
|
|
VALUE top_wrapper;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* eval env */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_block_t *base_block;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-06-10 23:14:59 -04:00
|
|
|
VALUE *root_lep;
|
|
|
|
VALUE root_svar;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* thread control */
|
2013-07-23 06:38:36 -04:00
|
|
|
rb_nativethread_id_t thread_id;
|
2014-06-11 04:38:09 -04:00
|
|
|
#ifdef NON_SCALAR_THREAD_ID
|
|
|
|
rb_thread_id_string_t thread_id_string;
|
|
|
|
#endif
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
enum rb_thread_status status;
|
2012-11-28 03:31:03 -05:00
|
|
|
int to_kill;
|
2006-12-31 10:02:22 -05:00
|
|
|
int priority;
|
2014-08-14 20:25:34 -04:00
|
|
|
int mark_stack_len;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
native_thread_data_t native_thread_data;
|
2008-12-30 02:57:53 -05:00
|
|
|
void *blocking_region_buffer;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
VALUE thgroup;
|
|
|
|
VALUE value;
|
|
|
|
|
2012-07-18 01:46:40 -04:00
|
|
|
/* temporary place of errinfo */
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE errinfo;
|
2012-07-18 01:46:40 -04:00
|
|
|
|
2012-08-07 07:13:57 -04:00
|
|
|
/* temporary place of retval on OPT_CALL_THREADED_CODE */
|
|
|
|
#if OPT_CALL_THREADED_CODE
|
|
|
|
VALUE retval;
|
|
|
|
#endif
|
|
|
|
|
2012-07-18 01:46:40 -04:00
|
|
|
/* async errinfo queue */
|
2012-12-23 05:18:58 -05:00
|
|
|
VALUE pending_interrupt_queue;
|
|
|
|
VALUE pending_interrupt_mask_stack;
|
2014-08-14 20:25:34 -04:00
|
|
|
int pending_interrupt_queue_checked;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2011-06-11 10:27:08 -04:00
|
|
|
rb_atomic_t interrupt_flag;
|
2012-11-26 05:57:39 -05:00
|
|
|
unsigned long interrupt_mask;
|
2013-07-23 05:53:14 -04:00
|
|
|
rb_nativethread_lock_t interrupt_lock;
|
2013-07-23 06:50:32 -04:00
|
|
|
rb_nativethread_cond_t interrupt_cond;
|
2008-05-29 21:52:38 -04:00
|
|
|
struct rb_unblock_callback unblock;
|
2008-06-12 09:01:38 -04:00
|
|
|
VALUE locking_mutex;
|
2008-07-27 11:20:01 -04:00
|
|
|
struct rb_mutex_struct *keeping_mutexes;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
struct rb_vm_tag *tag;
|
2010-01-25 13:22:58 -05:00
|
|
|
struct rb_vm_protect_tag *protect_tag;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-06-13 22:21:51 -04:00
|
|
|
/*! Thread-local state of evaluation context.
|
2012-06-13 23:03:48 -04:00
|
|
|
*
|
2012-06-13 22:21:51 -04:00
|
|
|
* If negative, this thread is evaluating the main program.
|
|
|
|
* If positive, this thread is evaluating a program under Kernel::eval
|
|
|
|
* family.
|
|
|
|
*/
|
2006-12-31 10:02:22 -05:00
|
|
|
int parse_in_eval;
|
2012-06-13 22:21:51 -04:00
|
|
|
|
|
|
|
/*! Thread-local state of compiling context.
|
|
|
|
*
|
|
|
|
* If non-zero, the parser does not automatically print error messages to
|
|
|
|
* stderr. */
|
2008-07-01 12:55:30 -04:00
|
|
|
int mild_compile_error;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* storage */
|
|
|
|
st_table *local_storage;
|
2014-11-26 20:56:38 -05:00
|
|
|
VALUE local_storage_recursive_hash;
|
2014-12-10 14:35:07 -05:00
|
|
|
VALUE local_storage_recursive_hash_for_trace;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-11-28 07:34:15 -05:00
|
|
|
rb_thread_list_t *join_list;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
VALUE first_proc;
|
|
|
|
VALUE first_args;
|
2007-02-05 07:21:01 -05:00
|
|
|
VALUE (*first_func)(ANYARGS);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* for GC */
|
2014-01-28 01:09:58 -05:00
|
|
|
struct {
|
|
|
|
VALUE *stack_start;
|
|
|
|
VALUE *stack_end;
|
|
|
|
size_t stack_maxsize;
|
2007-06-14 04:35:20 -04:00
|
|
|
#ifdef __ia64
|
2014-01-28 01:09:58 -05:00
|
|
|
VALUE *register_stack_start;
|
|
|
|
VALUE *register_stack_end;
|
|
|
|
size_t register_stack_maxsize;
|
2007-06-14 04:35:20 -04:00
|
|
|
#endif
|
2014-01-28 01:09:58 -05:00
|
|
|
jmp_buf regs;
|
|
|
|
} machine;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* statistics data for profiler */
|
|
|
|
VALUE stat_insn_usage;
|
|
|
|
|
2007-04-19 06:37:08 -04:00
|
|
|
/* tracer */
|
2012-08-16 07:41:24 -04:00
|
|
|
rb_hook_list_t event_hooks;
|
2012-12-21 04:33:44 -05:00
|
|
|
struct rb_trace_arg_struct *trace_arg; /* trace information */
|
2007-04-19 06:37:08 -04:00
|
|
|
|
* cont.c: support Fiber. Check test/ruby/test_fiber.rb for detail.
Fiber is known as "Micro Thread", "Coroutine", and other terms.
At this time, only Fiber#pass is supported to change context.
I want to know more suitable method name/API for Fiber (... do you
know more suitable class name instead of Fiber?) as "suspend/resume",
"call", "yield", "start/kick/stop/restart", ....
* eval.c, eval_intern.h, thread.c, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-27 15:12:43 -04:00
|
|
|
/* fiber */
|
2014-10-15 18:35:08 -04:00
|
|
|
rb_fiber_t *fiber;
|
|
|
|
rb_fiber_t *root_fiber;
|
* cont.c: support Fiber. Check test/ruby/test_fiber.rb for detail.
Fiber is known as "Micro Thread", "Coroutine", and other terms.
At this time, only Fiber#pass is supported to change context.
I want to know more suitable method name/API for Fiber (... do you
know more suitable class name instead of Fiber?) as "suspend/resume",
"call", "yield", "start/kick/stop/restart", ....
* eval.c, eval_intern.h, thread.c, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-05-27 15:12:43 -04:00
|
|
|
rb_jmpbuf_t root_jmpbuf;
|
|
|
|
|
2013-11-15 12:15:31 -05:00
|
|
|
/* ensure & callcc */
|
|
|
|
rb_ensure_list_t *ensure_list;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* misc */
|
|
|
|
int method_missing_reason;
|
|
|
|
int abort_on_exception;
|
2010-05-13 12:20:26 -04:00
|
|
|
#ifdef USE_SIGALTSTACK
|
|
|
|
void *altstack;
|
|
|
|
#endif
|
2011-06-13 10:14:53 -04:00
|
|
|
unsigned long running_time_us;
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-22 20:20:28 -04:00
|
|
|
} rb_thread_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-12-20 03:13:53 -05:00
|
|
|
typedef enum {
|
|
|
|
VM_DEFINECLASS_TYPE_CLASS = 0x00,
|
|
|
|
VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
|
|
|
|
VM_DEFINECLASS_TYPE_MODULE = 0x02,
|
|
|
|
/* 0x03..0x06 is reserved */
|
2013-10-22 08:59:27 -04:00
|
|
|
VM_DEFINECLASS_TYPE_MASK = 0x07
|
2012-12-20 03:13:53 -05:00
|
|
|
} rb_vm_defineclass_type_t;
|
|
|
|
|
2012-12-27 07:09:33 -05:00
|
|
|
#define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
|
2012-12-20 03:13:53 -05:00
|
|
|
#define VM_DEFINECLASS_FLAG_SCOPED 0x08
|
|
|
|
#define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
|
|
|
|
#define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
|
|
|
|
#define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
|
|
|
|
((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
|
|
|
|
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
/* iseq.c */
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 05:32:56 -04:00
|
|
|
|
|
|
|
/* node -> iseq */
|
2010-10-31 09:11:02 -04:00
|
|
|
VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
|
2012-06-03 22:49:37 -04:00
|
|
|
VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent);
|
|
|
|
VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path);
|
2010-10-31 09:11:02 -04:00
|
|
|
VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, VALUE);
|
|
|
|
VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 05:32:56 -04:00
|
|
|
|
|
|
|
/* src -> iseq */
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 00:25:46 -04:00
|
|
|
VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
|
* iseq.c, vm_eval.c: set th->base_block properly.
th->base_block is information for (a) parsing, (b) compiling
and (c) setting up the frame to execute the program passed by
`eval' method. For example, (1) parser need to know up-level
variables to detect it is variable or method without paren.
Befor (a), (b) and (c), VM set th->base_block by passed bindng
(or previous frame information). After execute (a), (b) and (c),
VM should clear th->base_block. However, if (a), (b) or (c)
raises an exception, then th->base_block is not cleared.
Problem is that the uncleared value th->balo_block is used for
irrelevant iseq compilation. It causes SEGV or critical error.
I tried to solve this problem: to clear them before exception,
but finally I found out that it is difficult to do it (Ruby
program can be run in many places).
Because of this background, I set th->base_block before
compiling iseq and restore it after compiling.
Basically, th->base_block is dirty hack (similar to global
variable) and this patch is also dirty.
* bootstraptest/test_eval.rb: add a test for above.
* internal.h: remove unused decl.
* iseq.c (rb_iseq_compile_with_option): add base_block parameter.
set th->base_block before compation and restore it after
compilation.
* ruby.c (require_libraries): pass 0 as base_block instead of
setting th->base_block
* tool/compile_prelude.rb (prelude_eval): apply above changes.
* vm.c, vm_eval.c: ditto.
* vm_core.h: add comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-22 05:32:56 -04:00
|
|
|
VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block);
|
|
|
|
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
|
|
|
|
|
2009-01-18 20:06:56 -05:00
|
|
|
VALUE rb_iseq_disasm(VALUE self);
|
2014-06-18 02:16:39 -04:00
|
|
|
int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 04:12:18 -04:00
|
|
|
const char *ruby_node_name(int node);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-06-29 13:26:16 -04:00
|
|
|
RUBY_EXTERN VALUE rb_cISeq;
|
|
|
|
RUBY_EXTERN VALUE rb_cRubyVM;
|
|
|
|
RUBY_EXTERN VALUE rb_cEnv;
|
2008-06-30 23:05:58 -04:00
|
|
|
RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#define GetProcPtr(obj, ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
GetCoreDataFromValue((obj), rb_proc_t, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
typedef struct {
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_block_t block;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
VALUE envval; /* for GC mark */
|
|
|
|
VALUE blockprocval;
|
2014-07-20 08:28:48 -04:00
|
|
|
int8_t safe_level; /* 0..3 */
|
2014-07-20 01:34:32 -04:00
|
|
|
int8_t is_from_method; /* bool */
|
|
|
|
int8_t is_lambda; /* bool */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
} rb_proc_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
#define GetEnvPtr(obj, ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
GetCoreDataFromValue((obj), rb_env_t, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int env_size;
|
|
|
|
int local_size;
|
|
|
|
VALUE prev_envval; /* for GC mark */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
rb_block_t block;
|
2014-09-08 15:38:22 -04:00
|
|
|
VALUE env[1]; /* flexible array */
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
} rb_env_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2013-07-22 03:32:52 -04:00
|
|
|
extern const rb_data_type_t ruby_binding_data_type;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define GetBindingPtr(obj, ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
GetCoreDataFromValue((obj), rb_binding_t, (ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
VALUE env;
|
2012-06-03 22:49:37 -04:00
|
|
|
VALUE path;
|
2014-10-18 07:46:31 -04:00
|
|
|
VALUE blockprocval; /* for GC mark */
|
2012-06-03 22:49:37 -04:00
|
|
|
unsigned short first_lineno;
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
} rb_binding_t;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* used by compile time and send insn */
|
2012-08-08 03:52:19 -04:00
|
|
|
|
|
|
|
enum vm_check_match_type {
|
|
|
|
VM_CHECKMATCH_TYPE_WHEN = 1,
|
|
|
|
VM_CHECKMATCH_TYPE_CASE = 2,
|
|
|
|
VM_CHECKMATCH_TYPE_RESCUE = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VM_CHECKMATCH_TYPE_MASK 0x03
|
|
|
|
#define VM_CHECKMATCH_ARRAY 0x04
|
|
|
|
|
2012-10-15 13:22:57 -04:00
|
|
|
#define VM_CALL_ARGS_SPLAT (0x01 << 1) /* m(*args) */
|
|
|
|
#define VM_CALL_ARGS_BLOCKARG (0x01 << 2) /* m(&block) */
|
|
|
|
#define VM_CALL_FCALL (0x01 << 3) /* m(...) */
|
|
|
|
#define VM_CALL_VCALL (0x01 << 4) /* m */
|
|
|
|
#define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
|
|
|
|
#define VM_CALL_SUPER (0x01 << 6) /* super */
|
|
|
|
#define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
|
* rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
[Feature #10440] (Details are described in this ticket)
Most of complex part is moved to vm_args.c.
Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
* introduce rb_call_info_kw_arg_t to represent keyword arguments.
* add rb_call_info_t::kw_arg.
* rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
* rename rb_iseq_t::arg_keywords to arg_keyword_num.
* rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
to represent keyword bitmap parameter index.
This bitmap parameter shows that which keyword parameters are given
or not given (0 for given).
It is refered by `checkkeyword' instruction described bellow.
* rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
to represent keyword rest parameter index.
* add rb_iseq_t::arg_keyword_default_values to represent default
keyword values.
* rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
to represent
(ci->flag & (SPLAT|BLOCKARG)) &&
ci->blockiseq == NULL &&
ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
* rewrite splat argument code.
* rewrite keyword arguments/parameters code.
* merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
not. If Hash object and all keys are Symbol literals, they are
compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
This instruction check the availability of corresponding keyword.
For example, a method "def foo k1: 'v1'; end" is cimpiled to the
following instructions.
0000 checkkeyword 2, 0 # check k1 is given.
0003 branchif 9 # if given, jump to address #9
0005 putstring "v1"
0007 setlocal_OP__WC__0 3 # k1 = 'v1'
0009 trace 8
0011 putnil
0012 trace 16
0014 leave
* insns.def (opt_send_simple): removed and add new instruction
"opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
has parameter variables "k1, kr1, k2, &b, internal_id, krest",
but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
(locate a block variable at last)
* parse.y (vtable_pop): added.
This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 13:02:55 -05:00
|
|
|
#define VM_CALL_ARGS_SIMPLE (0x01 << 8) /* (ci->flag & (SPLAT|BLOCKARG)) && ci->blockiseq == NULL && ci->kw_arg == NULL */
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2010-10-30 21:42:54 -04:00
|
|
|
enum vm_special_object_type {
|
|
|
|
VM_SPECIAL_OBJECT_VMCORE = 1,
|
|
|
|
VM_SPECIAL_OBJECT_CBASE,
|
2010-12-09 21:42:06 -05:00
|
|
|
VM_SPECIAL_OBJECT_CONST_BASE
|
2010-10-30 21:42:54 -04:00
|
|
|
};
|
2008-06-30 23:05:58 -04:00
|
|
|
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-10 17:46:43 -04:00
|
|
|
#define VM_FRAME_MAGIC_METHOD 0x11
|
|
|
|
#define VM_FRAME_MAGIC_BLOCK 0x21
|
|
|
|
#define VM_FRAME_MAGIC_CLASS 0x31
|
|
|
|
#define VM_FRAME_MAGIC_TOP 0x41
|
|
|
|
#define VM_FRAME_MAGIC_CFUNC 0x61
|
|
|
|
#define VM_FRAME_MAGIC_PROC 0x71
|
|
|
|
#define VM_FRAME_MAGIC_IFUNC 0x81
|
|
|
|
#define VM_FRAME_MAGIC_EVAL 0x91
|
|
|
|
#define VM_FRAME_MAGIC_LAMBDA 0xa1
|
2014-06-19 05:17:21 -04:00
|
|
|
#define VM_FRAME_MAGIC_RESCUE 0xb1
|
|
|
|
#define VM_FRAME_MAGIC_MASK_BITS 8
|
2014-10-17 04:50:01 -04:00
|
|
|
#define VM_FRAME_MAGIC_MASK (~(~(VALUE)0<<VM_FRAME_MAGIC_MASK_BITS))
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-10 17:46:43 -04:00
|
|
|
|
|
|
|
#define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
|
|
|
|
|
|
|
|
/* other frame flag */
|
2014-04-30 05:08:10 -04:00
|
|
|
#define VM_FRAME_FLAG_PASSED 0x0100
|
|
|
|
#define VM_FRAME_FLAG_FINISH 0x0200
|
|
|
|
#define VM_FRAME_FLAG_BMETHOD 0x0400
|
|
|
|
#define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
|
|
|
|
#define VM_FRAME_TYPE_BMETHOD_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_BMETHOD) != 0)
|
* vm.c, eval_intern.h (PASS_PASSED_BLOCK):
set a VM_FRAME_FLAG_PASSED flag to skip this frame when
searching ruby-level-cfp.
* eval.c, eval_intern.h, proc.c: fix to check cfp. if there is
no valid ruby-level-cfp, cause RuntimeError exception.
[ruby-dev:34128]
* vm_core.h, vm_evalbody.c, vm.c, vm_dump.c, vm_insnhelper.c,
insns.def: rename FRAME_MAGIC_* to VM_FRAME_MAGIC_*.
* KNOWNBUGS.rb, bootstraptest/test*.rb: move solved bugs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-10 17:46:43 -04:00
|
|
|
|
|
|
|
#define RUBYVM_CFUNC_FRAME_P(cfp) \
|
|
|
|
(VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
|
|
|
|
|
2009-07-13 05:30:23 -04:00
|
|
|
/* inline cache */
|
|
|
|
typedef struct iseq_inline_cache_entry *IC;
|
2012-10-09 01:33:54 -04:00
|
|
|
typedef rb_call_info_t *CALL_INFO;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-03-18 23:58:57 -04:00
|
|
|
void rb_vm_change_state(void);
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
typedef VALUE CDHASH;
|
|
|
|
|
2007-07-01 14:16:02 -04:00
|
|
|
#ifndef FUNC_FASTCALL
|
|
|
|
#define FUNC_FASTCALL(x) x
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-07-01 14:16:02 -04:00
|
|
|
typedef rb_control_frame_t *
|
|
|
|
(FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
|
2011-01-21 10:54:58 -05:00
|
|
|
#define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
|
|
|
|
#define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-06-10 23:14:59 -04:00
|
|
|
/*
|
|
|
|
* block frame:
|
|
|
|
* ep[ 0]: prev frame
|
|
|
|
* ep[-1]: CREF (for *_eval)
|
|
|
|
*
|
|
|
|
* method frame:
|
|
|
|
* ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VM_ENVVAL_BLOCK_PTR_FLAG 0x02
|
|
|
|
#define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG)
|
|
|
|
#define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG)
|
|
|
|
#define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v))
|
|
|
|
#define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v)))
|
|
|
|
|
|
|
|
#define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0]))
|
|
|
|
#define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0]))
|
|
|
|
#define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0])
|
|
|
|
|
|
|
|
VALUE *rb_vm_ep_local_ep(VALUE *ep);
|
2015-01-16 03:21:49 -05:00
|
|
|
rb_block_t *rb_vm_control_frame_block_ptr(const rb_control_frame_t *cfp);
|
2012-06-04 03:24:44 -04:00
|
|
|
|
2011-01-21 10:54:58 -05:00
|
|
|
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
|
|
|
|
#define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
#define RUBY_VM_END_CONTROL_FRAME(th) \
|
|
|
|
((rb_control_frame_t *)((th)->stack + (th)->stack_size))
|
|
|
|
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
|
2006-12-31 10:02:22 -05:00
|
|
|
((void *)(ecfp) > (void *)(cfp))
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
|
|
|
|
(!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
#define RUBY_VM_IFUNC_P(ptr) (BUILTIN_TYPE(ptr) == T_NODE)
|
|
|
|
#define RUBY_VM_NORMAL_ISEQ_P(ptr) \
|
2011-01-21 10:54:58 -05:00
|
|
|
((ptr) && !RUBY_VM_IFUNC_P(ptr))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* blockinlining.c, compile.c, compile.h, error.c, eval.c,
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h,
eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c,
process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def,
yarv.h, yarvcore.h, yarvcore.c: change type and macro names:
* yarv_*_t -> rb_*_t
* yarv_*_struct -> rb_*_struct
* yarv_tag -> rb_vm_tag
* YARV_* -> RUBY_VM_*
* proc.c, vm.c: move functions about env object creation
from proc.c to vm.c.
* proc.c, yarvcore.c: fix rb_cVM initialization place.
* inits.c: change Init_ISeq() order (after Init_VM).
* ruby.h, proc.c: change declaration place of rb_cEnv
from proc.c to ruby.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 14:00:03 -05:00
|
|
|
#define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
|
|
|
|
#define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
|
2012-09-28 00:05:36 -04:00
|
|
|
((rb_control_frame_t *)((VALUE *)(b) - 4))
|
|
|
|
/* magic number `4' is depend on rb_control_frame_t layout. */
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* VM related object allocate functions */
|
2008-05-22 12:19:14 -04:00
|
|
|
VALUE rb_thread_alloc(VALUE klass);
|
2014-09-12 16:57:45 -04:00
|
|
|
VALUE rb_proc_wrap(VALUE klass, rb_proc_t *); /* may use with rb_proc_alloc */
|
2014-10-18 07:46:31 -04:00
|
|
|
VALUE rb_binding_alloc(VALUE klass);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* for debug */
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 21:09:43 -05:00
|
|
|
extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
|
2013-11-29 07:01:18 -05:00
|
|
|
extern void rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *_pc);
|
2012-06-10 23:14:59 -04:00
|
|
|
extern void rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp);
|
|
|
|
|
* vm_dump.c: add a prefix "rb_vmdebug_" to
vm_stack_dump_raw(), vm_stack_dump_raw_current(),
vm_env_dump_raw(), vm_proc_dump_raw(), vm_stack_dump_th(),
vm_debug_print_register(), vm_thread_dump_regs(),
vm_debug_print_pre(), vm_debug_print_post(),
vm_thread_dump_state().
This change also may affect core (in fact, user of
above functions may be only ko1).
* vm_core.h: ditto.
* vm_exec.h (SDR2): remove duplicate definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 21:09:43 -05:00
|
|
|
#define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
|
|
|
|
#define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
|
2014-05-24 23:46:55 -04:00
|
|
|
void rb_vm_bugreport(const void *);
|
|
|
|
NORETURN(void rb_bug_context(const void *, const char *fmt, ...));
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
|
|
|
/* functions about thread/vm execution */
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2008-05-22 12:19:14 -04:00
|
|
|
VALUE rb_iseq_eval(VALUE iseqval);
|
2008-12-26 20:15:56 -05:00
|
|
|
VALUE rb_iseq_eval_main(VALUE iseqval);
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2008-05-22 12:19:14 -04:00
|
|
|
int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
|
|
|
|
|
2012-08-20 07:36:34 -04:00
|
|
|
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
|
2009-07-15 10:59:41 -04:00
|
|
|
int argc, const VALUE *argv, const rb_block_t *blockptr);
|
2014-11-13 04:10:40 -05:00
|
|
|
VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const rb_block_t *block, VALUE klass, int8_t is_lambda);
|
* vm.c: add a prefix "rb_" to exposed functions
vm_get_ruby_level_next_cfp(), rb_vm_make_env_object(),
vm_stack_to_heap(), vm_make_proc(), vm_invoke_proc(),
vm_get_sourceline(), vm_cref(), vm_localjump_error(),
vm_make_jump_tag_but_local_jump(), vm_jump_tag_but_local_jump().
This changes may affect only core because most of renamed functions
require a pointer of not-exposed struct such as rb_thread_t or NODE.
In short, they are core functions.
* cont.c, eval.c, eval_intern.h, load.c, proc.c, thread.c,
vm_core.h, vm_dump.c, vm_eval.c, vm_exec.c, vm_insnhelper.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 21:38:11 -05:00
|
|
|
VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
|
2014-10-18 07:46:31 -04:00
|
|
|
VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp);
|
* vm.c: add a prefix "rb_" to exposed functions
vm_get_ruby_level_next_cfp(), rb_vm_make_env_object(),
vm_stack_to_heap(), vm_make_proc(), vm_invoke_proc(),
vm_get_sourceline(), vm_cref(), vm_localjump_error(),
vm_make_jump_tag_but_local_jump(), vm_jump_tag_but_local_jump().
This changes may affect only core because most of renamed functions
require a pointer of not-exposed struct such as rb_thread_t or NODE.
In short, they are core functions.
* cont.c, eval.c, eval_intern.h, load.c, proc.c, thread.c,
vm_core.h, vm_dump.c, vm_eval.c, vm_exec.c, vm_insnhelper.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 21:38:11 -05:00
|
|
|
VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
|
2014-07-01 13:57:37 -04:00
|
|
|
VALUE rb_vm_env_local_variables(VALUE envval);
|
2013-08-09 05:51:00 -04:00
|
|
|
VALUE *rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars);
|
2010-12-03 21:08:05 -05:00
|
|
|
void rb_vm_inc_const_missing_count(void);
|
2010-11-28 00:48:31 -05:00
|
|
|
void rb_vm_gvl_destroy(rb_vm_t *vm);
|
2011-06-18 04:26:19 -04:00
|
|
|
VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
|
2012-08-02 07:08:44 -04:00
|
|
|
const VALUE *argv, const rb_method_entry_t *me,
|
|
|
|
VALUE defined_class);
|
2011-07-25 10:29:28 -04:00
|
|
|
void rb_unlink_method_entry(rb_method_entry_t *me);
|
|
|
|
void rb_gc_mark_unlinked_live_method_entries(void *pvm);
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
2010-10-05 20:08:44 -04:00
|
|
|
void rb_thread_start_timer_thread(void);
|
2011-06-26 20:30:41 -04:00
|
|
|
void rb_thread_stop_timer_thread(int);
|
2010-10-05 20:08:44 -04:00
|
|
|
void rb_thread_reset_timer_thread(void);
|
2011-06-26 20:30:41 -04:00
|
|
|
void rb_thread_wakeup_timer_thread(void);
|
|
|
|
|
vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table. I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:
1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
(0002 patch in Feature 9632 will introduce a secondary list
for waiting FDs)
This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.
vm_thread_close 1.762
* vm_core.h (rb_vm_t): list_head and counter for living_threads
(rb_thread_t): vmlt_node for living_threads linkage
(rb_vm_living_threads_init): new function wrapper
(rb_vm_living_threads_insert): ditto
(rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
[ruby-core:61871][Feature 9632 (part 1)]
Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 19:48:51 -04:00
|
|
|
static inline void
|
|
|
|
rb_vm_living_threads_init(rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
list_head_init(&vm->living_threads);
|
|
|
|
vm->living_thread_num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_vm_living_threads_insert(rb_vm_t *vm, rb_thread_t *th)
|
|
|
|
{
|
2014-12-27 01:11:10 -05:00
|
|
|
list_add_tail(&vm->living_threads, &th->vmlt_node);
|
vm*: doubly-linked list from ccan to manage vm->living_threads
A doubly-linked list for tracking living threads guarantees
constant-time insert/delete performance with no corner cases of a
hash table. I chose this ccan implementation of doubly-linked
lists over the BSD sys/queue.h implementation since:
1) insertion and removal are both branchless
2) locality is improved if a struct may be a member of multiple lists
(0002 patch in Feature 9632 will introduce a secondary list
for waiting FDs)
This also increases cache locality during iteration: improving
performance in a new IO#close benchmark with many sleeping threads
while still scanning the same number of threads.
vm_thread_close 1.762
* vm_core.h (rb_vm_t): list_head and counter for living_threads
(rb_thread_t): vmlt_node for living_threads linkage
(rb_vm_living_threads_init): new function wrapper
(rb_vm_living_threads_insert): ditto
(rb_vm_living_threads_remove): ditto
* vm.c (rb_vm_living_threads_foreach): new function wrapper
* thread.c (terminate_i, thread_start_func_2, thread_create_core,
thread_fd_close_i, thread_fd_close): update to use new APIs
* vm.c (vm_mark_each_thread_func, rb_vm_mark, ruby_vm_destruct,
vm_memsize, vm_init2, Init_VM): ditto
* vm_trace.c (clear_trace_func_i, rb_clear_trace_func): ditto
* benchmark/bm_vm_thread_close.rb: added to show improvement
* ccan/build_assert/build_assert.h: added as a dependency of list.h
* ccan/check_type/check_type.h: ditto
* ccan/container_of/container_of.h: ditto
* ccan/licenses/BSD-MIT: ditto
* ccan/licenses/CC0: ditto
* ccan/str/str.h: ditto (stripped of unused macros)
* ccan/list/list.h: ditto
* common.mk: add CCAN_LIST_INCLUDES
[ruby-core:61871][Feature 9632 (part 1)]
Apologies for the size of this commit, but I think a good
doubly-linked list will be useful for future features, too.
This may be used to add ordering to a container_of-based hash
table to preserve compatibility if required (e.g. feature 9614).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-10 19:48:51 -04:00
|
|
|
vm->living_thread_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_vm_living_threads_remove(rb_vm_t *vm, rb_thread_t *th)
|
|
|
|
{
|
|
|
|
list_del(&th->vmlt_node);
|
|
|
|
vm->living_thread_num--;
|
|
|
|
}
|
|
|
|
|
2009-01-11 20:43:23 -05:00
|
|
|
int ruby_thread_has_gvl_p(void);
|
2009-08-15 21:38:32 -04:00
|
|
|
typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
|
2014-12-16 22:08:20 -05:00
|
|
|
rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
|
|
|
|
rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
|
2010-05-13 00:09:26 -04:00
|
|
|
int rb_vm_get_sourceline(const rb_control_frame_t *);
|
2009-10-29 02:43:28 -04:00
|
|
|
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
|
2011-06-18 08:32:57 -04:00
|
|
|
void rb_vm_stack_to_heap(rb_thread_t *th);
|
* internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.
* iseq.h: declare rb_iseq_t dependent internal functions here.
* vm_core.h: declare rb_thread_t dependent internal functions here.
* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
thread.c, time.c, transcode.c, variable.c, vm.c,
tool/compile_prelude.rb: don't declare internal functions declared
in above headers. include above headers if required.
Note that rb_thread_mark() was declared as
void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
void rb_thread_mark(void *ptr) in vm.c. Now it is declared as
the later in internal.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 18:43:38 -04:00
|
|
|
void ruby_thread_init_stack(rb_thread_t *th);
|
2013-01-29 03:25:32 -05:00
|
|
|
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
|
2014-06-19 08:43:48 -04:00
|
|
|
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
|
2009-01-11 20:43:23 -05:00
|
|
|
|
2014-09-11 06:53:48 -04:00
|
|
|
void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE exception_class, const char *mesg);
|
|
|
|
|
* internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.
* iseq.h: declare rb_iseq_t dependent internal functions here.
* vm_core.h: declare rb_thread_t dependent internal functions here.
* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
thread.c, time.c, transcode.c, variable.c, vm.c,
tool/compile_prelude.rb: don't declare internal functions declared
in above headers. include above headers if required.
Note that rb_thread_mark() was declared as
void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
void rb_thread_mark(void *ptr) in vm.c. Now it is declared as
the later in internal.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 18:43:38 -04:00
|
|
|
void rb_gc_mark_machine_stack(rb_thread_t *th);
|
2007-11-20 05:47:53 -05:00
|
|
|
|
2011-08-26 15:03:21 -04:00
|
|
|
int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
|
|
|
|
|
2008-06-15 05:17:06 -04:00
|
|
|
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
|
2007-07-01 19:57:04 -04:00
|
|
|
|
2013-11-17 21:29:58 -05:00
|
|
|
#define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
|
|
|
|
#define VM_STACK_OVERFLOWED_P(cfp, sp, margin) \
|
|
|
|
(!RUBY_CONST_ASSERT(sizeof(*(sp)) == sizeof(VALUE)) || \
|
|
|
|
!RUBY_CONST_ASSERT(sizeof(*(cfp)) == sizeof(rb_control_frame_t)) || \
|
|
|
|
((rb_control_frame_t *)((sp) + (margin)) + 1) >= (cfp))
|
|
|
|
#define WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) \
|
|
|
|
if (LIKELY(!VM_STACK_OVERFLOWED_P(cfp, sp, margin))) {(void)0;} else /* overflowed */
|
|
|
|
#define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) \
|
|
|
|
WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) vm_stackoverflow()
|
|
|
|
#define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
|
|
|
|
WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow()
|
2012-12-25 04:57:07 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* for thread */
|
|
|
|
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
#if RUBY_VM_THREAD_MODEL == 2
|
2011-10-18 10:07:32 -04:00
|
|
|
extern rb_thread_t *ruby_current_thread;
|
2007-02-26 17:51:33 -05:00
|
|
|
extern rb_vm_t *ruby_current_vm;
|
2012-08-16 07:41:24 -04:00
|
|
|
extern rb_event_flag_t ruby_vm_event_flags;
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
|
2007-02-26 17:51:33 -05:00
|
|
|
#define GET_VM() ruby_current_vm
|
* vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'.
This optimization makes all cfunc method calls `frameless', which
is fster than ordinal cfunc method call.
If `frame' is needed (for example, it calls another method with
`rb_funcall()'), then build a frame. In other words, this
optimization delays frame building.
However, to delay the frame building, we need additional overheads:
(1) Store the last call information.
(2) Check the delayed frame buidling before the frame is needed.
(3) Overhead to build a delayed frame.
rb_thread_t::passed_ci is storage of delayed cfunc call information.
(1) is lightweight because it is only 1 assignment to `passed_ci'.
To achieve (2), we modify GET_THREAD() to check `passed_ci' every
time. It causes 10% overhead on my envrionment.
This optimization only works for cfunc methods which do not need
their `frame'.
After evaluation on my environment, this optimization does not
effective every time. Because of this evaluation results, this
optimization is disabled at default.
* vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour
of VM internals. I will extend this feature.
* vm_method.c, method.h: change parameters of the `invoker' function.
Receive `func' pointer as the first parameter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23 00:22:31 -04:00
|
|
|
|
|
|
|
#ifndef OPT_CALL_CFUNC_WITHOUT_FRAME
|
|
|
|
#define OPT_CALL_CFUNC_WITHOUT_FRAME 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline rb_thread_t *
|
|
|
|
GET_THREAD(void)
|
|
|
|
{
|
|
|
|
rb_thread_t *th = ruby_current_thread;
|
|
|
|
#if OPT_CALL_CFUNC_WITHOUT_FRAME
|
|
|
|
if (UNLIKELY(th->passed_ci != 0)) {
|
|
|
|
void vm_call_cfunc_push_frame(rb_thread_t *th);
|
|
|
|
vm_call_cfunc_push_frame(th);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return th;
|
|
|
|
}
|
|
|
|
|
2008-09-04 00:22:04 -04:00
|
|
|
#define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
#define rb_thread_set_current(th) do { \
|
2011-06-13 10:14:53 -04:00
|
|
|
if ((th)->vm->running_thread != (th)) { \
|
2012-11-30 08:52:34 -05:00
|
|
|
(th)->running_time_us = 0; \
|
2011-06-13 10:14:53 -04:00
|
|
|
} \
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
rb_thread_set_current_raw(th); \
|
2011-01-21 10:54:58 -05:00
|
|
|
(th)->vm->running_thread = (th); \
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06 20:25:05 -05:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#error "unsupported thread model"
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-11-26 07:17:10 -05:00
|
|
|
enum {
|
2013-05-26 17:30:44 -04:00
|
|
|
TIMER_INTERRUPT_MASK = 0x01,
|
|
|
|
PENDING_INTERRUPT_MASK = 0x02,
|
|
|
|
POSTPONED_JOB_INTERRUPT_MASK = 0x04,
|
|
|
|
TRAP_INTERRUPT_MASK = 0x08
|
2012-11-26 07:17:10 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK)
|
2012-12-23 05:18:58 -05:00
|
|
|
#define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, PENDING_INTERRUPT_MASK)
|
2013-05-26 17:30:44 -04:00
|
|
|
#define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
|
2012-11-26 07:17:10 -05:00
|
|
|
#define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK)
|
2012-12-23 05:18:58 -05:00
|
|
|
#define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
|
2012-11-26 05:57:39 -05:00
|
|
|
#define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask)
|
2007-12-24 23:16:06 -05:00
|
|
|
|
2010-10-09 16:33:21 -04:00
|
|
|
int rb_signal_buff_size(void);
|
|
|
|
void rb_signal_exec(rb_thread_t *th, int sig);
|
2010-10-05 20:08:44 -04:00
|
|
|
void rb_threadptr_check_signal(rb_thread_t *mth);
|
2009-06-08 12:14:06 -04:00
|
|
|
void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
|
|
|
|
void rb_threadptr_signal_exit(rb_thread_t *th);
|
2012-07-19 10:19:40 -04:00
|
|
|
void rb_threadptr_execute_interrupts(rb_thread_t *, int);
|
2011-06-18 04:26:19 -04:00
|
|
|
void rb_threadptr_interrupt(rb_thread_t *th);
|
2011-07-08 00:40:01 -04:00
|
|
|
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
|
2012-12-23 05:18:58 -05:00
|
|
|
void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
|
|
|
|
void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
|
|
|
|
int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-12-04 13:38:21 -05:00
|
|
|
#define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
|
2012-12-23 05:18:58 -05:00
|
|
|
if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
|
|
|
|
th->pending_interrupt_queue_checked = 0; \
|
2012-12-04 13:38:21 -05:00
|
|
|
RUBY_VM_SET_INTERRUPT(th); \
|
|
|
|
rb_threadptr_execute_interrupts(th, 1); \
|
|
|
|
} \
|
|
|
|
else if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
|
|
|
|
rb_threadptr_execute_interrupts(th, 1); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-11-19 20:21:19 -05:00
|
|
|
#define RUBY_VM_CHECK_INTS(th) do { \
|
2012-11-26 05:57:39 -05:00
|
|
|
if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
|
2012-11-19 20:21:19 -05:00
|
|
|
rb_threadptr_execute_interrupts(th, 0); \
|
2012-07-19 10:19:40 -04:00
|
|
|
} \
|
|
|
|
} while (0)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-07-02 08:49:35 -04:00
|
|
|
/* tracer */
|
2012-12-21 04:48:15 -05:00
|
|
|
struct rb_trace_arg_struct {
|
2012-11-20 04:48:24 -05:00
|
|
|
rb_event_flag_t event;
|
|
|
|
rb_thread_t *th;
|
|
|
|
rb_control_frame_t *cfp;
|
|
|
|
VALUE self;
|
|
|
|
ID id;
|
|
|
|
VALUE klass;
|
|
|
|
VALUE data;
|
2012-11-26 18:01:45 -05:00
|
|
|
|
|
|
|
int klass_solved;
|
|
|
|
|
|
|
|
/* calc from cfp */
|
2012-11-26 18:25:21 -05:00
|
|
|
int lineno;
|
|
|
|
VALUE path;
|
2012-12-21 04:48:15 -05:00
|
|
|
};
|
2012-11-20 04:48:24 -05:00
|
|
|
|
2012-12-21 04:48:15 -05:00
|
|
|
void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
|
2012-12-25 08:24:17 -05:00
|
|
|
void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg);
|
2012-11-20 04:48:24 -05:00
|
|
|
|
2012-12-25 08:24:17 -05:00
|
|
|
#define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
|
2012-11-20 04:48:24 -05:00
|
|
|
if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
|
|
|
|
if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
|
2012-12-21 04:48:15 -05:00
|
|
|
struct rb_trace_arg_struct trace_arg; \
|
2012-11-20 04:48:24 -05:00
|
|
|
trace_arg.event = (flag_); \
|
|
|
|
trace_arg.th = (th_); \
|
|
|
|
trace_arg.cfp = (trace_arg.th)->cfp; \
|
|
|
|
trace_arg.self = (self_); \
|
|
|
|
trace_arg.id = (id_); \
|
|
|
|
trace_arg.klass = (klass_); \
|
|
|
|
trace_arg.data = (data_); \
|
2012-11-26 18:25:21 -05:00
|
|
|
trace_arg.path = Qundef; \
|
2012-11-26 18:01:45 -05:00
|
|
|
trace_arg.klass_solved = 0; \
|
2012-12-25 08:24:17 -05:00
|
|
|
if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
|
|
|
|
else rb_threadptr_exec_event_hooks(&trace_arg); \
|
2007-07-02 08:49:35 -04:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2012-12-25 08:24:17 -05:00
|
|
|
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
|
|
|
|
EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
|
|
|
|
|
|
|
|
#define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
|
|
|
|
EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
2010-07-28 08:28:03 -04:00
|
|
|
|
|
|
|
int rb_thread_check_trap_pending(void);
|
|
|
|
|
2010-08-14 01:58:19 -04:00
|
|
|
extern VALUE rb_get_coverages(void);
|
|
|
|
extern void rb_set_coverages(VALUE);
|
|
|
|
extern void rb_reset_coverages(void);
|
|
|
|
|
2013-05-26 17:30:44 -04:00
|
|
|
void rb_postponed_job_flush(rb_vm_t *vm);
|
|
|
|
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2010-07-28 08:28:03 -04:00
|
|
|
|
2008-01-18 03:56:11 -05:00
|
|
|
#endif /* RUBY_VM_CORE_H */
|