440 Commits
Author SHA1 Message Date
nagachika 6175823bab merge revision(s) 7ff1bf317887c0d7b21e91ad548d07b9f05c540c,e89d80702bd98a8276243a7fcaa2a158b3bfb659: [Backport #18516]
An alias can suppress method redefinition warning

	---
	 test/ruby/test_alias.rb | 11 +++++++++++
	 1 file changed, 11 insertions(+)

	Fix memory leak at the same named alias [Bug #18516]

	When aliasing a method to the same name method, set a separate bit
	flag on that method definition, instead of the reference count
	increment.  Although this kind of alias has no actual effect at
	runtime, is used as the hack to suppress the method re-definition
	warning.
	---
	 method.h                |  1 +
	 test/ruby/test_alias.rb | 18 ++++++++++++++++++
	 vm_method.c             |  9 ++++++++-
	 3 files changed, 27 insertions(+), 1 deletion(-)
2022-03-13 11:52:53 +09:00
nagachika 7b3948750e merge revision(s) e1b03b0c2b2449a7794f4701bab8b2382eb15116,007e439fe965871c73127928f7244ebb96a86e58:
Enable VM_ASSERT in --jit CIs (#4543)

	---
	 .github/workflows/mjit.yml | 2 +-
	 ractor.c                   | 6 +++---
	 vm_core.h                  | 6 +++---
	 vm_method.c                | 2 +-
	 4 files changed, 8 insertions(+), 8 deletions(-)

	Do not expect ec on rb_vm_bugreport

	because a SEGV might happen on an MJIT worker. As you can clearly see
	from `if (vm && ec) {`, ec is not guaranteed to exist here.
	---
	 vm_dump.c | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)
2021-11-24 12:03:46 +09:00
nagachika a21ec8d1ec merge revision(s) 636d4f7eb9: [Backport #17822]
Avoid setting the visibility of refinement method entries

	Since refinement search is always performed, these entries should always
	be public. The method entry that the refinement search returns decides
	the visibility.

	Fixes [Bug #17822]
	---
	 test/ruby/test_refinement.rb | 22 ++++++++++++++++++++++
	 vm_method.c                  | 15 ++++++++++-----
	 2 files changed, 32 insertions(+), 5 deletions(-)
2021-05-29 14:36:28 +09:00
nagachika d47df50678 merge revision(s) 39a2ba5cc5: [Backport #17806]
Method cache: fix refinement entry handling

	To invalidate some callable method entries, we replace the entry in the
	class. Most types of method entries are on the method table of the
	origin class, but refinement entries without an orig_me are housed in
	the method table of the class itself. They are there because refinements
	take priority over prepended methods.

	By unconditionally inserting a copy of the refinement entry into the
	origin class, clearing the method cache created situations where there
	are refinement entry duplicates in the lookup chain, leading to infinite
	loops and other problems.

	Update the replacement logic to use the right class that houses the
	method entry. Also, be more selective about cache invalidation when
	moving refinement entries for prepend. This avoids calling
	clear_method_cache_by_id_in_class() before refinement entries are in the
	place it expects.

	[Bug #17806]
	---
	 class.c                      |  4 +++-
	 test/ruby/test_refinement.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++
	 vm_method.c                  | 13 ++++++++++--
	 3 files changed, 63 insertions(+), 3 deletions(-)
2021-05-29 14:35:12 +09:00
nagachika 7b6a2ad04a merge revision(s) 4b36a597f4: [Backport #17519]
Fix setting method visibility for a refinement without an origin
	 class

	If a class has been refined but does not have an origin class,
	there is a single method entry marked with VM_METHOD_TYPE_REFINED,
	but it contains the original method entry.  If the original method
	entry is present, we shouldn't skip the method when searching even
	when skipping refined methods.

	Fixes [Bug #17519]
	---
	 test/ruby/test_module.rb | 110 ++++++++++++++++++++++++++++++++++++++++++++++-
	 vm_method.c              |   3 +-
	 2 files changed, 111 insertions(+), 2 deletions(-)
2021-05-29 14:34:00 +09:00
NARUSE, Yui d1cec0bca5 merge revision(s) 58660e9434: [Backport #17519]
Skip refined method when exporting methods with changed visibility

	Previously, attempting to change the visibility of a method in a
	singleton class for a class/module that is prepended to and refined
	would raise a NoMethodError.

	Fixes [Bug #17519]
	---
	 test/ruby/test_module.rb | 23 +++++++++++++++++++++++
	 vm_method.c              | 14 +++++++++++---
	 2 files changed, 34 insertions(+), 3 deletions(-)
2021-04-02 12:26:56 +09:00
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 38f9c832e8 merge revision(s) 49d3830f44: [Backport #17560]
Fix documentation for Module#ruby2_keywords

	It returns nil, not self.

	Fixes [Bug #17560]
	---
	 vm_method.c | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)
2021-02-16 13:13:27 +09:00
NARUSE, Yui fb6cb226a0 merge revision(s) 8dfae85adb: [Backport #17575]
Warn the defined location as deprecation as well as the main message

	[Bug #17575]
	---
	 test/ruby/test_defined.rb | 17 +++++++++++++++++
	 vm_method.c               |  3 ++-
	 2 files changed, 19 insertions(+), 1 deletion(-)
2021-02-02 15:49:51 +09:00
NARUSE, Yui 7899046315 merge revision(s) eeacdcb9a0: [Backport #17558]
Fixed premature return

	After setting ruby2_keywords for bmethod, the rest of arguments
	had been ignored. [Bug #17558]
	---
	 test/ruby/test_keyword.rb | 9 +++++++++
	 vm_method.c               | 2 +-
	 2 files changed, 10 insertions(+), 1 deletion(-)
2021-02-02 15:47:50 +09:00
NARUSE, Yui 138f0ba6da merge revision(s) 0ed71b37fa: [Backport #17536]
Don't try to clear cache on garbage objects

	Method cache can be cleared during lazy sweeping.  An object that will
	be collected during lazy sweep *should not* have it's method cache
	cleared.  Soon-to-be-collected objects can be in an inconsistent state and
	this can lead to a crash.  This patch just leaves early if the object is
	going to be collected.

	Fixes [Bug #17536]

	Co-Authored-By: John Hawthorn <john@hawthorn.email>
	Co-Authored-By: Alan Wu <XrXr@users.noreply.github.com>
	---
	 vm_method.c | 1 +
	 1 file changed, 1 insertion(+)
2021-02-01 23:06:33 +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
Yusuke Endoh 3a81daaf8d Module#public_class_method also accepts a symbol array as an argument
I'm unsure if this is intentional, but add a document anyway.
[Feature #17314]
2020-12-24 00:15:29 +09:00
Koichi Sasada 02d9524cda separate rb_ractor_pub from rb_ractor_t
separate some fields from rb_ractor_t to rb_ractor_pub and put it
at the beggining of rb_ractor_t and declare it in vm_core.h so
vm_core.h can access rb_ractor_pub fields.

Now rb_ec_ractor_hooks() is a complete inline function and no
MJIT related issue.
2020-12-22 00:03:00 +09:00
Radosław Bułat eb8ea336d3 Feature 17314: allow to pass array to public, protected and private methods 2020-12-19 18:19:49 +09:00
Radosław Bułat 51bcd50915 Feature 17314: alias_method returns symbol 2020-12-19 12:23:58 +09:00
Koichi Sasada 04d62e6f62 fix method cache debug tool 2020-12-19 04:33:04 +09:00
Jeremy Evans 05313c914b Use category: :deprecated in warnings that are related to deprecation
Also document that both :deprecated and :experimental are supported
:category option values.

The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.

Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).

Add assert_deprecated_warn to test assertions.  Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Yusuke Endoh 982443e6e3 Revert "Better cooperation between public/protected/private with attr* and alias_method"
This reverts commit 81739ad4fd.
2020-12-18 16:08:55 +09:00
Yusuke Endoh c4e50b58d1 Revert "Added missing tests for public, private, protected and alias_method"
This reverts commit e042e8460b.
2020-12-18 16:08:24 +09:00
Nobuyoshi Nakada e042e8460b Added missing tests for public, private, protected and alias_method 2020-12-18 12:59:01 +09:00
Radosław Bułat 81739ad4fd Better cooperation between public/protected/private with attr* and alias_method 2020-12-17 12:46:02 -05:00
Koichi Sasada c37ba2c547 add ccs_not_found debug counter
ccs_not_found to count not found in ccs table.
2020-12-14 18:17:35 +09:00
Koichi Sasada 53edb27bac use method cache on Object#respond_to?
rb_method_boundp (method_boundp) searches method_entry, but this
search did not use pCMC, so change to use it.
2020-12-14 15:28:09 +09:00
Koichi Sasada a8aa169b8f add cc_invalidate_negative debug counter
counts for invalidating negative cache.
2020-12-14 11:57:46 +09:00
Koichi Sasada 967040ba59 Introduce negative method cache
pCMC doesn't have negative method cache so this patch  implements it.
2020-12-14 11:57:46 +09:00
Koichi Sasada 182fb73c40 rb_ext_ractor_safe() to declare ractor-safe ext
C extensions can violate the ractor-safety, so only ractor-safe
C extensions (C methods) can run on non-main ractors.
rb_ext_ractor_safe(true) declares that the successive
defined methods are ractor-safe. Otherwiwze, defined methods
checked they are invoked in main ractor and raise an error
if invoked at non-main ractors.

[Feature #17307]
2020-12-01 15:44:18 +09:00
Nobuyoshi Nakada fac2498e02 [Bug #11213] let defined?(super) call respond_to_missing? 2020-11-20 16:04:45 +09:00
Alan Wu c56fdaecc4 Revert assert for debugging on CI
This reverts commit ac69849e49.
The bug seems to have been fixed.
2020-10-26 16:44:15 -04:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Aaron Patterson b9488accf9 Fix ASAN support when invalidating CCs
Again, this code is walking the heap.  Empty slots can be poisoned, so
we need to unpoison before checking the type
2020-09-28 08:20:23 -07:00
Koichi Sasada caaa36b4e6 prohibi method call by defined_method in other racotrs
We can not call a non-isolated Proc in multiple ractors.
2020-09-25 20:37:38 +09:00
Koichi Sasada ea78960ee5 sync callable_method_entry()
callable_method_entry() read/write method table structures so that
this function should be synchronized between Ractors.
2020-09-10 18:44:02 +09:00
Alan Wu 264e4cd04f Remove write barrier exemption for T_ICLASS
Before this commit, iclasses were "shady", or not protected by write
barriers. Because of that, the GC needs to spend more time marking these
objects than otherwise.

Applications that make heavy use of modules should see reduction in GC
time as they have a significant number of live iclasses on the heap.

 - Put logic for iclass method table ownership into a function
 - Remove calls to WB_UNPROTECT and insert write barriers for iclasses

This commit relies on the following invariant: for any non oirigin
iclass `I`, `RCLASS_M_TBL(I) == RCLASS_M_TBL(RBasic(I)->klass)`. This
invariant did not hold prior to 98286e9 for classes and modules that
have prepended modules.

[Feature #16984]
2020-08-17 17:17:47 -04:00
Alan Wu ac69849e49 Enable an assert on all configs for debugging
I'm trying to get a better understanding for rare crashes that happen on
ci:
 - http://ci.rvm.jp/results/trunk_clang_10@silicon-docker/3101898
 - http://ci.rvm.jp/results/trunk-test@ruby-sky1/2777695

Looking at the stack trace it looks like a type confusion possibly
induced by heap corruption. I'm hoping to verify this theory.
2020-08-01 23:05:19 -04:00
Nobuyoshi Nakada d637208abd Fixed a typo 2020-07-19 23:13:21 +09:00
Nobuyoshi Nakada 1351374bd1 Split visibility cases 2020-06-30 19:12:05 +09:00
Jeremy Evans b6d6b89615 Allow refining a frozen class
Doing so modifies the class's method table, but not in a way that should
be detectable from Ruby, so it may be safe to avoid checking if the
class is frozen.

Fixes [Bug #11669]
2020-06-18 08:22:40 -07:00
Nobuyoshi Nakada 184f78314e Properly resolve refinements in defined? on private call [Bug #16932] 2020-06-04 02:12:57 +09:00
Nobuyoshi Nakada 8340c773e5 Properly resolve refinements in defined? on method call [Bug #16932] 2020-06-04 02:12:57 +09:00
Jeremy Evans 98286e9850 Ensure origins for all included, prepended, and refined modules
This fixes various issues when a module is included in or prepended
to a module or class, and then refined, or refined and then included
or prepended to a module or class.

Implement by renaming ensure_origin to rb_ensure_origin, making it
non-static, and calling it when refining a module.

Fix Module#initialize_copy to handle origins correctly.  Previously,
Module#initialize_copy did not handle origins correctly.  For example,
this code:

```ruby
module B; end
class A
  def b; 2 end
  prepend B
end
a = A.dup.new
class A
  def b; 1 end
end
p a.b
```

Printed 1 instead of 2.  This is because the super chain for
a.singleton_class was:

```
a.singleton_class
A.dup
B(iclass)
B(iclass origin)
A(origin) # not A.dup(origin)
```

The B iclasses would not be modified, so the includer entry would be
still be set to A and not A.dup.

This modifies things so that if the class/module has an origin,
all iclasses between the class/module and the origin are duplicated
and have the correct includer entry set, and the correct origin
is created.

This requires other changes to make sure all tests still pass:

* rb_undef_methods_from doesn't automatically handle classes with
  origins, so pass it the origin for Comparable when undefing
  methods in Complex. This fixed a failure in the Complex tests.

* When adding a method, the method cache was not cleared
  correctly if klass has an origin.  Clear the method cache for
  the klass before switching to the origin of klass.  This fixed
  failures in the autoload tests related to overridding require,
  without breaking the optimization tests.  Also clear the method
  cache for both the module and origin when removing a method.

* Module#include? is fixed to skip origin iclasses.

* Refinements are fixed to use the origin class of the module that
  has an origin.

* RCLASS_REFINED_BY_ANY is removed as it was only used in a single
  place and is no longer needed.

* Marshal#dump is fixed to skip iclass origins.

* rb_method_entry_make is fixed to handled overridden optimized
  methods for modules that have origins.

Fixes [Bug #16852]
2020-06-03 09:50:37 -07:00
Nobuyoshi Nakada 74c8aaef7d Just call search_method_protect [Bug #16669] 2020-04-23 10:24:49 +09:00
Koichi Sasada 8119bcbfc0 rb_method_entry() returns valid me.
search_method() can return invalid method, but vm_defined() checks
it as valid method entry. This is why defined?(foo) if foo is undef'ed.
To solve this problem, check invalidation and return NULL.
[Bug #16669]
https://twitter.com/kamipo/status/1252881930103558144

Tests will be merged by nobu soon.
2020-04-23 02:21:38 +09:00
Nobuyoshi Nakada e474c189da Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
Jeremy Evans adecd43197 Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188
Correctly show defined class for aliases of aliases
2020-03-22 09:30:20 -07:00
Koichi Sasada 2943ff9d44 fix bug on method cache invalidation.
To invalidate cached method entry, existing method entry (ment)
is marked as invalidated and replace with copied ment. However,
complemented method entry (method entries in Module) should not
be set to Module's m_tbl.
[Bug #16669]
2020-03-11 02:50:44 +09:00
卜部昌平 aa44b29030 suppress uninitialized variable warnings
Starting GCC 7, warnings about uninitialized variables are issued around
them.  Such warnings could be false positives (all versions of clang do
not warn), but adding initializers there could never be bad things.
2020-03-04 12:30:42 +09:00
卜部昌平 f12b9a3338 %p is for void *
See also
35eb12c063
6f5eb28507
687308cf0d
b6a2d63eb3
2020-03-04 12:30:42 +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