1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/internal/vm.h
NARUSE, Yui de6072a22e merge revision(s) abdc634f64a440afcdc7f23c9757d27aab4db8a9,083c5f08ec4e95c9b75810d46f933928327a5ab3,1ecda213668644d656eb0d60654737482447dd92,813fe4c256f89babebb8ab53821ae5eb6bb138c6: [Backport #17497]
remove unused decl

	---
	 internal/vm.h | 6 ------
	 vm_args.c     | 2 --
	 2 files changed, 8 deletions(-)

	Check stack overflow in recursive glob_helper [Bug #17162]

	---
	 dir.c         |  2 ++
	 internal/vm.h |  1 +
	 vm_eval.c     | 10 ++++++++++
	 3 files changed, 13 insertions(+)

	global call-cache cache table for rb_funcall*

	rb_funcall* (rb_funcall(), rb_funcallv(), ...) functions invokes
	Ruby's method with given receiver. Ruby 2.7 introduced inline method
	cache with static memory area. However, Ruby 3.0 reimplemented the
	method cache data structures and the inline cache was removed.

	Without inline cache, rb_funcall* searched methods everytime.
	Most of cases per-Class Method Cache (pCMC) will be helped but
	pCMC requires VM-wide locking and it hurts performance on
	multi-Ractor execution, especially all Ractors calls methods
	with rb_funcall*.

	This patch introduced Global Call-Cache Cache Table (gccct) for
	rb_funcall*. Call-Cache was introduced from Ruby 3.0 to manage
	method cache entry atomically and gccct enables method-caching
	without VM-wide locking. This table solves the performance issue
	on multi-ractor execution.
	[Bug #17497]

	Ruby-level method invocation does not use gccct because it has
	inline-method-cache and the table size is limited. Basically
	rb_funcall* is not used frequently, so 1023 entries can be enough.
	We will revisit the table size if it is not enough.
	---
	 debug_counter.h |   3 +
	 vm.c            |  12 +++
	 vm_callinfo.h   |  12 ---
	 vm_core.h       |   5 +
	 vm_eval.c       | 288 ++++++++++++++++++++++++++++++++++++++++++--------------
	 vm_insnhelper.c |  11 ++-
	 vm_method.c     |  14 ++-
	 7 files changed, 255 insertions(+), 90 deletions(-)

	opt_equality_by_mid for rb_equal_opt

	This patch improves the performance of sequential and parallel
	execution of rb_equal() (and rb_eql()).
	[Bug #17497]

	rb_equal_opt (and rb_eql_opt) does not have own cd and it waste
	a time to initialize cd. This patch introduces opt_equality_by_mid()
	to check equality without cd.

	Furthermore, current master uses "static" cd on rb_equal_opt
	(and rb_eql_opt) and it hurts CPU caches on multi-thread execution.
	Now they are gone so there are no bottleneck on parallel execution.
	---
	 vm_insnhelper.c | 99 ++++++++++++++++++++++++++++++++++++---------------------
	 1 file changed, 63 insertions(+), 36 deletions(-)
2021-03-11 20:24:48 +09:00

131 lines
5.1 KiB
C

#ifndef INTERNAL_VM_H /*-*-C-*-vi:se ft=c:*/
#define INTERNAL_VM_H
/**
* @file
* @author Ruby developers <ruby-core@ruby-lang.org>
* @copyright This file is a part of the programming language Ruby.
* Permission is hereby granted, to either redistribute and/or
* modify this file, provided that the conditions mentioned in the
* file COPYING are met. Consult the file for details.
* @brief Internal header for RubyVM.
*/
#include "ruby/internal/stdbool.h" /* for bool */
#include "internal/serial.h" /* for rb_serial_t */
#include "internal/static_assert.h" /* for STATIC_ASSERT */
#include "ruby/ruby.h" /* for ID */
#include "ruby/st.h" /* for st_table */
#ifdef rb_funcallv
# undef rb_funcallv
#endif
#ifdef rb_method_basic_definition_p
# undef rb_method_basic_definition_p
#endif
struct rb_callable_method_entry_struct; /* in method.h */
struct rb_method_definition_struct; /* in method.h */
struct rb_execution_context_struct; /* in vm_core.h */
struct rb_control_frame_struct; /* in vm_core.h */
struct rb_callinfo; /* in vm_core.h */
enum method_missing_reason {
MISSING_NOENTRY = 0x00,
MISSING_PRIVATE = 0x01,
MISSING_PROTECTED = 0x02,
MISSING_FCALL = 0x04,
MISSING_VCALL = 0x08,
MISSING_SUPER = 0x10,
MISSING_MISSING = 0x20,
MISSING_NONE = 0x40
};
/* vm_insnhelper.h */
rb_serial_t rb_next_class_serial(void);
/* vm.c */
VALUE rb_obj_is_thread(VALUE obj);
void rb_vm_mark(void *ptr);
void rb_vm_each_stack_value(void *ptr, void (*cb)(VALUE, void*), void *ctx);
PUREFUNC(VALUE rb_vm_top_self(void));
void rb_vm_inc_const_missing_count(void);
const void **rb_vm_get_insns_address_table(void);
VALUE rb_source_location(int *pline);
const char *rb_source_location_cstr(int *pline);
MJIT_STATIC void rb_vm_pop_cfunc_frame(void);
int rb_vm_add_root_module(VALUE module);
void rb_vm_check_redefinition_by_prepend(VALUE klass);
int rb_vm_check_optimizable_mid(VALUE mid);
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
MJIT_STATIC VALUE ruby_vm_special_exception_copy(VALUE);
PUREFUNC(st_table *rb_vm_fstring_table(void));
MJIT_SYMBOL_EXPORT_BEGIN
VALUE vm_exec(struct rb_execution_context_struct *, bool); /* used in JIT-ed code */
MJIT_SYMBOL_EXPORT_END
/* vm_eval.c */
VALUE rb_current_realfilepath(void);
VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE);
typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE);
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
rb_check_funcall_hook *hook, VALUE arg);
VALUE rb_check_funcall_with_hook_kw(VALUE recv, ID mid, int argc, const VALUE *argv,
rb_check_funcall_hook *hook, VALUE arg, int kw_splat);
const char *rb_type_str(enum ruby_value_type type);
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
VALUE rb_check_funcall_basic_kw(VALUE, ID, VALUE, int, const VALUE*, int);
VALUE rb_yield_1(VALUE val);
VALUE rb_yield_force_blockarg(VALUE values);
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
rb_block_call_func_t bl_proc, int min_argc, int max_argc,
VALUE data2);
void rb_check_stack_overflow(void);
/* vm_insnhelper.c */
VALUE rb_equal_opt(VALUE obj1, VALUE obj2);
VALUE rb_eql_opt(VALUE obj1, VALUE obj2);
struct rb_iseq_struct;
MJIT_SYMBOL_EXPORT_BEGIN
const struct rb_callcache *rb_vm_search_method_slowpath(const struct rb_callinfo *ci, VALUE klass);
MJIT_SYMBOL_EXPORT_END
/* vm_method.c */
struct rb_execution_context_struct;
MJIT_SYMBOL_EXPORT_BEGIN
int rb_ec_obj_respond_to(struct rb_execution_context_struct *ec, VALUE obj, ID id, int priv);
MJIT_SYMBOL_EXPORT_END
/* vm_dump.c */
void rb_print_backtrace(void);
/* vm_backtrace.c */
VALUE rb_vm_thread_backtrace(int argc, const VALUE *argv, VALUE thval);
VALUE rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval);
VALUE rb_vm_backtrace(int argc, const VALUE * argv, struct rb_execution_context_struct * ec);
VALUE rb_vm_backtrace_locations(int argc, const VALUE * argv, struct rb_execution_context_struct * ec);
VALUE rb_make_backtrace(void);
void rb_backtrace_print_as_bugreport(void);
int rb_backtrace_p(VALUE obj);
VALUE rb_backtrace_to_str_ary(VALUE obj);
VALUE rb_backtrace_to_location_ary(VALUE obj);
void rb_backtrace_each(VALUE (*iter)(VALUE recv, VALUE str), VALUE output);
MJIT_SYMBOL_EXPORT_BEGIN
VALUE rb_ec_backtrace_object(const struct rb_execution_context_struct *ec);
void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self);
MJIT_SYMBOL_EXPORT_END
#define RUBY_DTRACE_CREATE_HOOK(name, arg) \
RUBY_DTRACE_HOOK(name##_CREATE, arg)
#define RUBY_DTRACE_HOOK(name, arg) \
do { \
if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
int dtrace_line; \
const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \
if (!dtrace_file) dtrace_file = ""; \
RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \
} \
} while (0)
#endif /* INTERNAL_VM_H */