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
|
|
|
|
2015-06-10 19:25:30 -04:00
|
|
|
/*
|
|
|
|
* Enable check mode.
|
|
|
|
* 1: enable local assertions.
|
|
|
|
*/
|
|
|
|
#ifndef VM_CHECK_MODE
|
|
|
|
#define VM_CHECK_MODE 0
|
|
|
|
#endif
|
|
|
|
|
2015-10-23 12:57:58 -04:00
|
|
|
/**
|
|
|
|
* VM Debug Level
|
|
|
|
*
|
|
|
|
* debug level:
|
|
|
|
* 0: no debug output
|
|
|
|
* 1: show instruction name
|
|
|
|
* 2: show stack frame when control stack frame is changed
|
|
|
|
* 3: show stack status
|
|
|
|
* 4: show register
|
|
|
|
* 5:
|
|
|
|
* 10: gc check
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VMDEBUG
|
|
|
|
#define VMDEBUG 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#undef VMDEBUG
|
|
|
|
#define VMDEBUG 3
|
|
|
|
#endif
|
|
|
|
|
2016-01-25 03:34:00 -05:00
|
|
|
#include "ruby_assert.h"
|
|
|
|
|
2015-06-10 19:25:30 -04:00
|
|
|
#if VM_CHECK_MODE > 0
|
2017-04-07 02:41:32 -04:00
|
|
|
#define VM_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr)
|
2016-07-28 07:02:30 -04:00
|
|
|
|
|
|
|
#define VM_UNREACHABLE(func) rb_bug(#func ": unreachable")
|
|
|
|
|
2015-06-10 19:25:30 -04:00
|
|
|
#else
|
2015-06-10 22:35:46 -04:00
|
|
|
#define VM_ASSERT(expr) ((void)0)
|
2017-08-10 07:40:49 -04:00
|
|
|
#define VM_UNREACHABLE(func) UNREACHABLE
|
2015-06-10 19:25:30 -04:00
|
|
|
#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
|
|
|
#define RUBY_VM_THREAD_MODEL 2
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2018-01-01 08:18:55 -05:00
|
|
|
/*
|
|
|
|
* implementation selector of get_insn_info algorithm
|
|
|
|
* 0: linear search
|
|
|
|
* 1: binary search
|
2018-01-09 09:05:23 -05:00
|
|
|
* 2: succinct bitvector
|
2018-01-01 08:18:55 -05:00
|
|
|
*/
|
2018-01-09 09:05:23 -05:00
|
|
|
#ifndef VM_INSN_INFO_TABLE_IMPL
|
2018-01-10 00:57:15 -05:00
|
|
|
# define VM_INSN_INFO_TABLE_IMPL 2
|
2018-01-09 09:05:23 -05:00
|
|
|
#endif
|
2018-01-01 08:18:55 -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"
|
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
|
|
|
|
|
2008-09-23 18:43:53 -04:00
|
|
|
#include <setjmp.h>
|
2006-12-31 10:02:22 -05:00
|
|
|
#include <signal.h>
|
|
|
|
|
2018-10-18 23:33:48 -04:00
|
|
|
#if defined(NSIG_MAX) /* POSIX issue 8 */
|
|
|
|
# undef NSIG
|
|
|
|
# define NSIG NSIG_MAX
|
|
|
|
#elif defined(_SIG_MAXSIG) /* FreeBSD */
|
|
|
|
# undef NSIG
|
|
|
|
# define NSIG _SIG_MAXSIG
|
|
|
|
#elif defined(_SIGMAX) /* QNX */
|
|
|
|
# define NSIG (_SIGMAX + 1)
|
|
|
|
#elif defined(NSIG) /* 99% of everything else */
|
|
|
|
# /* take it */
|
|
|
|
#else /* Last resort */
|
|
|
|
# define NSIG (sizeof(sigset_t) * CHAR_BIT + 1)
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RUBY_NSIG NSIG
|
|
|
|
|
2018-07-04 23:02:33 -04:00
|
|
|
#if defined(SIGCLD)
|
|
|
|
# define RUBY_SIGCHLD (SIGCLD)
|
|
|
|
#elif defined(SIGCHLD)
|
|
|
|
# define RUBY_SIGCHLD (SIGCHLD)
|
|
|
|
#else
|
|
|
|
# define RUBY_SIGCHLD (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* platforms with broken or non-existent SIGCHLD work by polling */
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
# define SIGCHLD_LOSSY (1)
|
|
|
|
#else
|
|
|
|
# define SIGCHLD_LOSSY (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* define to 0 to test old code path */
|
|
|
|
#define WAITPID_USE_SIGCHLD (RUBY_SIGCHLD || SIGCHLD_LOSSY)
|
|
|
|
|
* 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__)
|
2018-04-20 17:38:27 -04:00
|
|
|
# define USE_SIGALTSTACK
|
|
|
|
void *rb_register_sigaltstack(void);
|
|
|
|
# define RB_ALTSTACK_INIT(var) var = rb_register_sigaltstack()
|
|
|
|
# define RB_ALTSTACK_FREE(var) xfree(var)
|
2018-07-29 06:15:11 -04:00
|
|
|
# define RB_ALTSTACK(var) var
|
2018-04-20 17:38:27 -04:00
|
|
|
#else /* noop */
|
|
|
|
# define RB_ALTSTACK_INIT(var)
|
|
|
|
# define RB_ALTSTACK_FREE(var)
|
2018-07-29 06:15:11 -04:00
|
|
|
# define RB_ALTSTACK(var) (0)
|
2010-05-13 12:20:26 -04:00
|
|
|
#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
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
2018-08-23 04:32:30 -04:00
|
|
|
void rb_vm_encoded_insn_data_table_init(void);
|
2008-05-22 23:23:08 -04:00
|
|
|
typedef unsigned long rb_num_t;
|
2018-01-09 08:30:27 -05:00
|
|
|
typedef signed long rb_snum_t;
|
2008-05-22 23:23:08 -04:00
|
|
|
|
2015-07-17 09:18:12 -04:00
|
|
|
enum ruby_tag_type {
|
2017-07-12 11:02:09 -04:00
|
|
|
RUBY_TAG_NONE = 0x0,
|
2015-07-17 09:18:12 -04:00
|
|
|
RUBY_TAG_RETURN = 0x1,
|
|
|
|
RUBY_TAG_BREAK = 0x2,
|
|
|
|
RUBY_TAG_NEXT = 0x3,
|
|
|
|
RUBY_TAG_RETRY = 0x4,
|
|
|
|
RUBY_TAG_REDO = 0x5,
|
|
|
|
RUBY_TAG_RAISE = 0x6,
|
|
|
|
RUBY_TAG_THROW = 0x7,
|
|
|
|
RUBY_TAG_FATAL = 0x8,
|
|
|
|
RUBY_TAG_MASK = 0xf
|
|
|
|
};
|
2017-06-23 03:25:52 -04:00
|
|
|
|
2017-07-12 11:02:09 -04:00
|
|
|
#define TAG_NONE RUBY_TAG_NONE
|
2015-07-17 09:18:12 -04:00
|
|
|
#define TAG_RETURN RUBY_TAG_RETURN
|
|
|
|
#define TAG_BREAK RUBY_TAG_BREAK
|
|
|
|
#define TAG_NEXT RUBY_TAG_NEXT
|
|
|
|
#define TAG_RETRY RUBY_TAG_RETRY
|
|
|
|
#define TAG_REDO RUBY_TAG_REDO
|
|
|
|
#define TAG_RAISE RUBY_TAG_RAISE
|
|
|
|
#define TAG_THROW RUBY_TAG_THROW
|
|
|
|
#define TAG_FATAL RUBY_TAG_FATAL
|
|
|
|
#define TAG_MASK RUBY_TAG_MASK
|
|
|
|
|
2015-07-19 20:08:23 -04:00
|
|
|
enum ruby_vm_throw_flags {
|
|
|
|
VM_THROW_NO_ESCAPE_FLAG = 0x8000,
|
|
|
|
VM_THROW_STATE_MASK = 0xff
|
|
|
|
};
|
|
|
|
|
2015-10-29 01:45:18 -04:00
|
|
|
/* forward declarations */
|
|
|
|
struct rb_thread_struct;
|
|
|
|
struct rb_control_frame_struct;
|
|
|
|
|
2009-07-15 10:59:41 -04:00
|
|
|
/* iseq data type */
|
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
|
|
|
|
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;
|
2015-10-29 18:43:45 -04:00
|
|
|
const rb_cref_t *ic_cref;
|
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;
|
|
|
|
};
|
|
|
|
|
2015-06-03 06:42:18 -04:00
|
|
|
enum method_missing_reason {
|
|
|
|
MISSING_NOENTRY = 0x00,
|
|
|
|
MISSING_PRIVATE = 0x01,
|
|
|
|
MISSING_PROTECTED = 0x02,
|
2016-02-27 23:41:38 -05:00
|
|
|
MISSING_FCALL = 0x04,
|
|
|
|
MISSING_VCALL = 0x08,
|
|
|
|
MISSING_SUPER = 0x10,
|
|
|
|
MISSING_MISSING = 0x20,
|
|
|
|
MISSING_NONE = 0x40
|
2015-06-03 06:42:18 -04:00
|
|
|
};
|
|
|
|
|
2015-09-19 13:59:58 -04:00
|
|
|
struct rb_call_info {
|
* 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;
|
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;
|
2015-09-19 13:59:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct rb_call_info_kw_arg {
|
|
|
|
int keyword_len;
|
|
|
|
VALUE keywords[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rb_call_info_with_kwarg {
|
|
|
|
struct rb_call_info ci;
|
|
|
|
struct rb_call_info_kw_arg *kw_arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rb_calling_info {
|
2016-07-28 07:02:30 -04:00
|
|
|
VALUE block_handler;
|
2015-09-19 13:59:58 -04:00
|
|
|
VALUE recv;
|
|
|
|
int argc;
|
|
|
|
};
|
* 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
|
|
|
|
2015-10-23 13:00:51 -04:00
|
|
|
struct rb_call_cache;
|
2017-10-26 22:49:30 -04:00
|
|
|
struct rb_execution_context_struct;
|
|
|
|
typedef VALUE (*vm_call_handler)(struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc);
|
2015-10-23 13:00:51 -04:00
|
|
|
|
2015-09-19 13:59:58 -04:00
|
|
|
struct rb_call_cache {
|
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;
|
2012-10-09 01:33:54 -04:00
|
|
|
|
|
|
|
/* inline cache: values */
|
* method.h: introduce rb_callable_method_entry_t to remove
rb_control_frame_t::klass.
[Bug #11278], [Bug #11279]
rb_method_entry_t data belong to modules/classes.
rb_method_entry_t::owner points defined module or class.
module M
def foo; end
end
In this case, owner is M.
rb_callable_method_entry_t data belong to only classes.
For modules, MRI creates corresponding T_ICLASS internally.
rb_callable_method_entry_t can also belong to T_ICLASS.
rb_callable_method_entry_t::defined_class points T_CLASS or
T_ICLASS.
rb_method_entry_t data for classes (not for modules) are also
rb_callable_method_entry_t data because it is completely same data.
In this case, rb_method_entry_t::owner == rb_method_entry_t::defined_class.
For example, there are classes C and D, and incldues M,
class C; include M; end
class D; include M; end
then, two T_ICLASS objects for C's super class and D's super class
will be created.
When C.new.foo is called, then M#foo is searcheed and
rb_callable_method_t data is used by VM to invoke M#foo.
rb_method_entry_t data is only one for M#foo.
However, rb_callable_method_entry_t data are two (and can be more).
It is proportional to the number of including (and prepending)
classes (the number of T_ICLASS which point to the module).
Now, created rb_callable_method_entry_t are collected when
the original module M was modified. We can think it is a cache.
We need to select what kind of method entry data is needed.
To operate definition, then you need to use rb_method_entry_t.
You can access them by the following functions.
* rb_method_entry(VALUE klass, ID id);
* rb_method_entry_with_refinements(VALUE klass, ID id);
* rb_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
To invoke methods, then you need to use rb_callable_method_entry_t
which you can get by the following APIs corresponding to the
above listed functions.
* rb_callable_method_entry(VALUE klass, ID id);
* rb_callable_method_entry_with_refinements(VALUE klass, ID id);
* rb_callable_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
VM pushes rb_callable_method_entry_t, so that rb_vm_frame_method_entry()
returns rb_callable_method_entry_t.
You can check a super class of current method by
rb_callable_method_entry_t::defined_class.
* method.h: renamed from rb_method_entry_t::klass to
rb_method_entry_t::owner.
* internal.h: add rb_classext_struct::callable_m_tbl to cache
rb_callable_method_entry_t data.
We need to consider abotu this field again because it is only
active for T_ICLASS.
* class.c (method_entry_i): ditto.
* class.c (rb_define_attr): rb_method_entry() does not takes
defiend_class_ptr.
* gc.c (mark_method_entry): mark RCLASS_CALLABLE_M_TBL() for T_ICLASS.
* cont.c (fiber_init): rb_control_frame_t::klass is removed.
* proc.c: fix `struct METHOD' data structure because
rb_callable_method_t has all information.
* vm_core.h: remove several fields.
* rb_control_frame_t::klass.
* rb_block_t::klass.
And catch up changes.
* eval.c: catch up changes.
* gc.c: ditto.
* insns.def: ditto.
* vm.c: ditto.
* vm_args.c: ditto.
* vm_backtrace.c: ditto.
* vm_dump.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-03 07:24:50 -04:00
|
|
|
const rb_callable_method_entry_t *me;
|
* 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
|
|
|
|
2015-10-23 13:00:51 -04:00
|
|
|
vm_call_handler call;
|
2015-09-19 13:59:58 -04:00
|
|
|
|
2012-10-16 13:07:23 -04:00
|
|
|
union {
|
2015-07-24 17:44:14 -04:00
|
|
|
unsigned int index; /* used by ivar */
|
2015-06-03 06:42:18 -04:00
|
|
|
enum method_missing_reason method_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;
|
2015-09-19 13:59:58 -04:00
|
|
|
};
|
2012-10-09 01:33:54 -04:00
|
|
|
|
2007-06-24 14:40:13 -04:00
|
|
|
#if 1
|
2016-02-22 02:15:57 -05:00
|
|
|
#define CoreDataFromValue(obj, type) (type*)DATA_PTR(obj)
|
2007-06-24 14:40:13 -04:00
|
|
|
#else
|
2016-02-22 02:15:57 -05:00
|
|
|
#define CoreDataFromValue(obj, type) (type*)rb_data_object_get(obj)
|
2007-06-24 14:40:13 -04:00
|
|
|
#endif
|
2016-02-22 02:15:57 -05:00
|
|
|
#define GetCoreDataFromValue(obj, type, ptr) ((ptr) = CoreDataFromValue((obj), type))
|
2007-06-24 14:40:13 -04:00
|
|
|
|
2012-06-03 22:49:37 -04:00
|
|
|
typedef struct rb_iseq_location_struct {
|
2017-05-31 20:05:33 -04:00
|
|
|
VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
|
|
|
|
VALUE base_label; /* String */
|
|
|
|
VALUE label; /* String */
|
2014-08-24 22:24:10 -04:00
|
|
|
VALUE first_lineno; /* TODO: may be unsigned short */
|
2018-11-04 21:13:45 -05:00
|
|
|
int node_id;
|
2018-01-09 03:45:35 -05:00
|
|
|
rb_code_location_t code_location;
|
2012-06-03 22:49:37 -04:00
|
|
|
} rb_iseq_location_t;
|
2012-05-22 04:31:38 -04:00
|
|
|
|
2017-05-31 20:05:33 -04:00
|
|
|
#define PATHOBJ_PATH 0
|
|
|
|
#define PATHOBJ_REALPATH 1
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
pathobj_path(VALUE pathobj)
|
|
|
|
{
|
|
|
|
if (RB_TYPE_P(pathobj, T_STRING)) {
|
|
|
|
return pathobj;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
|
|
|
|
return RARRAY_AREF(pathobj, PATHOBJ_PATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
pathobj_realpath(VALUE pathobj)
|
|
|
|
{
|
|
|
|
if (RB_TYPE_P(pathobj, T_STRING)) {
|
|
|
|
return pathobj;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
|
|
|
|
return RARRAY_AREF(pathobj, PATHOBJ_REALPATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 23:17:44 -05:00
|
|
|
/* Forward declarations */
|
mjit.c: merge MJIT infrastructure
that allows to JIT-compile Ruby methods by generating C code and
using C compiler. See the first comment of mjit.c to know what this
file does.
mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.
This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.
`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs. TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.
mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.
Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.
common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.
inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.
ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.
thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows. Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes
vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.
vm_insnhelper.h: trigger MJIT on method calls during VM execution.
vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.
iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV. TODO: unload some GCed units in some safe way.
gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.
cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.
mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.
Patch author: Vladimir Makarov <vmakarov@redhat.com>.
Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.
Part of Feature 12589 and 14235.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 01:58:09 -05:00
|
|
|
struct rb_mjit_unit;
|
|
|
|
|
2015-07-22 06:55:02 -04:00
|
|
|
struct rb_iseq_constant_body {
|
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,
|
2018-01-04 19:49:41 -05:00
|
|
|
ISEQ_TYPE_PLAIN
|
2010-10-30 21:42:54 -04:00
|
|
|
} type; /* instruction sequence type */
|
2015-07-21 18:52:59 -04:00
|
|
|
|
2015-07-22 07:21:21 -04:00
|
|
|
unsigned int iseq_size;
|
2015-07-23 05:34:31 -04:00
|
|
|
const VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
|
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;
|
|
|
|
|
2015-07-24 17:44:14 -04:00
|
|
|
unsigned int size;
|
2014-11-02 18:14:21 -05:00
|
|
|
|
|
|
|
int lead_num;
|
|
|
|
int opt_num;
|
|
|
|
int rest_start;
|
|
|
|
int post_start;
|
|
|
|
int post_num;
|
|
|
|
int block_start;
|
|
|
|
|
2015-07-24 16:58:09 -04:00
|
|
|
const VALUE *opt_table; /* (opt_num + 1) entries. */
|
2014-11-02 23:43:07 -05:00
|
|
|
/* 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
|
|
|
|
2015-07-24 16:58:09 -04:00
|
|
|
const struct rb_iseq_param_keyword {
|
2014-11-02 18:14:21 -05:00
|
|
|
int num;
|
|
|
|
int required_num;
|
|
|
|
int bits_start;
|
|
|
|
int rest_start;
|
2015-07-23 05:53:16 -04:00
|
|
|
const ID *table;
|
|
|
|
const VALUE *default_values;
|
2014-11-02 18:14:21 -05:00
|
|
|
} *keyword;
|
|
|
|
} param;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2015-07-22 07:21:21 -04:00
|
|
|
rb_iseq_location_t location;
|
|
|
|
|
|
|
|
/* insn info, must be freed */
|
2018-01-01 04:16:27 -05:00
|
|
|
struct iseq_insn_info {
|
|
|
|
const struct iseq_insn_info_entry *body;
|
2018-01-09 09:05:23 -05:00
|
|
|
unsigned int *positions;
|
2018-01-01 04:16:27 -05:00
|
|
|
unsigned int size;
|
2018-01-09 09:05:23 -05:00
|
|
|
#if VM_INSN_INFO_TABLE_IMPL == 2
|
|
|
|
struct succ_index_table *succ_index_table;
|
|
|
|
#endif
|
2018-01-01 04:16:27 -05:00
|
|
|
} insns_info;
|
2015-07-22 07:21:21 -04:00
|
|
|
|
2015-07-23 05:53:16 -04:00
|
|
|
const ID *local_table; /* must free */
|
2015-07-22 07:21:21 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* catch table */
|
2015-07-24 15:49:16 -04:00
|
|
|
const struct iseq_catch_table *catch_table;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* for child iseq */
|
2015-07-16 09:13:50 -04:00
|
|
|
const struct rb_iseq_struct *parent_iseq;
|
|
|
|
struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
|
2015-07-22 07:21:21 -04:00
|
|
|
|
|
|
|
union iseq_inline_storage_entry *is_entries;
|
2015-09-19 13:59:58 -04:00
|
|
|
struct rb_call_info *ci_entries; /* struct rb_call_info ci_entries[ci_size];
|
|
|
|
* struct rb_call_info_with_kwarg cikw_entries[ci_kw_size];
|
|
|
|
* So that:
|
|
|
|
* struct rb_call_info_with_kwarg *cikw_entries = &body->ci_entries[ci_size];
|
|
|
|
*/
|
2018-10-21 09:45:36 -04:00
|
|
|
struct rb_call_cache *cc_entries; /* size is ci_size + ci_kw_size */
|
2015-09-19 13:59:58 -04:00
|
|
|
|
2018-03-19 14:21:54 -04:00
|
|
|
struct {
|
2018-04-19 20:25:30 -04:00
|
|
|
rb_snum_t flip_count;
|
|
|
|
VALUE coverage;
|
2018-10-20 06:45:55 -04:00
|
|
|
VALUE pc2branchindex;
|
2018-05-09 01:42:06 -04:00
|
|
|
VALUE *original_iseq;
|
2018-03-19 14:21:54 -04:00
|
|
|
} variable;
|
2015-07-22 07:21:21 -04:00
|
|
|
|
2015-07-24 17:44:14 -04:00
|
|
|
unsigned int local_table_size;
|
|
|
|
unsigned int is_size;
|
2015-09-19 13:59:58 -04:00
|
|
|
unsigned int ci_size;
|
|
|
|
unsigned int ci_kw_size;
|
2016-07-28 07:02:30 -04:00
|
|
|
unsigned int stack_max; /* for stack overflow check */
|
mjit.c: merge MJIT infrastructure
that allows to JIT-compile Ruby methods by generating C code and
using C compiler. See the first comment of mjit.c to know what this
file does.
mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.
This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.
`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs. TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.
mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.
Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.
common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.
inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.
ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.
thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows. Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes
vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.
vm_insnhelper.h: trigger MJIT on method calls during VM execution.
vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.
iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV. TODO: unload some GCed units in some safe way.
gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.
cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.
mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.
Patch author: Vladimir Makarov <vmakarov@redhat.com>.
Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.
Part of Feature 12589 and 14235.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 01:58:09 -05:00
|
|
|
|
2018-10-20 02:53:00 -04:00
|
|
|
#if USE_MJIT
|
mjit.c: merge MJIT infrastructure
that allows to JIT-compile Ruby methods by generating C code and
using C compiler. See the first comment of mjit.c to know what this
file does.
mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.
This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.
`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs. TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.
mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.
Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.
common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.
inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.
ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.
thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows. Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes
vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.
vm_insnhelper.h: trigger MJIT on method calls during VM execution.
vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.
iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV. TODO: unload some GCed units in some safe way.
gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.
cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.
mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.
Patch author: Vladimir Makarov <vmakarov@redhat.com>.
Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.
Part of Feature 12589 and 14235.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 01:58:09 -05:00
|
|
|
/* The following fields are MJIT related info. */
|
2018-02-04 23:17:44 -05:00
|
|
|
VALUE (*jit_func)(struct rb_execution_context_struct *,
|
|
|
|
struct rb_control_frame_struct *); /* function pointer for loaded native code */
|
mjit.c: merge MJIT infrastructure
that allows to JIT-compile Ruby methods by generating C code and
using C compiler. See the first comment of mjit.c to know what this
file does.
mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.
This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.
`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs. TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.
mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.
Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.
common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.
inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.
ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.
thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows. Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes
vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.
vm_insnhelper.h: trigger MJIT on method calls during VM execution.
vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.
iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV. TODO: unload some GCed units in some safe way.
gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.
cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.
mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.
Patch author: Vladimir Makarov <vmakarov@redhat.com>.
Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.
Part of Feature 12589 and 14235.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 01:58:09 -05:00
|
|
|
long unsigned total_calls; /* number of total calls with `mjit_exec()` */
|
|
|
|
struct rb_mjit_unit *jit_unit;
|
2018-10-20 02:53:00 -04:00
|
|
|
#endif
|
2018-03-04 02:04:28 -05:00
|
|
|
char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */
|
2015-07-22 06:55:02 -04:00
|
|
|
};
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2015-07-21 18:52:59 -04:00
|
|
|
/* T_IMEMO/iseq */
|
|
|
|
/* typedef rb_iseq_t is in method.h */
|
|
|
|
struct rb_iseq_struct {
|
2018-12-06 05:52:27 -05:00
|
|
|
VALUE flags; /* 1 */
|
|
|
|
VALUE wrapper; /* 2 */
|
|
|
|
|
|
|
|
struct rb_iseq_constant_body *body; /* 3 */
|
2015-12-08 08:58:50 -05:00
|
|
|
|
|
|
|
union { /* 4, 5 words */
|
|
|
|
struct iseq_compile_data *compile_data; /* used at compile time */
|
|
|
|
|
|
|
|
struct {
|
|
|
|
VALUE obj;
|
|
|
|
int index;
|
|
|
|
} loader;
|
2017-11-18 04:39:41 -05:00
|
|
|
|
2018-12-06 05:52:27 -05:00
|
|
|
struct {
|
|
|
|
struct rb_hook_list_struct *local_hooks;
|
|
|
|
rb_event_flag_t global_trace_events;
|
|
|
|
} exec;
|
2015-12-08 08:58:50 -05:00
|
|
|
} aux;
|
2015-07-21 18:52:59 -04:00
|
|
|
};
|
|
|
|
|
2015-12-08 08:58:50 -05:00
|
|
|
#ifndef USE_LAZY_LOAD
|
2015-12-18 02:13:16 -05:00
|
|
|
#define USE_LAZY_LOAD 0
|
2015-12-08 08:58:50 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_LAZY_LOAD
|
|
|
|
const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq);
|
2015-12-08 09:12:11 -05:00
|
|
|
#endif
|
2015-12-08 08:58:50 -05:00
|
|
|
|
|
|
|
static inline const rb_iseq_t *
|
|
|
|
rb_iseq_check(const rb_iseq_t *iseq)
|
|
|
|
{
|
2015-12-08 09:12:11 -05:00
|
|
|
#if USE_LAZY_LOAD
|
2015-12-08 08:58:50 -05:00
|
|
|
if (iseq->body == NULL) {
|
|
|
|
rb_iseq_complete((rb_iseq_t *)iseq);
|
|
|
|
}
|
2015-12-08 09:12:11 -05:00
|
|
|
#endif
|
2015-12-08 08:58:50 -05:00
|
|
|
return iseq;
|
|
|
|
}
|
|
|
|
|
2018-10-30 10:57:03 -04:00
|
|
|
static inline const rb_iseq_t *
|
|
|
|
def_iseq_ptr(rb_method_definition_t *def)
|
|
|
|
{
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
if (def->type != VM_METHOD_TYPE_ISEQ) rb_bug("def_iseq_ptr: not iseq (%d)", def->type);
|
|
|
|
#endif
|
|
|
|
return rb_iseq_check(def->body.iseq.iseqptr);
|
|
|
|
}
|
|
|
|
|
2008-06-15 05:17:06 -04:00
|
|
|
enum ruby_special_exceptions {
|
|
|
|
ruby_error_reenter,
|
|
|
|
ruby_error_nomemory,
|
|
|
|
ruby_error_sysstack,
|
2017-08-21 02:46:46 -04:00
|
|
|
ruby_error_stackfatal,
|
2017-04-08 22:34:49 -04:00
|
|
|
ruby_error_stream_closed,
|
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,
|
2017-03-27 02:12:37 -04:00
|
|
|
BOP_UMINUS,
|
2016-03-17 08:47:31 -04:00
|
|
|
BOP_MAX,
|
|
|
|
BOP_MIN,
|
2018-01-07 14:18:49 -05:00
|
|
|
BOP_CALL,
|
2018-09-25 22:38:45 -04:00
|
|
|
BOP_AND,
|
|
|
|
BOP_OR,
|
2014-07-17 21:53:18 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-04-04 10:37:07 -04:00
|
|
|
struct rb_vm_struct;
|
|
|
|
typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
|
|
|
|
|
|
|
|
typedef struct rb_at_exit_list {
|
|
|
|
rb_vm_at_exit_func *func;
|
|
|
|
struct rb_at_exit_list *next;
|
|
|
|
} rb_at_exit_list;
|
|
|
|
|
2009-09-18 03:29:17 -04:00
|
|
|
struct rb_objspace;
|
2015-09-07 03:50:11 -04:00
|
|
|
struct rb_objspace *rb_objspace_alloc(void);
|
2009-09-18 03:29:17 -04:00
|
|
|
void rb_objspace_free(struct rb_objspace *);
|
|
|
|
|
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;
|
2018-11-26 13:16:39 -05:00
|
|
|
unsigned int need_clean;
|
|
|
|
unsigned int running;
|
2012-08-16 07:41:24 -04:00
|
|
|
} 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;
|
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;
|
2018-08-13 17:34:20 -04:00
|
|
|
|
|
|
|
/* persists across uncontended GVL release/acquire for time slice */
|
|
|
|
const struct rb_thread_struct *running_thread;
|
|
|
|
|
2018-04-20 17:38:27 -04:00
|
|
|
#ifdef USE_SIGALTSTACK
|
|
|
|
void *main_altstack;
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2018-04-19 23:22:26 -04:00
|
|
|
rb_serial_t fork_gen;
|
2018-07-04 23:02:33 -04:00
|
|
|
rb_nativethread_lock_t waitpid_lock;
|
|
|
|
struct list_head waiting_pids; /* PID > 0: <=> struct waitpid_state */
|
|
|
|
struct list_head waiting_grps; /* PID <= 0: <=> struct waitpid_state */
|
2017-05-20 05:47:14 -04:00
|
|
|
struct list_head waiting_fds; /* <=> struct waiting_fd */
|
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;
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE thgroup_default;
|
2018-01-27 16:04:36 -05:00
|
|
|
int living_thread_num;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2016-05-17 13:24:34 -04:00
|
|
|
unsigned int running: 1;
|
|
|
|
unsigned int thread_abort_on_exception: 1;
|
2016-06-05 20:25:38 -04:00
|
|
|
unsigned int thread_report_on_exception: 1;
|
2017-12-28 15:09:24 -05:00
|
|
|
|
|
|
|
unsigned int safe_level_: 1;
|
2018-06-21 22:43:51 -04:00
|
|
|
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 {
|
2017-07-27 08:17:56 -04:00
|
|
|
VALUE cmd[RUBY_NSIG];
|
|
|
|
unsigned char safe[RUBY_NSIG];
|
|
|
|
} trap_list;
|
2007-04-19 06:37:08 -04:00
|
|
|
|
|
|
|
/* hook */
|
2018-11-26 13:16:39 -05:00
|
|
|
rb_hook_list_t global_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;
|
|
|
|
|
2018-11-29 22:56:29 -05:00
|
|
|
/* postponed_job (async-signal-safe, NOT thread-safe) */
|
2018-10-22 23:47:45 -04:00
|
|
|
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;
|
|
|
|
|
2018-11-29 22:56:29 -05:00
|
|
|
/* workqueue (thread-safe, NOT async-signal-safe) */
|
|
|
|
struct list_head workqueue; /* <=> rb_workqueue_job.jnode */
|
|
|
|
rb_nativethread_lock_t workqueue_lock;
|
|
|
|
|
2013-08-07 10:12:08 -04:00
|
|
|
VALUE verbose, debug, orig_progname, progname;
|
2008-07-03 08:55:12 -04:00
|
|
|
VALUE coverages;
|
2017-09-03 10:26:06 -04:00
|
|
|
int coverage_mode;
|
2008-06-09 01:18:03 -04:00
|
|
|
|
2013-10-11 14:27:18 -04:00
|
|
|
VALUE defined_module_hash;
|
|
|
|
|
2008-04-26 23:20:35 -04:00
|
|
|
struct rb_objspace *objspace;
|
2010-12-02 06:06:32 -05:00
|
|
|
|
2016-04-04 10:37:07 -04:00
|
|
|
rb_at_exit_list *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 */
|
2017-12-04 20:10:15 -05:00
|
|
|
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
|
2017-12-04 20:10:13 -05:00
|
|
|
#if defined(__powerpc64__)
|
|
|
|
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 32 * 1024 * sizeof(VALUE)) /* 128 KB or 256 KB */
|
|
|
|
#else
|
2012-12-19 17:29:18 -05:00
|
|
|
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
|
2017-12-04 20:10:13 -05:00
|
|
|
#endif
|
2012-12-19 17:29:18 -05:00
|
|
|
|
2014-07-17 21:53:18 -04:00
|
|
|
/* optimize insn */
|
2016-05-17 02:53:48 -04:00
|
|
|
#define INTEGER_REDEFINED_OP_FLAG (1 << 0)
|
2014-07-17 21:53:18 -04:00
|
|
|
#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)
|
2016-05-17 02:53:48 -04:00
|
|
|
/* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */
|
2014-07-17 21:53:18 -04:00
|
|
|
#define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
|
|
|
|
#define TIME_REDEFINED_OP_FLAG (1 << 7)
|
|
|
|
#define REGEXP_REDEFINED_OP_FLAG (1 << 8)
|
2015-12-07 20:46:45 -05:00
|
|
|
#define NIL_REDEFINED_OP_FLAG (1 << 9)
|
|
|
|
#define TRUE_REDEFINED_OP_FLAG (1 << 10)
|
|
|
|
#define FALSE_REDEFINED_OP_FLAG (1 << 11)
|
2018-01-07 14:18:49 -05:00
|
|
|
#define PROC_REDEFINED_OP_FLAG (1 << 12)
|
2014-07-17 21:53:18 -04:00
|
|
|
|
|
|
|
#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
|
* method.h: introduce rb_callable_method_entry_t to remove
rb_control_frame_t::klass.
[Bug #11278], [Bug #11279]
rb_method_entry_t data belong to modules/classes.
rb_method_entry_t::owner points defined module or class.
module M
def foo; end
end
In this case, owner is M.
rb_callable_method_entry_t data belong to only classes.
For modules, MRI creates corresponding T_ICLASS internally.
rb_callable_method_entry_t can also belong to T_ICLASS.
rb_callable_method_entry_t::defined_class points T_CLASS or
T_ICLASS.
rb_method_entry_t data for classes (not for modules) are also
rb_callable_method_entry_t data because it is completely same data.
In this case, rb_method_entry_t::owner == rb_method_entry_t::defined_class.
For example, there are classes C and D, and incldues M,
class C; include M; end
class D; include M; end
then, two T_ICLASS objects for C's super class and D's super class
will be created.
When C.new.foo is called, then M#foo is searcheed and
rb_callable_method_t data is used by VM to invoke M#foo.
rb_method_entry_t data is only one for M#foo.
However, rb_callable_method_entry_t data are two (and can be more).
It is proportional to the number of including (and prepending)
classes (the number of T_ICLASS which point to the module).
Now, created rb_callable_method_entry_t are collected when
the original module M was modified. We can think it is a cache.
We need to select what kind of method entry data is needed.
To operate definition, then you need to use rb_method_entry_t.
You can access them by the following functions.
* rb_method_entry(VALUE klass, ID id);
* rb_method_entry_with_refinements(VALUE klass, ID id);
* rb_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
To invoke methods, then you need to use rb_callable_method_entry_t
which you can get by the following APIs corresponding to the
above listed functions.
* rb_callable_method_entry(VALUE klass, ID id);
* rb_callable_method_entry_with_refinements(VALUE klass, ID id);
* rb_callable_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
VM pushes rb_callable_method_entry_t, so that rb_vm_frame_method_entry()
returns rb_callable_method_entry_t.
You can check a super class of current method by
rb_callable_method_entry_t::defined_class.
* method.h: renamed from rb_method_entry_t::klass to
rb_method_entry_t::owner.
* internal.h: add rb_classext_struct::callable_m_tbl to cache
rb_callable_method_entry_t data.
We need to consider abotu this field again because it is only
active for T_ICLASS.
* class.c (method_entry_i): ditto.
* class.c (rb_define_attr): rb_method_entry() does not takes
defiend_class_ptr.
* gc.c (mark_method_entry): mark RCLASS_CALLABLE_M_TBL() for T_ICLASS.
* cont.c (fiber_init): rb_control_frame_t::klass is removed.
* proc.c: fix `struct METHOD' data structure because
rb_callable_method_t has all information.
* vm_core.h: remove several fields.
* rb_control_frame_t::klass.
* rb_block_t::klass.
And catch up changes.
* eval.c: catch up changes.
* gc.c: ditto.
* insns.def: ditto.
* vm.c: ditto.
* vm_args.c: ditto.
* vm_backtrace.c: ditto.
* vm_dump.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-03 07:24:50 -04:00
|
|
|
#define VM_DEBUG_VERIFY_METHOD_CACHE (VM_DEBUG_MODE != 0)
|
2014-09-04 04:50:31 -04:00
|
|
|
#endif
|
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
struct rb_captured_block {
|
|
|
|
VALUE self;
|
|
|
|
const VALUE *ep;
|
|
|
|
union {
|
|
|
|
const rb_iseq_t *iseq;
|
|
|
|
const struct vm_ifunc *ifunc;
|
|
|
|
VALUE val;
|
|
|
|
} code;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rb_block_handler_type {
|
|
|
|
block_handler_type_iseq,
|
|
|
|
block_handler_type_ifunc,
|
|
|
|
block_handler_type_symbol,
|
|
|
|
block_handler_type_proc
|
|
|
|
};
|
|
|
|
|
|
|
|
enum rb_block_type {
|
|
|
|
block_type_iseq,
|
|
|
|
block_type_ifunc,
|
|
|
|
block_type_symbol,
|
|
|
|
block_type_proc
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rb_block {
|
|
|
|
union {
|
|
|
|
struct rb_captured_block captured;
|
|
|
|
VALUE symbol;
|
|
|
|
VALUE proc;
|
|
|
|
} as;
|
|
|
|
enum rb_block_type type;
|
|
|
|
};
|
|
|
|
|
* 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 {
|
2015-07-23 05:34:31 -04:00
|
|
|
const VALUE *pc; /* cfp[0] */
|
* 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 *sp; /* cfp[1] */
|
2015-07-21 17:41:04 -04:00
|
|
|
const rb_iseq_t *iseq; /* cfp[2] */
|
2016-07-28 07:02:30 -04:00
|
|
|
VALUE self; /* cfp[3] / block[0] */
|
|
|
|
const VALUE *ep; /* cfp[4] / block[1] */
|
|
|
|
const void *block_code; /* cfp[5] / block[2] */ /* iseq or ifunc */
|
mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.
This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.
This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).
Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.
I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.
common.mk: update dependencies for mjit_compile.c.
internal.h: declare `rb_vm_insn_addr2insn` for MJIT.
vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.
win32/mkexports.rb: export thread/ec functions, which are used by MJIT.
include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.
array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.
I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.
Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>
Part of [Feature #14235]
---
* Known issues
* Code generated by gcc is faster than clang. The benchmark may be worse
in macOS. Following benchmark result is provided by gcc w/ Linux.
* Performance is decreased when Google Chrome is running
* JIT can work on MinGW, but it doesn't improve performance at least
in short running benchmark.
* Currently it doesn't perform well with Rails. We'll try to fix this
before release.
---
* Benchmark reslts
Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores
- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option
** Optcarrot fps
Benchmark: https://github.com/mame/optcarrot
| |2.0.0-p0 |r62186 |JIT off |JIT on |
|:--------|:--------|:--------|:--------|:--------|
|fps |37.32 |51.46 |51.31 |58.88 |
|vs 2.0.0 |1.00x |1.38x |1.37x |1.58x |
** MJIT benchmarks
Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)
| |2.0.0-p0 |r62186 |JIT off |JIT on |
|:----------|:--------|:--------|:--------|:--------|
|aread |1.00 |1.09 |1.07 |2.19 |
|aref |1.00 |1.13 |1.11 |2.22 |
|aset |1.00 |1.50 |1.45 |2.64 |
|awrite |1.00 |1.17 |1.13 |2.20 |
|call |1.00 |1.29 |1.26 |2.02 |
|const2 |1.00 |1.10 |1.10 |2.19 |
|const |1.00 |1.11 |1.10 |2.19 |
|fannk |1.00 |1.04 |1.02 |1.00 |
|fib |1.00 |1.32 |1.31 |1.84 |
|ivread |1.00 |1.13 |1.12 |2.43 |
|ivwrite |1.00 |1.23 |1.21 |2.40 |
|mandelbrot |1.00 |1.13 |1.16 |1.28 |
|meteor |1.00 |2.97 |2.92 |3.17 |
|nbody |1.00 |1.17 |1.15 |1.49 |
|nest-ntimes|1.00 |1.22 |1.20 |1.39 |
|nest-while |1.00 |1.10 |1.10 |1.37 |
|norm |1.00 |1.18 |1.16 |1.24 |
|nsvb |1.00 |1.16 |1.16 |1.17 |
|red-black |1.00 |1.02 |0.99 |1.12 |
|sieve |1.00 |1.30 |1.28 |1.62 |
|trees |1.00 |1.14 |1.13 |1.19 |
|while |1.00 |1.12 |1.11 |2.41 |
** Discourse's script/bench.rb
Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb
NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
to fix it. Please wait for the fix.)
*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)
categories_admin:
50: 17
75: 18
90: 22
99: 29
home_admin:
50: 21
75: 21
90: 27
99: 40
topic_admin:
50: 17
75: 18
90: 22
99: 32
categories:
50: 35
75: 41
90: 43
99: 77
home:
50: 39
75: 46
90: 49
99: 95
topic:
50: 46
75: 52
90: 56
99: 101
*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)
categories_admin:
50: 19
75: 21
90: 25
99: 33
home_admin:
50: 24
75: 26
90: 30
99: 35
topic_admin:
50: 19
75: 20
90: 25
99: 30
categories:
50: 40
75: 44
90: 48
99: 76
home:
50: 42
75: 48
90: 51
99: 89
topic:
50: 49
75: 55
90: 58
99: 99
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 06:22:28 -05:00
|
|
|
const VALUE *bp; /* cfp[6] */
|
2012-09-28 00:05:36 -04:00
|
|
|
|
|
|
|
#if VM_DEBUG_BP_CHECK
|
mjit_compile.c: merge initial JIT compiler
which has been developed by Takashi Kokubun <takashikkbn@gmail> as
YARV-MJIT. Many of its bugs are fixed by wanabe <s.wanabe@gmail.com>.
This JIT compiler is designed to be a safe migration path to introduce
JIT compiler to MRI. So this commit does not include any bytecode
changes or dynamic instruction modifications, which are done in original
MJIT.
This commit even strips off some aggressive optimizations from
YARV-MJIT, and thus it's slower than YARV-MJIT too. But it's still
fairly faster than Ruby 2.5 in some benchmarks (attached below).
Note that this JIT compiler passes `make test`, `make test-all`, `make
test-spec` without JIT, and even with JIT. Not only it's perfectly safe
with JIT disabled because it does not replace VM instructions unlike
MJIT, but also with JIT enabled it stably runs Ruby applications
including Rails applications.
I'm expecting this version as just "initial" JIT compiler. I have many
optimization ideas which are skipped for initial merging, and you may
easily replace this JIT compiler with a faster one by just replacing
mjit_compile.c. `mjit_compile` interface is designed for the purpose.
common.mk: update dependencies for mjit_compile.c.
internal.h: declare `rb_vm_insn_addr2insn` for MJIT.
vm.c: exclude some definitions if `-DMJIT_HEADER` is provided to
compiler. This avoids to include some functions which take a long time
to compile, e.g. vm_exec_core. Some of the purpose is achieved in
transform_mjit_header.rb (see `IGNORED_FUNCTIONS`) but others are
manually resolved for now. Load mjit_helper.h for MJIT header.
mjit_helper.h: New. This is a file used only by JIT-ed code. I'll
refactor `mjit_call_cfunc` later.
vm_eval.c: add some #ifdef switches to skip compiling some functions
like Init_vm_eval.
win32/mkexports.rb: export thread/ec functions, which are used by MJIT.
include/ruby/defines.h: add MJIT_FUNC_EXPORTED macro alis to clarify
that a function is exported only for MJIT.
array.c: export a function used by MJIT.
bignum.c: ditto.
class.c: ditto.
compile.c: ditto.
error.c: ditto.
gc.c: ditto.
hash.c: ditto.
iseq.c: ditto.
numeric.c: ditto.
object.c: ditto.
proc.c: ditto.
re.c: ditto.
st.c: ditto.
string.c: ditto.
thread.c: ditto.
variable.c: ditto.
vm_backtrace.c: ditto.
vm_insnhelper.c: ditto.
vm_method.c: ditto.
I would like to improve maintainability of function exports, but I
believe this way is acceptable as initial merging if we clarify the
new exports are for MJIT (so that we can use them as TODO list to fix)
and add unit tests to detect unresolved symbols.
I'll add unit tests of JIT compilations in succeeding commits.
Author: Takashi Kokubun <takashikkbn@gmail.com>
Contributor: wanabe <s.wanabe@gmail.com>
Part of [Feature #14235]
---
* Known issues
* Code generated by gcc is faster than clang. The benchmark may be worse
in macOS. Following benchmark result is provided by gcc w/ Linux.
* Performance is decreased when Google Chrome is running
* JIT can work on MinGW, but it doesn't improve performance at least
in short running benchmark.
* Currently it doesn't perform well with Rails. We'll try to fix this
before release.
---
* Benchmark reslts
Benchmarked with:
Intel 4.0GHz i7-4790K with 16GB memory under x86-64 Ubuntu 8 Cores
- 2.0.0-p0: Ruby 2.0.0-p0
- r62186: Ruby trunk (early 2.6.0), before MJIT changes
- JIT off: On this commit, but without `--jit` option
- JIT on: On this commit, and with `--jit` option
** Optcarrot fps
Benchmark: https://github.com/mame/optcarrot
| |2.0.0-p0 |r62186 |JIT off |JIT on |
|:--------|:--------|:--------|:--------|:--------|
|fps |37.32 |51.46 |51.31 |58.88 |
|vs 2.0.0 |1.00x |1.38x |1.37x |1.58x |
** MJIT benchmarks
Benchmark: https://github.com/benchmark-driver/mjit-benchmarks
(Original: https://github.com/vnmakarov/ruby/tree/rtl_mjit_branch/MJIT-benchmarks)
| |2.0.0-p0 |r62186 |JIT off |JIT on |
|:----------|:--------|:--------|:--------|:--------|
|aread |1.00 |1.09 |1.07 |2.19 |
|aref |1.00 |1.13 |1.11 |2.22 |
|aset |1.00 |1.50 |1.45 |2.64 |
|awrite |1.00 |1.17 |1.13 |2.20 |
|call |1.00 |1.29 |1.26 |2.02 |
|const2 |1.00 |1.10 |1.10 |2.19 |
|const |1.00 |1.11 |1.10 |2.19 |
|fannk |1.00 |1.04 |1.02 |1.00 |
|fib |1.00 |1.32 |1.31 |1.84 |
|ivread |1.00 |1.13 |1.12 |2.43 |
|ivwrite |1.00 |1.23 |1.21 |2.40 |
|mandelbrot |1.00 |1.13 |1.16 |1.28 |
|meteor |1.00 |2.97 |2.92 |3.17 |
|nbody |1.00 |1.17 |1.15 |1.49 |
|nest-ntimes|1.00 |1.22 |1.20 |1.39 |
|nest-while |1.00 |1.10 |1.10 |1.37 |
|norm |1.00 |1.18 |1.16 |1.24 |
|nsvb |1.00 |1.16 |1.16 |1.17 |
|red-black |1.00 |1.02 |0.99 |1.12 |
|sieve |1.00 |1.30 |1.28 |1.62 |
|trees |1.00 |1.14 |1.13 |1.19 |
|while |1.00 |1.12 |1.11 |2.41 |
** Discourse's script/bench.rb
Benchmark: https://github.com/discourse/discourse/blob/v1.8.7/script/bench.rb
NOTE: Rails performance was somehow a little degraded with JIT for now.
We should fix this.
(At least I know opt_aref is performing badly in JIT and I have an idea
to fix it. Please wait for the fix.)
*** JIT off
Your Results: (note for timings- percentile is first, duration is second in millisecs)
categories_admin:
50: 17
75: 18
90: 22
99: 29
home_admin:
50: 21
75: 21
90: 27
99: 40
topic_admin:
50: 17
75: 18
90: 22
99: 32
categories:
50: 35
75: 41
90: 43
99: 77
home:
50: 39
75: 46
90: 49
99: 95
topic:
50: 46
75: 52
90: 56
99: 101
*** JIT on
Your Results: (note for timings- percentile is first, duration is second in millisecs)
categories_admin:
50: 19
75: 21
90: 25
99: 33
home_admin:
50: 24
75: 26
90: 30
99: 35
topic_admin:
50: 19
75: 20
90: 25
99: 30
categories:
50: 40
75: 44
90: 48
99: 76
home:
50: 42
75: 48
90: 51
99: 89
topic:
50: 49
75: 55
90: 58
99: 99
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-04 06:22:28 -05:00
|
|
|
VALUE *bp_check; /* cfp[7] */
|
2012-09-28 00:05:36 -04:00
|
|
|
#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
|
|
|
|
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
|
|
|
|
2017-06-28 00:49:30 -04:00
|
|
|
static inline struct rb_thread_struct *
|
|
|
|
rb_thread_ptr(VALUE thval)
|
|
|
|
{
|
2017-06-28 00:57:02 -04:00
|
|
|
return (struct rb_thread_struct *)rb_check_typeddata(thval, &ruby_threadptr_data_type);
|
2017-06-28 00:49:30 -04:00
|
|
|
}
|
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
|
|
|
/*
|
2017-10-26 07:02:13 -04:00
|
|
|
the members which are written in EC_PUSH_TAG() should be placed at
|
2013-05-18 02:49:19 -04:00
|
|
|
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;
|
2017-06-23 07:15:26 -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;
|
2017-06-23 05:43:52 -04:00
|
|
|
enum ruby_tag_type state;
|
2006-12-31 10:02:22 -05:00
|
|
|
};
|
|
|
|
|
2017-06-23 07:15:26 -04:00
|
|
|
STATIC_ASSERT(rb_vm_tag_buf_offset, offsetof(struct rb_vm_tag, buf) > 0);
|
|
|
|
STATIC_ASSERT(rb_vm_tag_buf_end,
|
|
|
|
offsetof(struct rb_vm_tag, buf) + sizeof(rb_jmpbuf_t) <
|
|
|
|
sizeof(struct rb_vm_tag));
|
|
|
|
|
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
|
|
|
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;
|
|
|
|
|
2017-09-05 22:51:34 -04:00
|
|
|
typedef struct rb_execution_context_struct {
|
2017-05-09 01:06:41 -04:00
|
|
|
/* execution information */
|
2017-08-10 00:55:12 -04:00
|
|
|
VALUE *vm_stack; /* must free, must mark */
|
|
|
|
size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */
|
2017-05-09 01:06:41 -04:00
|
|
|
rb_control_frame_t *cfp;
|
2017-06-26 03:56:44 -04:00
|
|
|
|
|
|
|
struct rb_vm_tag *tag;
|
|
|
|
struct rb_vm_protect_tag *protect_tag;
|
2017-06-27 22:50:56 -04:00
|
|
|
|
2017-11-06 02:44:28 -05:00
|
|
|
/* interrupt flags */
|
|
|
|
rb_atomic_t interrupt_flag;
|
2018-05-15 06:11:32 -04:00
|
|
|
rb_atomic_t interrupt_mask; /* size should match flag */
|
2017-11-06 02:44:28 -05:00
|
|
|
|
2017-11-06 00:41:48 -05:00
|
|
|
rb_fiber_t *fiber_ptr;
|
|
|
|
struct rb_thread_struct *thread_ptr;
|
2017-06-28 10:27:49 -04:00
|
|
|
|
2017-06-27 22:50:56 -04:00
|
|
|
/* storage (ec (fiber) local) */
|
|
|
|
st_table *local_storage;
|
|
|
|
VALUE local_storage_recursive_hash;
|
|
|
|
VALUE local_storage_recursive_hash_for_trace;
|
2017-06-28 02:09:06 -04:00
|
|
|
|
|
|
|
/* eval env */
|
|
|
|
const VALUE *root_lep;
|
|
|
|
VALUE root_svar;
|
|
|
|
|
|
|
|
/* ensure & callcc */
|
|
|
|
rb_ensure_list_t *ensure_list;
|
2017-09-08 02:21:30 -04:00
|
|
|
|
2017-11-06 00:41:48 -05:00
|
|
|
/* trace information */
|
|
|
|
struct rb_trace_arg_struct *trace_arg;
|
2017-10-28 06:01:54 -04:00
|
|
|
|
2017-11-06 00:41:48 -05:00
|
|
|
/* temporary places */
|
|
|
|
VALUE errinfo;
|
|
|
|
VALUE passed_block_handler; /* for rb_iterate */
|
2018-10-19 16:56:10 -04:00
|
|
|
|
|
|
|
uint8_t raised_flag; /* only 3 bits needed */
|
|
|
|
|
|
|
|
/* n.b. only 7 bits needed, really: */
|
|
|
|
BITFIELD(enum method_missing_reason, method_missing_reason, 8);
|
|
|
|
|
2018-07-06 09:56:58 -04:00
|
|
|
VALUE private_const_reference;
|
2017-10-29 08:57:04 -04:00
|
|
|
|
2017-09-10 11:49:45 -04:00
|
|
|
/* for GC */
|
|
|
|
struct {
|
|
|
|
VALUE *stack_start;
|
|
|
|
VALUE *stack_end;
|
|
|
|
size_t stack_maxsize;
|
|
|
|
#ifdef __ia64
|
|
|
|
VALUE *register_stack_start;
|
|
|
|
VALUE *register_stack_end;
|
|
|
|
size_t register_stack_maxsize;
|
|
|
|
#endif
|
2018-05-09 05:53:19 -04:00
|
|
|
RUBY_ALIGNAS(SIZEOF_VALUE) jmp_buf regs;
|
2017-09-10 11:49:45 -04:00
|
|
|
} machine;
|
2017-05-09 01:06:41 -04:00
|
|
|
} rb_execution_context_t;
|
|
|
|
|
2018-11-16 01:51:57 -05:00
|
|
|
void rb_ec_set_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
|
2017-10-26 04:32:49 -04:00
|
|
|
|
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
|
|
|
|
2017-10-26 04:32:49 -04:00
|
|
|
rb_execution_context_t *ec;
|
2017-06-26 03:56:44 -04:00
|
|
|
|
2008-07-09 23:10:00 -04:00
|
|
|
VALUE last_status; /* $? */
|
2008-12-09 02:17:10 -05: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 */
|
2015-09-19 13:59:58 -04:00
|
|
|
struct rb_calling_info *calling;
|
* 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
|
|
|
|
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
|
|
|
/* 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
|
2018-08-22 00:04:06 -04:00
|
|
|
BITFIELD(enum rb_thread_status, status, 2);
|
2018-08-15 01:54:41 -04:00
|
|
|
/* bit flags */
|
|
|
|
unsigned int to_kill : 1;
|
|
|
|
unsigned int abort_on_exception: 1;
|
|
|
|
unsigned int report_on_exception: 1;
|
|
|
|
unsigned int pending_interrupt_queue_checked: 1;
|
|
|
|
int8_t priority; /* -3 .. 3 (RUBY_THREAD_PRIORITY_{MIN,MAX}) */
|
|
|
|
uint32_t running_time_us; /* 12500..800000 */
|
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-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;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2017-11-06 02:44:28 -05:00
|
|
|
/* interrupt management */
|
2013-07-23 05:53:14 -04:00
|
|
|
rb_nativethread_lock_t interrupt_lock;
|
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
|
|
|
|
2012-11-28 07:34:15 -05:00
|
|
|
rb_thread_list_t *join_list;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2018-11-08 00:01:23 -05:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
VALUE proc;
|
|
|
|
VALUE args;
|
|
|
|
} proc;
|
|
|
|
struct {
|
|
|
|
VALUE (*func)(ANYARGS);
|
|
|
|
void *arg;
|
|
|
|
} func;
|
|
|
|
} invoke_arg;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
thread_invoke_type_none = 0,
|
|
|
|
thread_invoke_type_proc,
|
2018-11-08 01:26:21 -05:00
|
|
|
thread_invoke_type_func
|
2018-11-08 00:01:23 -05:00
|
|
|
} invoke_type;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* statistics data for profiler */
|
|
|
|
VALUE stat_insn_usage;
|
|
|
|
|
* 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 *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;
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/* misc */
|
2018-07-28 21:32:37 -04:00
|
|
|
VALUE name;
|
|
|
|
|
* 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 */
|
2018-01-05 03:59:22 -05:00
|
|
|
rb_iseq_t *rb_iseq_new (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type);
|
|
|
|
rb_iseq_t *rb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);
|
|
|
|
rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent);
|
|
|
|
rb_iseq_t *rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno,
|
2017-05-30 03:05:58 -04:00
|
|
|
const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*);
|
2018-01-04 02:07:49 -05:00
|
|
|
rb_iseq_t *rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno,
|
|
|
|
const rb_iseq_t *parent, 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 */
|
2015-07-21 18:52:59 -04:00
|
|
|
rb_iseq_t *rb_iseq_compile(VALUE src, VALUE file, VALUE line);
|
2016-07-28 07:02:30 -04:00
|
|
|
rb_iseq_t *rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, const struct rb_block *base_block);
|
2017-05-31 20:05:33 -04:00
|
|
|
rb_iseq_t *rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, const struct rb_block *base_block, VALUE opt);
|
* 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
|
|
|
|
2015-07-21 18:52:59 -04:00
|
|
|
VALUE rb_iseq_disasm(const rb_iseq_t *iseq);
|
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
|
|
|
|
2015-12-02 03:05:36 -05:00
|
|
|
VALUE rb_iseq_coverage(const rb_iseq_t *iseq);
|
|
|
|
|
2008-06-29 13:26:16 -04:00
|
|
|
RUBY_EXTERN VALUE rb_cISeq;
|
|
|
|
RUBY_EXTERN VALUE rb_cRubyVM;
|
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 {
|
2016-07-28 07:02:30 -04:00
|
|
|
const struct rb_block block;
|
2017-12-28 15:09:24 -05:00
|
|
|
unsigned int is_from_method: 1; /* bool */
|
|
|
|
unsigned int is_lambda: 1; /* 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
|
|
|
|
|
|
|
typedef struct {
|
2016-07-28 15:13:26 -04:00
|
|
|
VALUE flags; /* imemo header */
|
2016-07-28 07:02:30 -04:00
|
|
|
const rb_iseq_t *iseq;
|
2016-07-28 15:13:26 -04:00
|
|
|
const VALUE *ep;
|
|
|
|
const VALUE *env;
|
|
|
|
unsigned int env_size;
|
* 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 {
|
2017-06-01 11:12:14 -04:00
|
|
|
const struct rb_block block;
|
|
|
|
const VALUE pathobj;
|
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
|
|
|
|
|
2017-08-05 02:51:08 -04:00
|
|
|
enum vm_call_flag_bits {
|
|
|
|
VM_CALL_ARGS_SPLAT_bit, /* m(*args) */
|
|
|
|
VM_CALL_ARGS_BLOCKARG_bit, /* m(&block) */
|
|
|
|
VM_CALL_FCALL_bit, /* m(...) */
|
|
|
|
VM_CALL_VCALL_bit, /* m */
|
|
|
|
VM_CALL_ARGS_SIMPLE_bit, /* (ci->flag & (SPLAT|BLOCKARG)) && blockiseq == NULL && ci->kw_arg == NULL */
|
|
|
|
VM_CALL_BLOCKISEQ_bit, /* has blockiseq */
|
|
|
|
VM_CALL_KWARG_bit, /* has kwarg */
|
2017-08-05 02:58:44 -04:00
|
|
|
VM_CALL_KW_SPLAT_bit, /* m(**opts) */
|
2017-08-05 02:51:08 -04:00
|
|
|
VM_CALL_TAILCALL_bit, /* located at tail position */
|
|
|
|
VM_CALL_SUPER_bit, /* super */
|
2018-08-10 03:45:16 -04:00
|
|
|
VM_CALL_ZSUPER_bit, /* zsuper */
|
2017-08-05 02:51:08 -04:00
|
|
|
VM_CALL_OPT_SEND_bit, /* internal flag */
|
|
|
|
VM_CALL__END
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VM_CALL_ARGS_SPLAT (0x01 << VM_CALL_ARGS_SPLAT_bit)
|
|
|
|
#define VM_CALL_ARGS_BLOCKARG (0x01 << VM_CALL_ARGS_BLOCKARG_bit)
|
|
|
|
#define VM_CALL_FCALL (0x01 << VM_CALL_FCALL_bit)
|
|
|
|
#define VM_CALL_VCALL (0x01 << VM_CALL_VCALL_bit)
|
|
|
|
#define VM_CALL_ARGS_SIMPLE (0x01 << VM_CALL_ARGS_SIMPLE_bit)
|
|
|
|
#define VM_CALL_BLOCKISEQ (0x01 << VM_CALL_BLOCKISEQ_bit)
|
|
|
|
#define VM_CALL_KWARG (0x01 << VM_CALL_KWARG_bit)
|
2017-08-05 02:58:44 -04:00
|
|
|
#define VM_CALL_KW_SPLAT (0x01 << VM_CALL_KW_SPLAT_bit)
|
2017-08-05 02:51:08 -04:00
|
|
|
#define VM_CALL_TAILCALL (0x01 << VM_CALL_TAILCALL_bit)
|
|
|
|
#define VM_CALL_SUPER (0x01 << VM_CALL_SUPER_bit)
|
2018-08-10 03:45:16 -04:00
|
|
|
#define VM_CALL_ZSUPER (0x01 << VM_CALL_ZSUPER_bit)
|
2017-08-05 02:51:08 -04:00
|
|
|
#define VM_CALL_OPT_SEND (0x01 << VM_CALL_OPT_SEND_bit)
|
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
|
|
|
|
2015-02-27 03:10:04 -05:00
|
|
|
enum vm_svar_index {
|
|
|
|
VM_SVAR_LASTLINE = 0, /* $_ */
|
|
|
|
VM_SVAR_BACKREF = 1, /* $~ */
|
|
|
|
|
|
|
|
VM_SVAR_EXTRA_START = 2,
|
|
|
|
VM_SVAR_FLIPFLOP_START = 2 /* flipflop */
|
|
|
|
};
|
|
|
|
|
2009-07-13 05:30:23 -04:00
|
|
|
/* inline cache */
|
|
|
|
typedef struct iseq_inline_cache_entry *IC;
|
2018-03-19 14:21:54 -04:00
|
|
|
typedef union iseq_inline_storage_entry *ISE;
|
2015-09-19 13:59:58 -04:00
|
|
|
typedef struct rb_call_info *CALL_INFO;
|
|
|
|
typedef struct rb_call_cache *CALL_CACHE;
|
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 *
|
2017-10-27 15:08:31 -04:00
|
|
|
(FUNC_FASTCALL(*rb_insn_func_t))(rb_execution_context_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
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
#define VM_TAGGED_PTR_SET(p, tag) ((VALUE)(p) | (tag))
|
2018-07-15 07:42:15 -04:00
|
|
|
#define VM_TAGGED_PTR_REF(v, mask) ((void *)((v) & ~mask))
|
2016-07-28 07:02:30 -04:00
|
|
|
|
|
|
|
#define GC_GUARDED_PTR(p) VM_TAGGED_PTR_SET((p), 0x01)
|
|
|
|
#define GC_GUARDED_PTR_REF(p) VM_TAGGED_PTR_REF((p), 0x03)
|
2011-01-21 10:54:58 -05:00
|
|
|
#define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
enum {
|
|
|
|
/* Frame/Environment flag bits:
|
2017-06-03 06:07:44 -04:00
|
|
|
* MMMM MMMM MMMM MMMM ____ __FF FFFF EEEX (LSB)
|
2016-07-28 07:02:30 -04:00
|
|
|
*
|
|
|
|
* X : tag for GC marking (It seems as Fixnum)
|
|
|
|
* EEE : 3 bits Env flags
|
2017-06-03 06:07:44 -04:00
|
|
|
* FF..: 6 bits Frame flags
|
2018-01-02 01:41:52 -05:00
|
|
|
* MM..: 15 bits frame magic (to check frame corruption)
|
2016-07-28 07:02:30 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* frame types */
|
|
|
|
VM_FRAME_MAGIC_METHOD = 0x11110001,
|
|
|
|
VM_FRAME_MAGIC_BLOCK = 0x22220001,
|
|
|
|
VM_FRAME_MAGIC_CLASS = 0x33330001,
|
|
|
|
VM_FRAME_MAGIC_TOP = 0x44440001,
|
|
|
|
VM_FRAME_MAGIC_CFUNC = 0x55550001,
|
2017-06-03 06:07:44 -04:00
|
|
|
VM_FRAME_MAGIC_IFUNC = 0x66660001,
|
|
|
|
VM_FRAME_MAGIC_EVAL = 0x77770001,
|
2018-01-02 01:41:52 -05:00
|
|
|
VM_FRAME_MAGIC_RESCUE = 0x78880001,
|
|
|
|
VM_FRAME_MAGIC_DUMMY = 0x79990001,
|
2016-07-28 07:02:30 -04:00
|
|
|
|
2018-01-02 01:41:52 -05:00
|
|
|
VM_FRAME_MAGIC_MASK = 0x7fff0001,
|
2016-07-28 07:02:30 -04:00
|
|
|
|
|
|
|
/* frame flag */
|
|
|
|
VM_FRAME_FLAG_PASSED = 0x0010,
|
|
|
|
VM_FRAME_FLAG_FINISH = 0x0020,
|
|
|
|
VM_FRAME_FLAG_BMETHOD = 0x0040,
|
2016-08-02 20:16:34 -04:00
|
|
|
VM_FRAME_FLAG_CFRAME = 0x0080,
|
2017-06-03 06:07:44 -04:00
|
|
|
VM_FRAME_FLAG_LAMBDA = 0x0100,
|
2017-10-24 07:13:49 -04:00
|
|
|
VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM = 0x0200,
|
2016-07-28 07:02:30 -04:00
|
|
|
|
|
|
|
/* env flag */
|
|
|
|
VM_ENV_FLAG_LOCAL = 0x0002,
|
|
|
|
VM_ENV_FLAG_ESCAPED = 0x0004,
|
|
|
|
VM_ENV_FLAG_WB_REQUIRED = 0x0008
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VM_ENV_DATA_SIZE ( 3)
|
2012-06-10 23:14:59 -04:00
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
#define VM_ENV_DATA_INDEX_ME_CREF (-2) /* ep[-2] */
|
|
|
|
#define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
|
|
|
|
#define VM_ENV_DATA_INDEX_FLAGS ( 0) /* ep[ 0] */
|
|
|
|
#define VM_ENV_DATA_INDEX_ENV ( 1) /* ep[ 1] */
|
|
|
|
|
|
|
|
#define VM_ENV_INDEX_LAST_LVAR (-VM_ENV_DATA_SIZE)
|
|
|
|
|
2016-08-02 20:28:12 -04:00
|
|
|
static inline void VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value);
|
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
static inline void
|
|
|
|
VM_ENV_FLAGS_SET(const VALUE *ep, VALUE flag)
|
|
|
|
{
|
|
|
|
VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
|
|
|
|
VM_ASSERT(FIXNUM_P(flags));
|
|
|
|
VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags | flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
VM_ENV_FLAGS_UNSET(const VALUE *ep, VALUE flag)
|
|
|
|
{
|
|
|
|
VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
|
|
|
|
VM_ASSERT(FIXNUM_P(flags));
|
|
|
|
VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags & ~flag);
|
|
|
|
}
|
|
|
|
|
2016-08-01 21:47:21 -04:00
|
|
|
static inline unsigned long
|
2016-07-28 07:02:30 -04:00
|
|
|
VM_ENV_FLAGS(const VALUE *ep, long flag)
|
|
|
|
{
|
|
|
|
VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
|
|
|
|
VM_ASSERT(FIXNUM_P(flags));
|
|
|
|
return flags & flag;
|
|
|
|
}
|
2012-06-10 23:14:59 -04:00
|
|
|
|
2016-08-01 21:47:21 -04:00
|
|
|
static inline unsigned long
|
2016-07-28 07:02:30 -04:00
|
|
|
VM_FRAME_TYPE(const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
return VM_ENV_FLAGS(cfp->ep, VM_FRAME_MAGIC_MASK);
|
|
|
|
}
|
|
|
|
|
2017-06-03 06:07:44 -04:00
|
|
|
static inline int
|
|
|
|
VM_FRAME_LAMBDA_P(const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_LAMBDA) != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:28:12 -04:00
|
|
|
static inline int
|
|
|
|
VM_FRAME_FINISHED_P(const rb_control_frame_t *cfp)
|
|
|
|
{
|
2017-06-03 06:07:44 -04:00
|
|
|
return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_FINISH) != 0;
|
2016-08-02 20:28:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_FRAME_BMETHOD_P(const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BMETHOD) != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-02 21:50:50 -04:00
|
|
|
static inline int
|
|
|
|
rb_obj_is_iseq(VALUE iseq)
|
|
|
|
{
|
2017-04-07 02:41:32 -04:00
|
|
|
return imemo_type_p(iseq, imemo_iseq);
|
2016-08-02 21:50:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
#define RUBY_VM_NORMAL_ISEQ_P(iseq) rb_obj_is_iseq((VALUE)iseq)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_FRAME_CFRAME_P(const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
int cframe_p = VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME) != 0;
|
|
|
|
VM_ASSERT(RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) != cframe_p);
|
|
|
|
return cframe_p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
return !VM_FRAME_CFRAME_P(cfp);
|
|
|
|
}
|
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
#define RUBYVM_CFUNC_FRAME_P(cfp) \
|
|
|
|
(VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
|
|
|
|
|
|
|
|
#define VM_GUARDED_PREV_EP(ep) GC_GUARDED_PTR(ep)
|
|
|
|
#define VM_BLOCK_HANDLER_NONE 0
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_ENV_LOCAL_P(const VALUE *ep)
|
|
|
|
{
|
2016-07-28 21:51:09 -04:00
|
|
|
return VM_ENV_FLAGS(ep, VM_ENV_FLAG_LOCAL) ? 1 : 0;
|
2016-07-28 07:02:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const VALUE *
|
|
|
|
VM_ENV_PREV_EP(const VALUE *ep)
|
|
|
|
{
|
|
|
|
VM_ASSERT(VM_ENV_LOCAL_P(ep) == 0);
|
|
|
|
return GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_ENV_BLOCK_HANDLER(const VALUE *ep)
|
|
|
|
{
|
|
|
|
VM_ASSERT(VM_ENV_LOCAL_P(ep));
|
|
|
|
return ep[VM_ENV_DATA_INDEX_SPECVAL];
|
|
|
|
}
|
|
|
|
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
int rb_vm_ep_in_heap_p(const VALUE *ep);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_ENV_ESCAPED_P(const VALUE *ep)
|
|
|
|
{
|
|
|
|
VM_ASSERT(rb_vm_ep_in_heap_p(ep) == !!VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED));
|
|
|
|
return VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2016-07-28 15:13:26 -04:00
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
static inline int
|
|
|
|
vm_assert_env(VALUE obj)
|
|
|
|
{
|
2017-04-07 02:41:32 -04:00
|
|
|
VM_ASSERT(imemo_type_p(obj, imemo_env));
|
2016-07-28 15:13:26 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
static inline VALUE
|
|
|
|
VM_ENV_ENVVAL(const VALUE *ep)
|
|
|
|
{
|
2016-07-28 15:13:26 -04:00
|
|
|
VALUE envval = ep[VM_ENV_DATA_INDEX_ENV];
|
2016-07-28 07:02:30 -04:00
|
|
|
VM_ASSERT(VM_ENV_ESCAPED_P(ep));
|
2016-07-28 15:13:26 -04:00
|
|
|
VM_ASSERT(vm_assert_env(envval));
|
|
|
|
return envval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const rb_env_t *
|
|
|
|
VM_ENV_ENVVAL_PTR(const VALUE *ep)
|
|
|
|
{
|
|
|
|
return (const rb_env_t *)VM_ENV_ENVVAL(ep);
|
2016-07-28 07:02:30 -04:00
|
|
|
}
|
|
|
|
|
2016-07-28 15:13:26 -04:00
|
|
|
static inline const rb_env_t *
|
|
|
|
vm_env_new(VALUE *env_ep, VALUE *env_body, unsigned int env_size, const rb_iseq_t *iseq)
|
|
|
|
{
|
|
|
|
rb_env_t *env = (rb_env_t *)rb_imemo_new(imemo_env, (VALUE)env_ep, (VALUE)env_body, 0, (VALUE)iseq);
|
|
|
|
env->env_size = env_size;
|
|
|
|
env_ep[VM_ENV_DATA_INDEX_ENV] = (VALUE)env;
|
|
|
|
return env;
|
|
|
|
}
|
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
static inline void
|
|
|
|
VM_FORCE_WRITE(const VALUE *ptr, VALUE v)
|
|
|
|
{
|
|
|
|
*((VALUE *)ptr) = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value)
|
|
|
|
{
|
|
|
|
VM_ASSERT(RB_SPECIAL_CONST_P(special_const_value));
|
|
|
|
VM_FORCE_WRITE(ptr, special_const_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
VM_STACK_ENV_WRITE(const VALUE *ep, int index, VALUE v)
|
|
|
|
{
|
|
|
|
VM_ASSERT(VM_ENV_FLAGS(ep, VM_ENV_FLAG_WB_REQUIRED) == 0);
|
|
|
|
VM_FORCE_WRITE(&ep[index], v);
|
|
|
|
}
|
|
|
|
|
|
|
|
const VALUE *rb_vm_ep_local_ep(const VALUE *ep);
|
2017-03-14 02:52:44 -04:00
|
|
|
const VALUE *rb_vm_proc_local_ep(VALUE proc);
|
2017-06-01 11:12:14 -04:00
|
|
|
void rb_vm_block_ep_update(VALUE obj, const struct rb_block *dst, const VALUE *ep);
|
|
|
|
void rb_vm_block_copy(VALUE obj, const struct rb_block *dst, const struct rb_block *src);
|
2017-03-14 02:52:44 -04:00
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
VALUE rb_vm_frame_block_handler(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)
|
2017-10-26 04:41:34 -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
|
|
|
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
|
2006-12-31 10:02:22 -05:00
|
|
|
((void *)(ecfp) > (void *)(cfp))
|
2017-10-26 04:41:34 -04:00
|
|
|
|
|
|
|
static inline const rb_control_frame_t *
|
|
|
|
RUBY_VM_END_CONTROL_FRAME(const rb_execution_context_t *ec)
|
|
|
|
{
|
|
|
|
return (rb_control_frame_t *)(ec->vm_stack + ec->vm_stack_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
|
|
|
|
{
|
|
|
|
return !RUBY_VM_VALID_CONTROL_FRAME_P(cfp, RUBY_VM_END_CONTROL_FRAME(ec));
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2016-07-28 07:02:30 -04:00
|
|
|
static inline int
|
|
|
|
VM_BH_ISEQ_BLOCK_P(VALUE block_handler)
|
|
|
|
{
|
|
|
|
if ((block_handler & 0x03) == 0x01) {
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
|
2017-04-07 02:41:32 -04:00
|
|
|
VM_ASSERT(imemo_type_p(captured->code.val, imemo_iseq));
|
2016-07-28 07:02:30 -04:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_FROM_ISEQ_BLOCK(const struct rb_captured_block *captured)
|
|
|
|
{
|
|
|
|
VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x01);
|
|
|
|
VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
|
|
|
|
return block_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const struct rb_captured_block *
|
|
|
|
VM_BH_TO_ISEQ_BLOCK(VALUE block_handler)
|
|
|
|
{
|
|
|
|
struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
|
|
|
|
VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
|
|
|
|
return captured;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
VM_BH_IFUNC_P(VALUE block_handler)
|
|
|
|
{
|
|
|
|
if ((block_handler & 0x03) == 0x03) {
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
struct rb_captured_block *captured = (void *)(block_handler & ~0x03);
|
2017-04-07 02:41:32 -04:00
|
|
|
VM_ASSERT(imemo_type_p(captured->code.val, imemo_ifunc));
|
2016-07-28 07:02:30 -04:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_FROM_IFUNC_BLOCK(const struct rb_captured_block *captured)
|
|
|
|
{
|
|
|
|
VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x03);
|
|
|
|
VM_ASSERT(VM_BH_IFUNC_P(block_handler));
|
|
|
|
return block_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const struct rb_captured_block *
|
|
|
|
VM_BH_TO_IFUNC_BLOCK(VALUE block_handler)
|
|
|
|
{
|
|
|
|
struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
|
|
|
|
VM_ASSERT(VM_BH_IFUNC_P(block_handler));
|
|
|
|
return captured;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const struct rb_captured_block *
|
|
|
|
VM_BH_TO_CAPT_BLOCK(VALUE block_handler)
|
|
|
|
{
|
|
|
|
struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
|
|
|
|
VM_ASSERT(VM_BH_IFUNC_P(block_handler) || VM_BH_ISEQ_BLOCK_P(block_handler));
|
|
|
|
return captured;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum rb_block_handler_type
|
|
|
|
vm_block_handler_type(VALUE block_handler)
|
|
|
|
{
|
|
|
|
if (VM_BH_ISEQ_BLOCK_P(block_handler)) {
|
|
|
|
return block_handler_type_iseq;
|
|
|
|
}
|
|
|
|
else if (VM_BH_IFUNC_P(block_handler)) {
|
|
|
|
return block_handler_type_ifunc;
|
|
|
|
}
|
|
|
|
else if (SYMBOL_P(block_handler)) {
|
|
|
|
return block_handler_type_symbol;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VM_ASSERT(rb_obj_is_proc(block_handler));
|
|
|
|
return block_handler_type_proc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 01:22:49 -04:00
|
|
|
static inline void
|
2017-09-11 04:50:07 -04:00
|
|
|
vm_block_handler_verify(MAYBE_UNUSED(VALUE block_handler))
|
2016-07-28 07:02:30 -04:00
|
|
|
{
|
|
|
|
VM_ASSERT(block_handler == VM_BLOCK_HANDLER_NONE ||
|
2017-02-06 23:24:44 -05:00
|
|
|
(vm_block_handler_type(block_handler), 1));
|
2016-07-28 07:02:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum rb_block_type
|
|
|
|
vm_block_type(const struct rb_block *block)
|
|
|
|
{
|
|
|
|
#if VM_CHECK_MODE > 0
|
|
|
|
switch (block->type) {
|
|
|
|
case block_type_iseq:
|
2017-04-07 02:41:32 -04:00
|
|
|
VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_iseq));
|
2016-07-28 07:02:30 -04:00
|
|
|
break;
|
|
|
|
case block_type_ifunc:
|
2017-04-07 02:41:32 -04:00
|
|
|
VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_ifunc));
|
2016-07-28 07:02:30 -04:00
|
|
|
break;
|
|
|
|
case block_type_symbol:
|
|
|
|
VM_ASSERT(SYMBOL_P(block->as.symbol));
|
|
|
|
break;
|
|
|
|
case block_type_proc:
|
|
|
|
VM_ASSERT(rb_obj_is_proc(block->as.proc));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return block->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
vm_block_type_set(const struct rb_block *block, enum rb_block_type type)
|
|
|
|
{
|
|
|
|
struct rb_block *mb = (struct rb_block *)block;
|
|
|
|
mb->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const struct rb_block *
|
|
|
|
vm_proc_block(VALUE procval)
|
|
|
|
{
|
|
|
|
VM_ASSERT(rb_obj_is_proc(procval));
|
2017-03-14 00:03:48 -04:00
|
|
|
return &((rb_proc_t *)RTYPEDDATA_DATA(procval))->block;
|
2016-07-28 07:02:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const rb_iseq_t *vm_block_iseq(const struct rb_block *block);
|
|
|
|
static inline const VALUE *vm_block_ep(const struct rb_block *block);
|
|
|
|
|
|
|
|
static inline const rb_iseq_t *
|
|
|
|
vm_proc_iseq(VALUE procval)
|
|
|
|
{
|
|
|
|
return vm_block_iseq(vm_proc_block(procval));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const VALUE *
|
|
|
|
vm_proc_ep(VALUE procval)
|
|
|
|
{
|
|
|
|
return vm_block_ep(vm_proc_block(procval));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const rb_iseq_t *
|
|
|
|
vm_block_iseq(const struct rb_block *block)
|
|
|
|
{
|
|
|
|
switch (vm_block_type(block)) {
|
2017-02-16 04:15:26 -05:00
|
|
|
case block_type_iseq: return rb_iseq_check(block->as.captured.code.iseq);
|
2016-07-28 07:02:30 -04:00
|
|
|
case block_type_proc: return vm_proc_iseq(block->as.proc);
|
|
|
|
case block_type_ifunc:
|
|
|
|
case block_type_symbol: return NULL;
|
|
|
|
}
|
|
|
|
VM_UNREACHABLE(vm_block_iseq);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const VALUE *
|
|
|
|
vm_block_ep(const struct rb_block *block)
|
|
|
|
{
|
|
|
|
switch (vm_block_type(block)) {
|
2016-07-28 07:02:32 -04:00
|
|
|
case block_type_iseq:
|
2016-07-28 07:02:30 -04:00
|
|
|
case block_type_ifunc: return block->as.captured.ep;
|
|
|
|
case block_type_proc: return vm_proc_ep(block->as.proc);
|
|
|
|
case block_type_symbol: return NULL;
|
|
|
|
}
|
|
|
|
VM_UNREACHABLE(vm_block_ep);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
vm_block_self(const struct rb_block *block)
|
|
|
|
{
|
|
|
|
switch (vm_block_type(block)) {
|
|
|
|
case block_type_iseq:
|
|
|
|
case block_type_ifunc:
|
|
|
|
return block->as.captured.self;
|
|
|
|
case block_type_proc:
|
|
|
|
return vm_block_self(vm_proc_block(block->as.proc));
|
|
|
|
case block_type_symbol:
|
|
|
|
return Qundef;
|
|
|
|
}
|
|
|
|
VM_UNREACHABLE(vm_block_self);
|
|
|
|
return Qundef;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_TO_SYMBOL(VALUE block_handler)
|
|
|
|
{
|
|
|
|
VM_ASSERT(SYMBOL_P(block_handler));
|
|
|
|
return block_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_FROM_SYMBOL(VALUE symbol)
|
|
|
|
{
|
|
|
|
VM_ASSERT(SYMBOL_P(symbol));
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_TO_PROC(VALUE block_handler)
|
|
|
|
{
|
|
|
|
VM_ASSERT(rb_obj_is_proc(block_handler));
|
|
|
|
return block_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
VM_BH_FROM_PROC(VALUE procval)
|
|
|
|
{
|
|
|
|
VM_ASSERT(rb_obj_is_proc(procval));
|
|
|
|
return procval;
|
|
|
|
}
|
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-10-18 07:46:31 -04:00
|
|
|
VALUE rb_binding_alloc(VALUE klass);
|
2017-12-28 15:09:24 -05:00
|
|
|
VALUE rb_proc_alloc(VALUE klass);
|
|
|
|
VALUE rb_proc_dup(VALUE self);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
/* for debug */
|
2017-10-29 10:31:01 -04:00
|
|
|
extern void rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
|
|
|
|
extern void rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc);
|
|
|
|
extern void rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
|
2012-06-10 23:14:59 -04:00
|
|
|
|
2017-10-29 10:31:01 -04:00
|
|
|
#define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp)
|
|
|
|
#define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (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
|
2015-07-21 18:52:59 -04:00
|
|
|
VALUE rb_iseq_eval(const rb_iseq_t *iseq);
|
|
|
|
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq);
|
2017-05-31 20:05:33 -04:00
|
|
|
VALUE rb_iseq_path(const rb_iseq_t *iseq);
|
|
|
|
VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
|
2013-04-05 06:29:38 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
2017-05-31 20:05:33 -04:00
|
|
|
|
|
|
|
VALUE rb_iseq_pathobj_new(VALUE path, VALUE realpath);
|
|
|
|
void rb_iseq_pathobj_set(const rb_iseq_t *iseq, VALUE path, VALUE realpath);
|
|
|
|
|
2017-10-28 07:11:17 -04:00
|
|
|
int rb_ec_frame_method_id_and_class(const rb_execution_context_t *ec, ID *idp, ID *called_idp, VALUE *klassp);
|
2017-11-07 01:09:47 -05:00
|
|
|
void rb_ec_setup_exception(const rb_execution_context_t *ec, VALUE mesg, VALUE cause);
|
2008-05-22 12:19:14 -04:00
|
|
|
|
2017-10-27 02:06:31 -04:00
|
|
|
VALUE rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, int argc, const VALUE *argv, VALUE block_handler);
|
2017-11-16 02:25:30 -05:00
|
|
|
|
2017-10-26 04:41:34 -04:00
|
|
|
VALUE rb_vm_make_proc_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda);
|
2017-11-16 02:25:30 -05:00
|
|
|
static inline VALUE
|
|
|
|
rb_vm_make_proc(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
|
|
|
|
{
|
|
|
|
return rb_vm_make_proc_lambda(ec, captured, klass, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline VALUE
|
|
|
|
rb_vm_make_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
|
|
|
|
{
|
|
|
|
return rb_vm_make_proc_lambda(ec, captured, klass, 1);
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:01:26 -05:00
|
|
|
VALUE rb_vm_make_binding(const rb_execution_context_t *ec, const rb_control_frame_t *src_cfp);
|
2015-07-14 13:36:36 -04:00
|
|
|
VALUE rb_vm_env_local_variables(const rb_env_t *env);
|
2016-07-28 15:13:26 -04:00
|
|
|
const rb_env_t *rb_vm_env_prev_env(const rb_env_t *env);
|
2017-06-01 11:12:14 -04:00
|
|
|
const VALUE *rb_binding_add_dynavars(VALUE bindval, 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);
|
2017-10-28 07:52:56 -04:00
|
|
|
VALUE rb_vm_call(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc,
|
* method.h: introduce rb_callable_method_entry_t to remove
rb_control_frame_t::klass.
[Bug #11278], [Bug #11279]
rb_method_entry_t data belong to modules/classes.
rb_method_entry_t::owner points defined module or class.
module M
def foo; end
end
In this case, owner is M.
rb_callable_method_entry_t data belong to only classes.
For modules, MRI creates corresponding T_ICLASS internally.
rb_callable_method_entry_t can also belong to T_ICLASS.
rb_callable_method_entry_t::defined_class points T_CLASS or
T_ICLASS.
rb_method_entry_t data for classes (not for modules) are also
rb_callable_method_entry_t data because it is completely same data.
In this case, rb_method_entry_t::owner == rb_method_entry_t::defined_class.
For example, there are classes C and D, and incldues M,
class C; include M; end
class D; include M; end
then, two T_ICLASS objects for C's super class and D's super class
will be created.
When C.new.foo is called, then M#foo is searcheed and
rb_callable_method_t data is used by VM to invoke M#foo.
rb_method_entry_t data is only one for M#foo.
However, rb_callable_method_entry_t data are two (and can be more).
It is proportional to the number of including (and prepending)
classes (the number of T_ICLASS which point to the module).
Now, created rb_callable_method_entry_t are collected when
the original module M was modified. We can think it is a cache.
We need to select what kind of method entry data is needed.
To operate definition, then you need to use rb_method_entry_t.
You can access them by the following functions.
* rb_method_entry(VALUE klass, ID id);
* rb_method_entry_with_refinements(VALUE klass, ID id);
* rb_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
To invoke methods, then you need to use rb_callable_method_entry_t
which you can get by the following APIs corresponding to the
above listed functions.
* rb_callable_method_entry(VALUE klass, ID id);
* rb_callable_method_entry_with_refinements(VALUE klass, ID id);
* rb_callable_method_entry_without_refinements(VALUE klass, ID id);
* rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
VM pushes rb_callable_method_entry_t, so that rb_vm_frame_method_entry()
returns rb_callable_method_entry_t.
You can check a super class of current method by
rb_callable_method_entry_t::defined_class.
* method.h: renamed from rb_method_entry_t::klass to
rb_method_entry_t::owner.
* internal.h: add rb_classext_struct::callable_m_tbl to cache
rb_callable_method_entry_t data.
We need to consider abotu this field again because it is only
active for T_ICLASS.
* class.c (method_entry_i): ditto.
* class.c (rb_define_attr): rb_method_entry() does not takes
defiend_class_ptr.
* gc.c (mark_method_entry): mark RCLASS_CALLABLE_M_TBL() for T_ICLASS.
* cont.c (fiber_init): rb_control_frame_t::klass is removed.
* proc.c: fix `struct METHOD' data structure because
rb_callable_method_t has all information.
* vm_core.h: remove several fields.
* rb_control_frame_t::klass.
* rb_block_t::klass.
And catch up changes.
* eval.c: catch up changes.
* gc.c: ditto.
* insns.def: ditto.
* vm.c: ditto.
* vm_args.c: ditto.
* vm_backtrace.c: ditto.
* vm_dump.c: ditto.
* vm_eval.c: ditto.
* vm_insnhelper.c: ditto.
* vm_method.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-03 07:24:50 -04:00
|
|
|
const VALUE *argv, const rb_callable_method_entry_t *me);
|
2018-10-07 09:34:59 -04:00
|
|
|
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec);
|
* 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);
|
2015-08-14 05:44:10 -04:00
|
|
|
void rb_thread_stop_timer_thread(void);
|
2010-10-05 20:08:44 -04:00
|
|
|
void rb_thread_reset_timer_thread(void);
|
2018-08-13 17:34:20 -04:00
|
|
|
void rb_thread_wakeup_timer_thread(int);
|
2011-06-26 20:30:41 -04: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
|
|
|
static inline void
|
|
|
|
rb_vm_living_threads_init(rb_vm_t *vm)
|
|
|
|
{
|
2017-05-20 05:47:14 -04:00
|
|
|
list_head_init(&vm->waiting_fds);
|
2018-07-04 23:02:33 -04:00
|
|
|
list_head_init(&vm->waiting_pids);
|
2018-11-29 22:56:29 -05:00
|
|
|
list_head_init(&vm->workqueue);
|
2018-07-04 23:02:33 -04:00
|
|
|
list_head_init(&vm->waiting_grps);
|
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
|
|
|
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-08-15 21:38:32 -04:00
|
|
|
typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
|
2017-10-26 04:41:34 -04:00
|
|
|
rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
|
2017-11-07 03:01:26 -05:00
|
|
|
rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
|
2010-05-13 00:09:26 -04:00
|
|
|
int rb_vm_get_sourceline(const rb_control_frame_t *);
|
2015-06-25 03:11:45 -04:00
|
|
|
VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
|
2017-10-28 06:47:19 -04:00
|
|
|
void rb_vm_stack_to_heap(rb_execution_context_t *ec);
|
* 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);
|
* vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):
add TracePoint#callee_id. [ruby-core:77241] [Feature #12747]
* cont.c, eval.c, gc.c, include/ruby/intern.h, insns.def, thread.c,
vm.c, vm_backtrace.c, vm_core.h, vm_eval.c, vm_insnhelper.c, vm_trace.c: ditto.
* test/ruby/test_settracefunc.rb: tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:15:27 -04:00
|
|
|
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp);
|
2017-10-28 06:43:30 -04:00
|
|
|
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp);
|
2018-10-07 09:34:59 -04:00
|
|
|
MJIT_STATIC VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler);
|
2009-01-11 20:43:23 -05:00
|
|
|
|
2017-04-09 00:01:07 -04:00
|
|
|
void rb_vm_register_special_exception_str(enum ruby_special_exceptions sp, VALUE exception_class, VALUE mesg);
|
|
|
|
|
|
|
|
#define rb_vm_register_special_exception(sp, e, m) \
|
|
|
|
rb_vm_register_special_exception_str(sp, e, rb_usascii_str_new_static((m), (long)rb_strlen_lit(m)))
|
2014-09-11 06:53:48 -04:00
|
|
|
|
2017-09-10 11:49:45 -04:00
|
|
|
void rb_gc_mark_machine_stack(const rb_execution_context_t *ec);
|
2007-11-20 05:47:53 -05:00
|
|
|
|
2015-06-03 15:12:26 -04:00
|
|
|
void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr);
|
2015-02-22 02:05:14 -05:00
|
|
|
|
2018-10-07 09:34:59 -04:00
|
|
|
MJIT_STATIC const rb_callable_method_entry_t *rb_vm_frame_method_entry(const rb_control_frame_t *cfp);
|
2015-06-02 00:20:30 -04:00
|
|
|
|
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
|
|
|
|
2017-06-23 04:24:54 -04:00
|
|
|
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr);
|
|
|
|
|
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
|
2017-10-21 02:22:43 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_BEGIN
|
|
|
|
|
2018-08-07 12:27:45 -04:00
|
|
|
RUBY_EXTERN rb_vm_t *ruby_current_vm_ptr;
|
|
|
|
RUBY_EXTERN rb_execution_context_t *ruby_current_execution_context_ptr;
|
|
|
|
RUBY_EXTERN rb_event_flag_t ruby_vm_event_flags;
|
2018-11-26 13:16:39 -05:00
|
|
|
RUBY_EXTERN rb_event_flag_t ruby_vm_event_enabled_global_flags;
|
|
|
|
RUBY_EXTERN unsigned int ruby_vm_event_local_num;
|
* 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
|
|
|
|
2017-10-21 02:22:43 -04:00
|
|
|
RUBY_SYMBOL_EXPORT_END
|
|
|
|
|
2017-11-07 01:01:16 -05:00
|
|
|
#define GET_VM() rb_current_vm()
|
|
|
|
#define GET_THREAD() rb_current_thread()
|
|
|
|
#define GET_EC() rb_current_execution_context()
|
2017-10-26 04:32:49 -04:00
|
|
|
|
|
|
|
static inline rb_thread_t *
|
|
|
|
rb_ec_thread_ptr(const rb_execution_context_t *ec)
|
|
|
|
{
|
2017-10-29 08:57:04 -04:00
|
|
|
return ec->thread_ptr;
|
2017-10-26 04:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline rb_vm_t *
|
|
|
|
rb_ec_vm_ptr(const rb_execution_context_t *ec)
|
|
|
|
{
|
2017-10-29 08:57:04 -04:00
|
|
|
const rb_thread_t *th = rb_ec_thread_ptr(ec);
|
2017-10-26 04:32:49 -04:00
|
|
|
if (th) {
|
2017-10-29 08:57:04 -04:00
|
|
|
return th->vm;
|
2017-10-26 04:32:49 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline rb_execution_context_t *
|
2017-11-07 01:01:16 -05:00
|
|
|
rb_current_execution_context(void)
|
2017-10-26 04:32:49 -04:00
|
|
|
{
|
|
|
|
return ruby_current_execution_context_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline rb_thread_t *
|
2017-11-07 01:01:16 -05:00
|
|
|
rb_current_thread(void)
|
2017-10-26 04:32:49 -04:00
|
|
|
{
|
|
|
|
const rb_execution_context_t *ec = GET_EC();
|
|
|
|
return rb_ec_thread_ptr(ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline rb_vm_t *
|
2017-11-07 01:01:16 -05:00
|
|
|
rb_current_vm(void)
|
2017-10-26 04:32:49 -04:00
|
|
|
{
|
|
|
|
VM_ASSERT(ruby_current_vm_ptr == NULL ||
|
|
|
|
ruby_current_execution_context_ptr == NULL ||
|
|
|
|
rb_ec_thread_ptr(GET_EC()) == NULL ||
|
|
|
|
rb_ec_vm_ptr(GET_EC()) == ruby_current_vm_ptr);
|
|
|
|
return ruby_current_vm_ptr;
|
|
|
|
}
|
* 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
|
|
|
|
2018-11-17 20:37:41 -05:00
|
|
|
static inline void
|
|
|
|
rb_thread_set_current_raw(const rb_thread_t *th)
|
|
|
|
{
|
|
|
|
ruby_current_execution_context_ptr = th->ec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rb_thread_set_current(rb_thread_t *th)
|
|
|
|
{
|
|
|
|
if (th->vm->running_thread != th) {
|
2018-11-17 20:37:45 -05:00
|
|
|
th->running_time_us = 0;
|
2018-11-17 20:37:41 -05:00
|
|
|
}
|
|
|
|
rb_thread_set_current_raw(th);
|
|
|
|
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
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
2017-11-06 02:44:28 -05:00
|
|
|
#define RUBY_VM_SET_TIMER_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TIMER_INTERRUPT_MASK)
|
|
|
|
#define RUBY_VM_SET_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, PENDING_INTERRUPT_MASK)
|
|
|
|
#define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
|
|
|
|
#define RUBY_VM_SET_TRAP_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TRAP_INTERRUPT_MASK)
|
|
|
|
#define RUBY_VM_INTERRUPTED(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask & \
|
|
|
|
(PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
|
|
|
|
#define RUBY_VM_INTERRUPTED_ANY(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask)
|
2007-12-24 23:16:06 -05:00
|
|
|
|
2016-05-29 06:18:20 -04:00
|
|
|
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt);
|
2010-10-09 16:33:21 -04:00
|
|
|
int rb_signal_buff_size(void);
|
2018-08-18 05:07:36 -04:00
|
|
|
int 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);
|
2018-08-18 05:07:36 -04:00
|
|
|
int 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);
|
2017-10-29 10:06:58 -04:00
|
|
|
void rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo);
|
2017-09-10 15:00:08 -04:00
|
|
|
void rb_execution_context_mark(const rb_execution_context_t *ec);
|
2017-10-26 04:32:49 -04:00
|
|
|
void rb_fiber_close(rb_fiber_t *fib);
|
|
|
|
void Init_native_thread(rb_thread_t *th);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2017-11-07 01:01:16 -05:00
|
|
|
#define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec)
|
2015-07-17 03:28:53 -04:00
|
|
|
static inline void
|
2017-11-07 01:01:16 -05:00
|
|
|
rb_vm_check_ints(rb_execution_context_t *ec)
|
2015-07-17 03:28:53 -04:00
|
|
|
{
|
2017-11-07 01:01:16 -05:00
|
|
|
VM_ASSERT(ec == GET_EC());
|
2017-11-06 02:44:28 -05:00
|
|
|
if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(ec))) {
|
|
|
|
rb_threadptr_execute_interrupts(rb_ec_thread_ptr(ec), 0);
|
2015-07-17 03:28:53 -04:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-07-02 08:49:35 -04:00
|
|
|
/* tracer */
|
2018-11-26 13:16:39 -05:00
|
|
|
|
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;
|
2017-10-29 09:17:37 -04:00
|
|
|
rb_execution_context_t *ec;
|
|
|
|
const rb_control_frame_t *cfp;
|
2012-11-20 04:48:24 -05:00
|
|
|
VALUE self;
|
|
|
|
ID id;
|
* vm_trace.c (tracepoint_attr_callee_id, rb_tracearg_callee_id):
add TracePoint#callee_id. [ruby-core:77241] [Feature #12747]
* cont.c, eval.c, gc.c, include/ruby/intern.h, insns.def, thread.c,
vm.c, vm_backtrace.c, vm_core.h, vm_eval.c, vm_insnhelper.c, vm_trace.c: ditto.
* test/ruby/test_settracefunc.rb: tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:15:27 -04:00
|
|
|
ID called_id;
|
2012-11-20 04:48:24 -05:00
|
|
|
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
|
|
|
|
2018-11-26 13:16:39 -05:00
|
|
|
void rb_hook_list_mark(rb_hook_list_t *hooks);
|
|
|
|
void rb_hook_list_free(rb_hook_list_t *hooks);
|
2018-11-26 15:16:14 -05:00
|
|
|
void rb_hook_list_connect_tracepoint(VALUE target, rb_hook_list_t *list, VALUE tpval, unsigned int target_line);
|
2018-11-26 13:16:39 -05:00
|
|
|
void rb_hook_list_remove_tracepoint(rb_hook_list_t *list, VALUE tpval);
|
2012-11-20 04:48:24 -05:00
|
|
|
|
2018-11-26 13:16:39 -05:00
|
|
|
void rb_exec_event_hooks(struct rb_trace_arg_struct *trace_arg, rb_hook_list_t *hooks, int pop_p);
|
|
|
|
|
|
|
|
#define EXEC_EVENT_HOOK_ORIG(ec_, hooks_, flag_, self_, id_, called_id_, klass_, data_, pop_p_) do { \
|
2015-07-17 03:28:22 -04:00
|
|
|
const rb_event_flag_t flag_arg_ = (flag_); \
|
2018-11-26 13:16:39 -05:00
|
|
|
rb_hook_list_t *hooks_arg_ = (hooks_); \
|
|
|
|
if (UNLIKELY((hooks_arg_)->events & (flag_arg_))) { \
|
|
|
|
/* defer evaluating the other arguments */ \
|
2018-11-26 13:16:54 -05:00
|
|
|
rb_exec_event_hook_orig(ec_, hooks_arg_, flag_arg_, self_, id_, called_id_, klass_, data_, pop_p_); \
|
2007-07-02 08:49:35 -04:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-07-17 03:28:22 -04:00
|
|
|
static inline void
|
2018-11-26 13:16:39 -05:00
|
|
|
rb_exec_event_hook_orig(rb_execution_context_t *ec, rb_hook_list_t *hooks, rb_event_flag_t flag,
|
|
|
|
VALUE self, ID id, ID called_id, VALUE klass, VALUE data, int pop_p)
|
2015-07-17 03:28:22 -04:00
|
|
|
{
|
2017-11-17 01:59:22 -05:00
|
|
|
struct rb_trace_arg_struct trace_arg;
|
|
|
|
|
2018-11-26 13:16:39 -05:00
|
|
|
VM_ASSERT((hooks->events & flag) != 0);
|
2017-11-17 01:59:22 -05:00
|
|
|
|
|
|
|
trace_arg.event = flag;
|
|
|
|
trace_arg.ec = ec;
|
|
|
|
trace_arg.cfp = ec->cfp;
|
|
|
|
trace_arg.self = self;
|
|
|
|
trace_arg.id = id;
|
|
|
|
trace_arg.called_id = called_id;
|
|
|
|
trace_arg.klass = klass;
|
|
|
|
trace_arg.data = data;
|
|
|
|
trace_arg.path = Qundef;
|
|
|
|
trace_arg.klass_solved = 0;
|
2018-11-26 13:16:39 -05:00
|
|
|
|
|
|
|
rb_exec_event_hooks(&trace_arg, hooks, pop_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline rb_hook_list_t *
|
|
|
|
rb_vm_global_hooks(const rb_execution_context_t *ec)
|
|
|
|
{
|
|
|
|
return &rb_ec_vm_ptr(ec)->global_hooks;
|
2015-07-17 03:28:22 -04:00
|
|
|
}
|
|
|
|
|
2017-10-29 09:19:14 -04:00
|
|
|
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_) \
|
2018-11-26 13:16:39 -05:00
|
|
|
EXEC_EVENT_HOOK_ORIG(ec_, rb_vm_global_hooks(ec_), flag_, self_, id_, called_id_, klass_, data_, 0)
|
2017-11-17 01:59:22 -05:00
|
|
|
|
2017-10-29 09:19:14 -04:00
|
|
|
#define EXEC_EVENT_HOOK_AND_POP_FRAME(ec_, flag_, self_, id_, called_id_, klass_, data_) \
|
2018-11-26 13:16:39 -05:00
|
|
|
EXEC_EVENT_HOOK_ORIG(ec_, rb_vm_global_hooks(ec_), flag_, self_, id_, called_id_, klass_, data_, 1)
|
2012-12-25 08:24:17 -05:00
|
|
|
|
2018-12-27 12:39:17 -05:00
|
|
|
static inline void
|
|
|
|
rb_exec_event_hook_script_compiled(rb_execution_context_t *ec, const rb_iseq_t *iseq, VALUE eval_script)
|
|
|
|
{
|
|
|
|
EXEC_EVENT_HOOK(ec, RUBY_EVENT_SCRIPT_COMPILED, ec->cfp->self, 0, 0, 0,
|
|
|
|
NIL_P(eval_script) ? (VALUE)iseq :
|
|
|
|
rb_ary_new_from_args(2, eval_script, (VALUE)iseq));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2017-12-06 02:19:17 -05:00
|
|
|
/* #define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 */ /* from vm_core.h */
|
2017-12-19 23:24:14 -05:00
|
|
|
#define RUBY_EVENT_COVERAGE_LINE 0x010000
|
|
|
|
#define RUBY_EVENT_COVERAGE_BRANCH 0x020000
|
2017-12-06 02:19:17 -05:00
|
|
|
|
2010-08-14 01:58:19 -04:00
|
|
|
extern VALUE rb_get_coverages(void);
|
2017-12-05 02:16:42 -05:00
|
|
|
extern void rb_set_coverages(VALUE, int, VALUE);
|
2018-10-20 01:33:04 -04:00
|
|
|
extern void rb_clear_coverages(void);
|
2010-08-14 01:58:19 -04:00
|
|
|
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 */
|