Commit graph

21 commits

Author SHA1 Message Date
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
NARUSE, Yui
147453ad1e merge revision(s) 85b5d4c8bf: [Backport #17509]
Revert "[Bug #11213] let defined?(super) call respond_to_missing?"

	This reverts commit fac2498e02 for
	now, due to [Bug #17509], the breakage in the case `super` is
	called in `respond_to?`.
	---
	 internal/vm.h             |  2 +-
	 test/ruby/test_defined.rb | 33 ---------------------------------
	 vm_insnhelper.c           |  4 ++--
	 vm_method.c               | 12 +++++++-----
	 4 files changed, 10 insertions(+), 41 deletions(-)
2021-02-01 19:16:54 +09:00
Marc-André Lafortune
db2ebbd71b
Optimize calls to Kernel#hash (#3987)
This avoids recursive checks when the `hash` method of an object
isn't specialized.
2020-12-25 02:08:12 +09:00
Takashi Kokubun
692af8e8f8
Prefer stdbool in vm_exec
Make the code a bit modern and consistent with some other places.
2020-12-21 21:16:39 -08:00
Koichi Sasada
aa6287cd26 fix inline method cache sync bug
`cd` is passed to method call functions to method invocation
functions, but `cd` can be manipulated by other ractors simultaneously
so it contains thread-safety issue.

To solve this issue, this patch stores `ci` and found `cc` to `calling`
and stops to pass `cd`.
2020-12-15 13:29:30 +09:00
Nobuyoshi Nakada
fac2498e02 [Bug #11213] let defined?(super) call respond_to_missing? 2020-11-20 16:04:45 +09:00
Alan Wu
6817f4c6b1 rb_vm_add_root_module(): Remove unused parameter 2020-11-09 16:08:36 -05:00
Aaron Patterson
67b2c21c32
Add GC.auto_compact= true/false and GC.auto_compact
* `GC.auto_compact=`, `GC.auto_compact` can be used to control when
  compaction runs.  Setting `auto_compact=` to true will cause
  compaction to occurr duing major collections.  At the moment,
  compaction adds significant overhead to major collections, so please
  test first!

[Feature #17176]
2020-11-02 14:42:48 -08:00
Samuel Williams
0a218a97ad Expose ec -> backtrace (internal) and use it to implement fiber backtrace.
See <https://bugs.ruby-lang.org/issues/16815> for more details.
2020-08-18 00:56:35 +12:00
Nobuyoshi Nakada
184f78314e Properly resolve refinements in defined? on private call [Bug #16932] 2020-06-04 02:12:57 +09:00
卜部昌平
9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平
d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平
5dc6080cb8 delete CACHELINE
Since https://github.com/ruby/ruby/pull/2888 this macro is no longer
used in any place.
2020-04-13 16:38:22 +09:00
卜部昌平
4ff3f20540 add #include guard hack
According to MSVC manual (*1), cl.exe can skip including a header file
when that:

- contains #pragma once, or
- starts with #ifndef, or
- starts with #if ! defined.

GCC has a similar trick (*2), but it acts more stricter (e. g. there
must be _no tokens_ outside of #ifndef...#endif).

Sun C lacked #pragma once for a looong time.  Oracle Developer Studio
12.5 finally implemented it, but we cannot assume such recent version.

This changeset modifies header files so that each of them include
strictly one #ifndef...#endif.  I believe this is the most portable way
to trigger compiler optimizations. [Bug #16770]

*1: https://docs.microsoft.com/en-us/cpp/preprocessor/once
*2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
2020-04-13 16:06:00 +09:00
卜部昌平
9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Koichi Sasada
b9007b6c54 Introduce disposable call-cache.
This patch contains several ideas:

(1) Disposable inline method cache (IMC) for race-free inline method cache
    * Making call-cache (CC) as a RVALUE (GC target object) and allocate new
      CC on cache miss.
    * This technique allows race-free access from parallel processing
      elements like RCU.
(2) Introduce per-Class method cache (pCMC)
    * Instead of fixed-size global method cache (GMC), pCMC allows flexible
      cache size.
    * Caching CCs reduces CC allocation and allow sharing CC's fast-path
      between same call-info (CI) call-sites.
(3) Invalidate an inline method cache by invalidating corresponding method
    entries (MEs)
    * Instead of using class serials, we set "invalidated" flag for method
      entry itself to represent cache invalidation.
    * Compare with using class serials, the impact of method modification
      (add/overwrite/delete) is small.
    * Updating class serials invalidate all method caches of the class and
      sub-classes.
    * Proposed approach only invalidate the method cache of only one ME.

See [Feature #16614] for more details.
2020-02-22 09:58:59 +09:00
Koichi Sasada
f2286925f0 VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).

iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).

To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).

struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.

rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-02-22 09:58:59 +09:00
Jeremy Evans
beae6cbf0f Fully separate positional arguments and keyword arguments
This removes the warnings added in 2.7, and changes the behavior
so that a final positional hash is not treated as keywords or
vice-versa.

To handle the arg_setup_block splat case correctly with keyword
arguments, we need to check if we are taking a keyword hash.
That case didn't have a test, but it affects real-world code,
so add a test for it.

This removes rb_empty_keyword_given_p() and related code, as
that is not needed in Ruby 3.  The empty keyword case is the
same as the no keyword case in Ruby 3.

This changes rb_scan_args to implement keyword argument
separation for C functions when the : character is used.
For backwards compatibility, it returns a duped hash.
This is a bad idea for performance, but not duping the hash
breaks at least Enumerator::ArithmeticSequence#inspect.

Instead of having RB_PASS_CALLED_KEYWORDS be a number,
simplify the code by just making it be rb_keyword_given_p().
2020-01-02 18:40:45 -08:00
卜部昌平
5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
卜部昌平
3ae09b30f8 internal/vm.h rework
Rearranged contents, then added MJIT_FUNC_EXPORTED function
declarations.
2019-12-26 20:45:12 +09:00
卜部昌平
b739a63eb4 split internal.h into files
One day, I could not resist the way it was written.  I finally started
to make the code clean.  This changeset is the beginning of a series of
housekeeping commits.  It is a simple refactoring; split internal.h into
files, so that we can divide and concur in the upcoming commits.  No
lines of codes are either added or removed, except the obvious file
headers/footers.  The generated binary is identical to the one before.
2019-12-26 20:45:12 +09:00