aboutsummaryrefslogtreecommitdiffstats
path: root/class.c
Commit message (Collapse)AuthorAgeFilesLines
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-3/+3
| | | | | | rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-265/+265
| | | | [Misc #18891]
* Add Module#undefined_instance_methodsJeremy Evans2022-06-061-0/+24
| | | | | Implements [Feature #12655] Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
* Remove unused RMODULE_INCLUDED_INTO_REFINEMENT flagJemma Issroff2022-05-261-1/+0
|
* Remove unnecessary module flag, add module assertions to other module flagsJemma Issroff2022-05-231-2/+3
|
* Fix potential GC issue while iterating over weak refsAlan Wu2022-05-051-8/+9
| | | | | | | | | | | | While walking over the list of subclasses for `include` and friends, we check whether the subclass is a garbage object. After the check, we allocate objects which might trigger GC and make the subclass garbage, even though before the allocation the subclass was not garbage. This is a sort of time-of-check-time-of-use issue. Fix this by saving the weak reference to a local variable, upgrading it to a strong reference while we do the allocation. It makes the code look slightly nicer even if it doesn't fix any runtime issues.
* Fix class ancestry checks for duped classesJohn Hawthorn2022-04-161-0/+2
| | | | | | | | | | | | | | | Previously in some when classes were duped (specifically those with a prepended module), they would not correctly have their "superclasses" array or depth filled in. This could cause ancestry checks (like is_a? and Module comparisons) to return incorrect results. This happened because rb_mod_init_copy builds origin classes in an order that doesn't have the super linked list fully connected until it's finished. This commit fixes the previous issue by calling rb_class_update_superclasses before returning the cloned class. This is similar to what's already done in make_metaclass.
* Finer-grained constant cache invalidation (take 2)Kevin Newton2022-04-011-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | This commit reintroduces finer-grained constant cache invalidation. After 8008fb7 got merged, it was causing issues on token-threaded builds (such as on Windows). The issue was that when you're iterating through instruction sequences and using the translator functions to get back the instruction structs, you're either using `rb_vm_insn_null_translator` or `rb_vm_insn_addr2insn2` depending if it's a direct-threading build. `rb_vm_insn_addr2insn2` does some normalization to always return to you the non-trace version of whatever instruction you're looking at. `rb_vm_insn_null_translator` does not do that normalization. This means that when you're looping through the instructions if you're trying to do an opcode comparison, it can change depending on the type of threading that you're using. This can be very confusing. So, this commit creates a new translator function `rb_vm_insn_normalizing_translator` to always return the non-trace version so that opcode comparisons don't have to worry about different configurations. [Feature #18589]
* Revert "Finer-grained inline constant cache invalidation"Nobuyoshi Nakada2022-03-251-12/+4
| | | | | | | | | | | | This reverts commits for [Feature #18589]: * 8008fb7352abc6fba433b99bf20763cf0d4adb38 "Update formatting per feedback" * 8f6eaca2e19828e92ecdb28b0fe693d606a03f96 "Delete ID from constant cache table if it becomes empty on ISEQ free" * 629908586b4bead1103267652f8b96b1083573a8 "Finer-grained inline constant cache invalidation" MSWin builds on AppVeyor have been crashing since the merger.
* Update formatting per feedbackKevin Newton2022-03-241-1/+1
| | | Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
* Finer-grained inline constant cache invalidationKevin Newton2022-03-241-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current behavior - caches depend on a global counter. All constant mutations cause caches to be invalidated. ```ruby class A B = 1 end def foo A::B # inline cache depends on global counter end foo # populate inline cache foo # hit inline cache C = 1 # global counter increments, all caches are invalidated foo # misses inline cache due to `C = 1` ``` Proposed behavior - caches depend on name components. Only constant mutations with corresponding names will invalidate the cache. ```ruby class A B = 1 end def foo A::B # inline cache depends constants named "A" and "B" end foo # populate inline cache foo # hit inline cache C = 1 # caches that depend on the name "C" are invalidated foo # hits inline cache because IC only depends on "A" and "B" ``` Examples of breaking the new cache: ```ruby module C # Breaks `foo` cache because "A" constant is set and the cache in foo depends # on "A" and "B" class A; end end B = 1 ``` We expect the new cache scheme to be invalidated less often because names aren't frequently reused. With the cache being invalidated less, we can rely on its stability more to keep our constant references fast and reduce the need to throw away generated code in YJIT.
* [Bug #18627] Fix crash when including modulePeter Zhu2022-03-181-18/+30
| | | | | | | During lazy sweeping, the iclass could be a dead object that has not yet been swept. However, the chain of superclasses of the iclass could already have been swept (and become a new object), which would cause a crash when trying to read the object.
* Assume that klass of dummy head is NULLPeter Zhu2022-03-161-1/+2
| | | | klass of the dummy head of the subclass entries should always be NULL.
* Always skip dummy head of subclass in rb_prepend_modulePeter Zhu2022-03-161-1/+1
| | | | | The first node of the subclass linked list of always a dummy head, so it should be skipped.
* Dedup superclass array in leaf sibling classesJohn Hawthorn2022-03-031-19/+14
| | | | | | | | | | | | | | | | Previously, we would build a new `superclasses` array for each class, even though for all immediate subclasses of a class, the array is identical. This avoids duplicating the arrays on leaf classes (those without subclasses) by calculating and storing a "superclasses including self" array on a class when it's first inherited and sharing that among all superclasses. An additional trick used is that the "superclass array including self" is valid as "self"'s superclass array. It just has it's own class at the end. We can use this to avoid an extra pointer of storage and can use one bit of a flag to track that we've "upgraded" the array.
* Constant time class to class ancestor lookupJohn Hawthorn2022-02-231-0/+60
| | | | | | | | | | | | | | | | | | | | | | | | | Previously when checking ancestors, we would walk all the way up the ancestry chain checking each parent for a matching class or module. I believe this was especially unfriendly to CPU cache since for each step we need to check two cache lines (the class and class ext). This check is used quite often in: * case statements * rescue statements * Calling protected methods * Class#is_a? * Module#=== * Module#<=> I believe it's most common to check a class against a parent class, to this commit aims to improve that (unfortunately does not help checking for an included Module). This is done by storing on each class the number and an array of all parent classes, in order (BasicObject is at index 0). Using this we can check whether a class is a subclass of another in constant time since we know the location to expect it in the hierarchy.
* Replace and Using METACLASS_OF macroS-H-GAMELINKS2022-02-191-15/+15
|
* Fix the placeholder subclass entry skipping [Bug #18489]Nobuyoshi Nakada2022-01-171-2/+1
|
* Separately allocate class_serial on 32-bit systemsPeter Zhu2022-01-141-0/+3
| | | | | | | | On 32-bit systems, VWA causes class_serial to not be aligned (it only guarantees 4 byte alignment but class_serial is 8 bytes and requires 8 byte alignment). This commit uses a hack to allocate class_serial through malloc. Once VWA allocates with 8 byte alignment in the future, we will revert this commit.
* Remove unneeded lineJeremy Evans2022-01-061-1/+0
|
* Allow include before calling Module#initializeJeremy Evans2022-01-061-0/+1
| | | | | | | | | | | | | | | | This is to allow Module subclasses that include modules before calling super in the subclass's initialize. Remove rb_module_check_initializable from Module#initialize. Module#initialize only calls module_exec if a block is passed, it doesn't have other issues that would cause problems if called multiple times or with an already initialized module. Move initialization of super to Module#allocate, though I'm not sure it is required there. However, it's needed to be removed from Module#initialize for this to work. Fixes [Bug #18292]
* Remove useless code [Bug #18185]Nobuyoshi Nakada2022-01-061-1/+0
| | | | | RMODULE_SUPER is initialized to 0, as the uninitialized module flag is used since b929af430c39df6597d2f3f53b82c38b1d76217b.
* Add docs for Refinement classzverok2021-12-241-0/+57
|
* Split too long lineNobuyoshi Nakada2021-12-221-1/+4
| | | | | I don't have a display enough for 170 columns, and it is hard to use small fonts for my eyes. :(
* Remove Class#descendantsJeremy Evans2021-12-201-25/+0
|
* Speed up Ractors for Variable Width AllocationPeter Zhu2021-11-231-1/+3
| | | | | | | | | | | | | | | | This commit adds a Ractor cache for every size pool. Previously, all VWA allocated objects used the slowpath and locked the VM. On a micro-benchmark that benchmarks String allocation: VWA turned off: 29.196591 0.889709 30.086300 ( 9.434059) VWA before this commit: 29.279486 41.477869 70.757355 ( 12.527379) VWA after this commit: 16.782903 0.557117 17.340020 ( 4.255603)
* Add Class#subclassesJean Boussier2021-11-231-18/+55
| | | | | | | Implements [Feature #18273] Returns an array containing the receiver's direct subclasses without singleton classes.
* Make RCLASS_EXT(c)->subclasses a doubly linked listMatt Valentine-House2021-11-221-38/+76
| | | | | | | | Updating RCLASS_PARENT_SUBCLASSES and RCLASS_MODULE_SUBCLASSES while compacting can trigger the read barrier. This commit makes RCLASS_SUBCLASSES a doubly linked list with a dedicated head object so that we can add and remove entries from the list without having to touch an object in the Ruby heap
* Remove RCLASS(obj)->ptr when RVARGC is enabledMatt Valentine-House2021-11-111-3/+1
| | | | | | | With RVARGC we always store the rb_classext_t in the same slot as the RClass struct that refers to it. So we don't need to store the pointer or access through the pointer anymore and can switch the RCLASS_EXT macro to use an offset
* gc.h: move rb_objspace_garbage_object_p to internal/gc.hYusuke Endoh2021-11-101-1/+0
| | | | ... to allow class.c to use the function
* class.c: descendants must not cause GC until the result array is createdYusuke Endoh2021-11-101-9/+13
| | | | | | | | | | | | | Follow up of 428227472fc6563046d8138aab17f07bef6af753. The previous fix uses `rb_ary_new_from_values` to create the result array, but it may trigger the GC. This second try is to create the result array by `rb_ary_new_capa` before the second iteration, and assume that `rb_ary_push` does not trigger GC. This assumption is very fragile, so should be improved in future. [Bug #18282] [Feature #14394]
* Remove a redundant conditionYusuke Endoh2021-11-091-2/+2
|
* class.c (Class#descendants): Ingore subclasses created after estimationYusuke Endoh2021-11-091-2/+4
| | | | It is theoretically possible if a finalizer creates a subclass.
* class.c: Use ALLOC_N instead of ALLOCA_NYusuke Endoh2021-11-091-2/+6
|
* class.c: calculate the length of Class.descendants in advanceYusuke Endoh2021-11-091-6/+29
| | | | | | | | | | GC must not be triggered during callback of rb_class_foreach_subclass. To prevent GC, we can not use rb_ary_push. Instead, this changeset calls rb_class_foreach_subclass twice: first counts the subclasses, then allocates a buffer (which may cause GC and reduce subclasses, but not increase), and finally stores the subclasses to the buffer. [Bug #18282] [Feature #14394]
* Add Class#descendantsJeremy Evans2021-10-261-0/+35
| | | | | | | | Doesn't include receiver or singleton classes. Implements [Feature #14394] Co-authored-by: fatkodima <fatkodima123@gmail.com> Co-authored-by: Benoit Daloze <eregontp@gmail.com>
* Make the metaclass of Refinement explicitlyShugo Maeda2021-10-261-0/+2
| | | | | Otherwise, singleton methods of Module are not inherited unless Refinement.singleton_class is called.
* [Feature #18239] Refactor RVARGC alloc functionsPeter Zhu2021-10-251-4/+4
| | | | | The allocation functions no longer assume that one RVALUE needs to be allocated.
* Deprecate include/prepend in refinements and add Refinement#import_methods ↵Shugo Maeda2021-10-211-3/+17
| | | | | | | | | | instead Refinement#import_methods imports methods from modules. Unlike Module#include, it copies methods and adds them into the refinement, so the refinement is activated in the imported methods. [Bug #17429] [ruby-core:101639]
* Use the flag for uninitialized module [Bug #18185]Nobuyoshi Nakada2021-09-241-6/+9
| | | | Make `Module#ancestors` not to include `BasicObject`.
* Consider modified modules initialized [Bug #18185]Nobuyoshi Nakada2021-09-241-4/+10
|
* Allow to include uninitialized modules [Bug #18177]Nobuyoshi Nakada2021-09-201-1/+2
| | | | The module that is about to be included is considered initialized.
* Fix a typo [Bug #17048]Nobuyoshi Nakada2021-09-191-2/+2
|
* Already initialized modules cannot be replaced [Bug #17048]Nobuyoshi Nakada2021-09-171-1/+42
|
* include/ruby/internal/intern/class.h: add doxygen卜部昌平2021-09-101-67/+0
| | | | Must not be a bad idea to improve documents. [ci skip]
* include/ruby/internal/method.h: add doxygen卜部昌平2021-09-101-77/+1
| | | | | | | | Must not be a bad idea to improve documents. [ci skip] In fact many functions declared in the header file are already documented more or less. They were just copy & pasted, with applying some style updates.
* include/ruby/internal/module.h: add doxygen卜部昌平2021-09-101-51/+1
| | | | | | | | Must not be a bad idea to improve documents. [ci skip] In fact many functions declared in the header file are already documented more or less. They were just copy & pasted, with applying some style updates.
* include/ruby/internal/newobj.h: add doxygen卜部昌平2021-09-101-4/+0
| | | | Must not be a bad idea to improve documents. [ci skip]
* Assert not to be UNDEF visibilityNobuyoshi Nakada2021-09-011-0/+1
| | | | | Any defined methods, bound to any classes/modules and not being UNDEFINED_METHOD_ENTRY_P, should not be METHOD_VISI_UNDEF.
* [Feature #18045] Implement size classes for GCPeter Zhu2021-08-251-2/+1
| | | | | | | | | This commits implements size classes in the GC for the Variable Width Allocation feature. Unless `USE_RVARGC` compile flag is set, only a single size class is created, maintaining current behaviour. See the redmine ticket for more details. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>