aboutsummaryrefslogtreecommitdiffstats
path: root/vm_method.c
Commit message (Collapse)AuthorAgeFilesLines
* Fixed premature returnNobuyoshi Nakada2021-01-191-1/+1
| | | | | After setting ruby2_keywords for bmethod, the rest of arguments had been ignored. [Bug #17558]
* Fix typo: invaldate -> invalidateAlan Wu2021-01-181-3/+3
|
* Don't try to clear cache on garbage objectsAaron Patterson2021-01-151-0/+1
| | | | | | | | | | | | | 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>
* delete negative cache from the table correctlyKoichi Sasada2021-01-141-9/+19
| | | | | | negative cache entry should be removed from vm->negative_cme_table even if the redefined class has no subclasses.
* Revert "[Bug #11213] let defined?(super) call respond_to_missing?"Nobuyoshi Nakada2021-01-131-5/+7
| | | | | | This reverts commit fac2498e0299f13dffe4f09a7dd7657fb49bf643 for now, due to [Bug #17509], the breakage in the case `super` is called in `respond_to?`.
* [DOC] Fix typos in vm_method.cMarcus Stollsteimer2020-12-261-7/+7
|
* Module#public_class_method also accepts a symbol array as an argumentYusuke Endoh2020-12-241-0/+11
| | | | | I'm unsure if this is intentional, but add a document anyway. [Feature #17314]
* separate rb_ractor_pub from rb_ractor_tKoichi Sasada2020-12-221-1/+1
| | | | | | | | | 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.
* Feature 17314: allow to pass array to public, protected and private methodsRadosław Bułat2020-12-191-6/+25
|
* Feature 17314: alias_method returns symbolRadosław Bułat2020-12-191-4/+5
|
* fix method cache debug toolKoichi Sasada2020-12-191-3/+3
|
* Use category: :deprecated in warnings that are related to deprecationJeremy Evans2020-12-181-1/+2
| | | | | | | | | | | | | | | | | 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.
* Revert "Better cooperation between public/protected/private with attr* and ↵Yusuke Endoh2020-12-181-30/+10
| | | | | | alias_method" This reverts commit 81739ad4fdfcc86a769056fec352f27c686fba1b.
* Revert "Added missing tests for public, private, protected and alias_method"Yusuke Endoh2020-12-181-2/+1
| | | | This reverts commit e042e8460bb9a63c05f938d51e8c7c5345a6f3a4.
* Added missing tests for public, private, protected and alias_methodNobuyoshi Nakada2020-12-181-1/+2
|
* Better cooperation between public/protected/private with attr* and alias_methodRadosław Bułat2020-12-171-10/+30
|
* add ccs_not_found debug counterKoichi Sasada2020-12-141-0/+2
| | | | ccs_not_found to count not found in ccs table.
* use method cache on Object#respond_to?Koichi Sasada2020-12-141-12/+34
| | | | | rb_method_boundp (method_boundp) searches method_entry, but this search did not use pCMC, so change to use it.
* add cc_invalidate_negative debug counterKoichi Sasada2020-12-141-0/+2
| | | | counts for invalidating negative cache.
* Introduce negative method cacheKoichi Sasada2020-12-141-6/+36
| | | | pCMC doesn't have negative method cache so this patch implements it.
* rb_ext_ractor_safe() to declare ractor-safe extKoichi Sasada2020-12-011-21/+47
| | | | | | | | | | | 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]
* [Bug #11213] let defined?(super) call respond_to_missing?Nobuyoshi Nakada2020-11-201-7/+5
|
* Revert assert for debugging on CIAlan Wu2020-10-261-1/+0
| | | | | This reverts commit ac69849e49982ea83036c04c5d5f7245e3956a49. The bug seems to have been fixed.
* Don't redefine #rb_intern over and over againStefan Stüben2020-10-211-3/+0
|
* Fix ASAN support when invalidating CCsAaron Patterson2020-09-281-0/+5
| | | | | Again, this code is walking the heap. Empty slots can be poisoned, so we need to unpoison before checking the type
* prohibi method call by defined_method in other racotrsKoichi Sasada2020-09-251-0/+2
| | | | We can not call a non-isolated Proc in multiple ractors.
* sync callable_method_entry()Koichi Sasada2020-09-101-10/+20
| | | | | callable_method_entry() read/write method table structures so that this function should be synchronized between Ractors.
* Remove write barrier exemption for T_ICLASSAlan Wu2020-08-171-7/+18
| | | | | | | | | | | | | | | | | | | 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]
* Enable an assert on all configs for debuggingAlan Wu2020-08-011-0/+1
| | | | | | | | | | 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.
* Fixed a typoNobuyoshi Nakada2020-07-191-3/+3
|
* Split visibility casesNobuyoshi Nakada2020-06-301-4/+9
|
* Allow refining a frozen classJeremy Evans2020-06-181-1/+3
| | | | | | | | 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]
* Properly resolve refinements in defined? on private call [Bug #16932]Nobuyoshi Nakada2020-06-041-0/+6
|
* Properly resolve refinements in defined? on method call [Bug #16932]Nobuyoshi Nakada2020-06-041-1/+1
|
* Ensure origins for all included, prepended, and refined modulesJeremy Evans2020-06-031-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* Just call search_method_protect [Bug #16669]Nobuyoshi Nakada2020-04-231-7/+1
|
* rb_method_entry() returns valid me.Koichi Sasada2020-04-231-1/+7
| | | | | | | | | | 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.
* Suppress -Wswitch warningsNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188Jeremy Evans2020-03-221-1/+1
| | | Correctly show defined class for aliases of aliases
* fix bug on method cache invalidation.Koichi Sasada2020-03-111-8/+13
| | | | | | | | 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]
* suppress uninitialized variable warnings卜部昌平2020-03-041-1/+1
| | | | | | 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.
* %p is for void *卜部昌平2020-03-041-3/+3
| | | | | | | | See also 35eb12c06397e770392a41343cbffc4b204e15c9 6f5eb285077d9abf8f97056531996c58674b570c 687308cf0dab0af675e40da2b6ab8ccd5f77c072 b6a2d63eb3dbc31e110e8cb95e054dd71d49a611
* Introduce disposable call-cache.Koichi Sasada2020-02-221-238/+392
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* VALUE size packed callinfo (ci).Koichi Sasada2020-02-221-11/+0
| | | | | | | | | | | | | | | | | | | | 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.
* suppress clang warnings卜部昌平2020-02-201-1/+1
| | | | | | Starting clang 11, casts between pointer and (narrower-than-pointer) int are now warned. However all such thing in our repository are guaranteed safe. Let's suppress the warnings.
* VALUE is narrower than rb_serial_t卜部昌平2020-01-211-1/+1
| | | | | | VALUE and rb_serial_t do not agree with their width. We have to be consistent. Assigning an rb_serial_t value to a VALUE variable is practically a problem on a ILP32 environment.
* Check Module#ruby2_keywords arityNobuyoshi Nakada2020-01-021-0/+1
| | | | | It is considered a mistake, because calling this method with no arguments has no effect.
* per-method serial number卜部昌平2019-12-181-0/+2
| | | | | | | | | | | | | | | | | Methods and their definitions can be allocated/deallocated on-the-fly. One pathological situation is when a method is deallocated then another one is allocated immediately after that. Address of those old/new method entries/definitions can be the same then, depending on underlying malloc/free implementation. So pointer comparison is insufficient. We have to check the contents. To do so we introduce def->method_serial, which is an integer unique to that specific method definition. PS: Note that method_serial being uintptr_t rather than rb_serial_t is intentional. This is because rb_serial_t can be bigger than a pointer on a 32bit system (rb_serial_t is at least 64bit). In order to preserve old packing of struct rb_call_cache, rb_serial_t is inappropriate.
* Skip optimized method check for most method IDsJohn Hawthorn2019-12-171-2/+10
| | | | | | | | | | | Previously every time a method was defined on a module, we would recursively walk all subclasses to see if the module was included in a class which the VM optimizes for (such as Integer#+). For most method definitions we can tell immediately that this won't be the case based on the method's name. To do this we just keep a hash with method IDs of optimized methods and if our new method isn't in that list we don't need to check subclasses at all.
* Replace debug test with assertionJohn Hawthorn2019-12-171-4/+1
| | | | | It's a Ruby bug if this ever happens check it as an assertion instead of paying the cost of the check every time.