summaryrefslogtreecommitdiff
path: root/vm_method.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix memory leak at the same named alias [Bug #18516]Nobuyoshi Nakada2022-01-271-1/+8
| | | | | | | | 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.
* Negative RBOOL usageNobuyoshi Nakada2022-01-011-1/+1
|
* undef `rb_vm_lookup_overloaded_cme()`Koichi Sasada2021-12-231-1/+2
| | | | | | | | | | | | | | Some callable method entries (cme) can be a key of `overloaded_cme_table` and the keys should be pinned because the table is numtable (VALUE is a key). Before the patch GC checks the cme is in `overloaded_cme_table` by looking up the table, but it needs VM locking. It works well in normal GC marking because it is protected by the VM lock, but it doesn't work on `rb_objspace_reachable_objects_from` because it doesn't use VM lock. Now, the number of target cmes are small enough, I decide to pin down all possible cmes instead of using looking up the table.
* make `overloaded_cme_table` truly weak key mapKoichi Sasada2021-12-211-23/+15
| | | | | | | | | | | | | `overloaded_cme_table` keeps cme -> monly_cme pairs to manage corresponding `monly_cme` for `cme`. The lifetime of the `monly_cme` should be longer than `monly_cme`, but the previous patch losts the reference to the living `monly_cme`. Now `overloaded_cme_table` values are always root (keys are only weak reference), it means `monly_cme` does not freed until corresponding `cme` is invalidated. To make managing easy, move `overloaded_cme_table` to `rb_vm_t`.
* `mandatory_only_cme` should not be in `def`Koichi Sasada2021-12-211-14/+119
| | | | | | | | | | | | | | | | | | | | | | | | `def` (`rb_method_definition_t`) is shared by multiple callable method entries (cme, `rb_callable_method_entry_t`). There are two issues: * old -> young reference: `cme1->def->mandatory_only_cme = monly_cme` if `cme1` is young and `monly_cme` is young, there is no problem. Howevr, another old `cme2` can refer `def`, in this case, old `cme2` points young `monly_cme` and it violates gengc assumption. * cme can have different `defined_class` but `monly_cme` only has one `defined_class`. It does not make sense and `monly_cme` should be created for a cme (not `def`). To solve these issues, this patch allocates `monly_cme` per `cme`. `cme` does not have another room to store a pointer to the `monly_cme`, so this patch introduces `overloaded_cme_table`, which is weak key map `[cme] -> [monly_cme]`. `def::body::iseqptr::monly_cme` is deleted. The first issue is reported by Alan Wu.
* optimize `Struct` getter/setterKoichi Sasada2021-11-191-1/+4
| | | | | Introduce new optimized method type `OPTIMIZED_METHOD_TYPE_STRUCT_AREF/ASET` with index information.
* `rb_method_optimized_t` for further extensionKoichi Sasada2021-11-191-3/+12
| | | | | Now `rb_method_optimized_t optimized` field is added to represent optimized method type.
* Update documentation for Module#{private,public,protected,module_function}Jeremy Evans2021-11-181-14/+27
| | | | Also, update NEWS for this change and the Kernel#load change.
* Make Module#{public,private,protected,module_function} return argumentsJeremy Evans2021-11-181-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, each of these methods returned self, but it is more useful to return arguments, to allow for simpler method decorators, such as: ```ruby cached private def foo; some_long_calculation; end ``` Where cached sets up caching for the method. For each of these methods, the following behavior is used: 1) No arguments returns nil 2) Single argument is returned 3) Multiple arguments are returned as an array The single argument case is really the case we are trying to optimize for, for the same reason that def was changed to return a symbol for the method. Idea and initial patch from Herwin Quarantainenet. Implements [Feature #12495]
* Fix crash when clearing method cache for builtin methodPeter Zhu2021-11-171-1/+1
| | | | | | | | Builtin methods do not always have their mandatory_only_cme created (it is only created when called with only mandatory parameters), so it could be null. If we try to clear the cme, it will crash because it is null. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* `Primitive.mandatory_only?` for fast pathKoichi Sasada2021-11-151-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Compare with the C methods, A built-in methods written in Ruby is slower if only mandatory parameters are given because it needs to check the argumens and fill default values for optional and keyword parameters (C methods can check the number of parameters with `argc`, so there are no overhead). Passing mandatory arguments are common (optional arguments are exceptional, in many cases) so it is important to provide the fast path for such common cases. `Primitive.mandatory_only?` is a special builtin function used with `if` expression like that: ```ruby def self.at(time, subsec = false, unit = :microsecond, in: nil) if Primitive.mandatory_only? Primitive.time_s_at1(time) else Primitive.time_s_at(time, subsec, unit, Primitive.arg!(:in)) end end ``` and it makes two ISeq, ``` def self.at(time, subsec = false, unit = :microsecond, in: nil) Primitive.time_s_at(time, subsec, unit, Primitive.arg!(:in)) end def self.at(time) Primitive.time_s_at1(time) end ``` and (2) is pointed by (1). Note that `Primitive.mandatory_only?` should be used only in a condition of an `if` statement and the `if` statement should be equal to the methdo body (you can not put any expression before and after the `if` statement). A method entry with `mandatory_only?` (`Time.at` on the above case) is marked as `iseq_overload`. When the method will be dispatch only with mandatory arguments (`Time.at(0)` for example), make another method entry with ISeq (2) as mandatory only method entry and it will be cached in an inline method cache. The idea is similar discussed in https://bugs.ruby-lang.org/issues/16254 but it only checks mandatory parameters or more, because many cases only mandatory parameters are given. If we find other cases (optional or keyword parameters are used frequently and it hurts performance), we can extend the feature.
* Partial revert of ceebc7fc98dAaron Patterson2021-10-201-12/+0
| | | | | | | I'm looking through the places where YJIT needs notifications. It looks like these changes to gc.c and vm_callinfo.h have become unnecessary since 84ab77ba592. This commit just makes the diff against upstream smaller, but otherwise shouldn't change any behavior.
* Get rid of dependency on rb_call_cacheAlan Wu2021-10-201-2/+6
|
* Yet Another Ruby JIT!Jose Narvaez2021-10-201-4/+4
| | | | Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
* add a callback for when method cache changesAaron Patterson2021-10-201-0/+1
|
* Refactor uJIT code into more files for readabilityMaxime Chevalier-Boisvert2021-10-201-1/+1
|
* MicroJIT: generate less code for CFUNCsAlan Wu2021-10-201-0/+15
| | | | | | | | Added UJIT_CHECK_MODE. Set to 1 to double check method dispatch in generated code. It's surprising to me that we need to watch both cc and cme. There might be opportunities to simplify there.
* Fix typo in static function nameJeremy Evans2021-10-011-3/+3
|
* Get rid of type-punning pointer casts [Bug #18062]Nobuyoshi Nakada2021-08-111-15/+25
|
* Using RBOOL macroS.H2021-08-021-5/+3
|
* Update documentation for ruby2_keywordsJeremy Evans2021-07-291-6/+9
| | | | | | | | | | Point out that the method should be used for backwards compatibility with code prior to Ruby 3.0 instead of Ruby 2.7. It's still needed in Ruby 2.7. It isn't needed in Ruby 3.0, as the methods using it could switch to delegating both positional and keyword arguments. Add a link to the www.ruby-lang.org web page that goes into detail describing when and how ruby2_keywords should be used.
* Adjust styles [ci skip]Nobuyoshi Nakada2021-06-171-2/+3
| | | | | | | | | * --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
* Enable VM_ASSERT in --jit CIs (#4543)Takashi Kokubun2021-06-011-1/+1
|
* Avoid setting the visibility of refinement method entriesAlan Wu2021-05-211-5/+10
| | | | | | | | 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]
* Method cache: fix refinement entry handlingAlan Wu2021-05-111-2/+11
| | | | | | | | | | | | | | | | | | | | 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]
* Protoized old pre-ANSI K&R style declarations and definitionsNobuyoshi Nakada2021-05-071-1/+1
|
* Fix setting method visibility for a refinement without an origin classJeremy Evans2021-04-231-1/+2
| | | | | | | | | | 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]
* Skip refined method when exporting methods with changed visibilityJeremy Evans2021-03-161-3/+11
| | | | | | | | 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]
* invalidate negative cache any time.Koichi Sasada2021-02-191-7/+5
| | | | | | | negative cache on a class which does not have subclasses was not invalidated, but it should be invalidated because other classes can cache this negative cache. [Bug #17553]
* Fix documentation for Module#ruby2_keywordsJeremy Evans2021-02-091-1/+1
| | | | | | It returns nil, not self. Fixes [Bug #17560]
* Make alias for aliased original methodNobuyoshi Nakada2021-02-031-1/+7
| | | | Chaining aliased methods increases searching cost linearly.
* Adjusted indent [ci skip]Nobuyoshi Nakada2021-02-031-2/+2
|
* Add RCLASS_SUBCLASSES MacroMatt Valentine-House2021-02-011-1/+1
|
* Add RCLASS_ALLOCATOR MacroMatt Valentine-House2021-02-011-2/+2
|
* global call-cache cache table for rb_funcall*Koichi Sasada2021-01-291-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Warn the defined location as deprecation as well as the main messageNobuyoshi Nakada2021-01-231-1/+2
| | | | [Bug #17575]
* 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.