summaryrefslogtreecommitdiff
path: root/internal/gc.h
Commit message (Collapse)AuthorAgeFilesLines
* Make classes embedded on 32 bitPeter Zhu2023-04-161-3/+0
| | | | | Classes are now exactly 80 bytes when embedded, which perfectly fits the 3rd size pool on 32 bit systems.
* Enable 5 size pools on 32 bit systemsPeter Zhu2023-04-111-6/+3
| | | | This commit will allow 32 bit systems to take advantage of VWA.
* [Feature #19474] Refactor NEWOBJ macrosMatt Valentine-House2023-04-061-16/+13
| | | | NEWOBJ_OF is now our canonical newobj macro. It takes an optional ec
* Remove dependancy of vm_core.h on shape.hMatt Valentine-House2023-04-061-2/+0
| | | | so that now shape can happily include gc.h
* [Feature #19579] Remove !USE_RVARGC code (#7655)Peter Zhu2023-04-041-1/+1
| | | | | | | | | | | Remove !USE_RVARGC code [Feature #19579] The Variable Width Allocation feature was turned on by default in Ruby 3.2. Since then, we haven't received bug reports or backports to the non-Variable Width Allocation code paths, so we assume that nobody is using it. We also don't plan on maintaining the non-Variable Width Allocation code, so we are going to remove it.
* Revert "Fix transient heap mode"Aaron Patterson2023-04-041-1/+0
| | | | | | | | This reverts commit 87253d047ce35e7836b6f97edbb4f819879a3b25. Revert "Implement `Process.warmup`" This reverts commit ba6ccd871442f55080bffd53e33678c0726787d2.
* Implement `Process.warmup`Jean Boussier2023-04-041-0/+1
| | | | | | | | | | | | [Feature #18885] For now, the optimizations performed are: - Run a major GC - Compact the heap - Promote all surviving objects to oldgen Other optimizations may follow.
* Allow user defined SIZE_POOL_COUNTPeter Zhu2023-03-271-4/+6
| | | | | We shouldn't overwrite the value of SIZE_POOL_COUNT if the user has specified one.
* Move RB_GC_SAVE_MACHINE_CONTEXT to vm_core.hMatt Valentine-House2023-03-151-7/+0
|
* Move WeakMap and WeakKeyMap code to weakmap.cPeter Zhu2023-03-101-0/+3
| | | | | | These classes don't belong in gc.c as they're not actually part of the GC. This commit refactors the code by moving all the code into a weakmap.c file.
* Remove unused forward decl of rb_thread_structMatt Valentine-House2023-03-091-2/+0
|
* Stop exporting symbols for MJITTakashi Kokubun2023-03-061-2/+0
|
* Merge gc.h and internal/gc.hMatt Valentine-House2023-02-091-0/+139
| | | | [Feature #19425]
* Make Time objects WB protectedPeter Zhu2023-02-071-0/+5
| | | | Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
* Fix typo in gc.h [ci skip]Peter Zhu2023-02-071-1/+1
|
* In `UNALIGNED_MEMBER_PTR` cast through `void` pointerNobuyoshi Nakada2023-01-211-1/+11
| | | | | Suppress warnings shown even with `-Waddress-of-packed-member` disabled in gcc 11.
* Add rb_gc_mark_and_move and implement on iseqPeter Zhu2023-01-191-0/+8
| | | | | | | | | | This commit adds rb_gc_mark_and_move which takes a pointer to an object and marks it during marking phase and updates references during compaction. This allows for marking and reference updating to be combined into a single function, which reduces code duplication and prevents bugs if marking and reference updating goes out of sync. This commit also implements rb_gc_mark_and_move on iseq as an example.
* Don't redefine RB_OBJ_WRITEPeter Zhu2023-01-181-4/+0
| | | | | RB_OBJ_WRITE already exists in rgengc.h, so we shouldn't redefine it in gc.h.
* Move definition of SIZE_POOL_COUNT back to gc.hPeter Zhu2022-12-151-1/+7
| | | | | | | | SIZE_POOL_COUNT is a GC macro, it should belong in gc.h and not shape.h. SIZE_POOL_COUNT doesn't depend on shape.h so we can have shape.h depend on gc.h. Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
* Transition complex objects to "too complex" shapeJemma Issroff2022-12-151-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an object becomes "too complex" (in other words it has too many variations in the shape tree), we transition it to use a "too complex" shape and use a hash for storing instance variables. Without this patch, there were rare cases where shape tree growth could "explode" and cause performance degradation on what would otherwise have been cached fast paths. This patch puts a limit on shape tree growth, and gracefully degrades in the rare case where there could be a factorial growth in the shape tree. For example: ```ruby class NG; end HUGE_NUMBER.times do NG.new.instance_variable_set(:"@unique_ivar_#{_1}", 1) end ``` We consider objects to be "too complex" when the object's class has more than SHAPE_MAX_VARIATIONS (currently 8) leaf nodes in the shape tree and the object introduces a new variation (a new leaf node) associated with that class. For example, new variations on instances of the following class would be considered "too complex" because those instances create more than 8 leaves in the shape tree: ```ruby class Foo; end 9.times { Foo.new.instance_variable_set(":@uniq_#{_1}", 1) } ``` However, the following class is *not* too complex because it only has one leaf in the shape tree: ```ruby class Foo def initialize @a = @b = @c = @d = @e = @f = @g = @h = @i = nil end end 9.times { Foo.new } `` This case is rare, so we don't expect this change to impact performance of most applications, but it needs to be handled. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Transition shape when object's capacity changesJemma Issroff2022-11-101-1/+4
| | | | | | | | | | | | | | | | This commit adds a `capacity` field to shapes, and adds shape transitions whenever an object's capacity changes. Objects which are allocated out of a bigger size pool will also make a transition from the root shape to the shape with the correct capacity for their size pool when they are allocated. This commit will allow us to remove numiv from objects completely, and will also mean we can guarantee that if two objects share shapes, their IVs are in the same positions (an embedded and extended object cannot share shapes). This will enable us to implement ivar sets in YJIT using object shapes. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Increase SIZE_POOL_COUNT to 5Peter Zhu2022-05-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Having more size pools will allow us to allocate larger objects through Variable Width Allocation. I have attached some benchmark results below. Discourse: On Discourse, we don't see much change in response times. We do see a small reduction in RSS. Branch RSS: 377.8 MB Master RSS: 396.3 MB railsbench: On railsbench, we don't see a big change in RPS or p99 performance. We see a small increase in RSS. Branch RPS: 815.38 Master RPS: 811.73 Branch p99: 1.69 ms Master p99: 1.68 ms Branch RSS: 90.6 MB Master RSS: 89.4 MB liquid: We don't see a significant change in liquid performance. Branch parse & render: 29.041 I/s Master parse & render: 29.211 I/s
* Decouple incremental marking step from page sizesPeter Zhu2022-03-301-0/+1
| | | | | | | | | | | | | | | | | Currently, the number of incremental marking steps is calculated based on the number of pooled pages available. This means that if we make Ruby heap pages larger, it would run fewer incremental marking steps (which would mean each incremental marking step takes longer). This commit changes incremental marking to run after every INCREMENTAL_MARK_STEP_ALLOCATIONS number of allocations. This means that the behaviour of incremental marking remains the same regardless of the Ruby heap page size. I've benchmarked against discourse benchmarks and did not get a significant change in response times beyond the margin of error. This is expected as this new incremental marking algorithm behaves very similarly to the previous one.
* Change darray size to size_t and add functions that use GC mallocPeter Zhu2022-02-161-0/+1
| | | | | | | Changes size and capacity of darray to size_t to support more elements. Adds functions to darray that use GC allocation functions.
* Speed up Ractors for Variable Width AllocationPeter Zhu2021-11-231-1/+11
| | | | | | | | | | | | | | | | 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)
* gc.h: move rb_objspace_garbage_object_p to internal/gc.hYusuke Endoh2021-11-101-0/+1
| | | | ... to allow class.c to use the function
* [Feature #18239] Implement VWA for stringsPeter Zhu2021-10-251-15/+12
| | | | | This commit adds support for embedded strings with variable capacity and uses Variable Width Allocation to allocate strings.
* [Feature #18239] Refactor RVARGC alloc functionsPeter Zhu2021-10-251-5/+6
| | | | | The allocation functions no longer assume that one RVALUE needs to be allocated.
* internal/*.h: skip doxygen卜部昌平2021-09-101-1/+0
| | | | | These contents are purely implementation details, not worth appearing in CAPI documents. [ci skip]
* [Feature #18045] Implement size classes for GCPeter Zhu2021-08-251-1/+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>
* [Feature #18045] Remove T_PAYLOADPeter Zhu2021-08-251-4/+0
| | | | | | | This commit removes T_PAYLOAD since the new VWA implementation no longer requires T_PAYLOAD types. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Revert "[Feature #18045] Implement size classes for GC"Peter Zhu2021-08-231-1/+5
| | | | | | This reverts commits 48ff7a9f3e47bffb3e4d067a12ba9b936261caa0 and b2e2cf2dedd104acad8610721db5e4d341f135ef because it is causing crashes in SPARC solaris and i386 debian.
* [Feature #18045] Implement size classes for GCPeter Zhu2021-08-231-1/+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>
* [Feature #18045] Remove T_PAYLOADPeter Zhu2021-08-231-4/+0
| | | | | | | This commit removes T_PAYLOAD since the new VWA implementation no longer requires T_PAYLOAD types. Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Don't export rb_gc_ractor_newobj_cache_clearPeter Zhu2021-07-281-1/+1
|
* [Bug #18014] Fix memory leak in GC when using RactorsPeter Zhu2021-07-151-0/+6
| | | | | | | When a Ractor is removed, the freelist in the Ractor cache is not returned to the GC, leaving the freelist permanently lost. This commit recycles the freelist when the Ractor is destroyed, preventing a memory leak from occurring.
* Protoized old pre-ANSI K&R style declarations and definitionsNobuyoshi Nakada2021-05-071-1/+1
|
* Allow newobj_of0 and newobj_slowpath to allocate into multiple heap slotsMatt Valentine-House2021-05-061-7/+22
|
* Narrowed down unaligned member access region in RB_OBJ_WRITENobuyoshi Nakada2020-12-131-2/+2
| | | | | Since UNALIGNED_MEMBER_ACCESS assigns to an intermediate variable, it can cause unused-value warnings.
* RB_EC_NEWOBJ_OFKoichi Sasada2020-12-071-0/+7
| | | | NEWOBJ with current ec.
* Initialize new T_OBJECT as ROBJECT_EMBEDJohn Hawthorn2020-09-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | Previously, when an object is first initialized, ROBJECT_EMBED isn't set. This means that for brand new objects, ROBJECT_NUMIV(obj) is 0 and ROBJECT_IV_INDEX_TBL(obj) is NULL. Previously, this combination meant that the inline cache would never be initialized when setting an ivar on an object for the first time since iv_index_tbl was NULL, and if it were it would never be used because ROBJECT_NUMIV was 0. Both cases always fell through to the generic rb_ivar_set which would then set the ROBJECT_EMBED flag and initialize the ivar array. This commit changes rb_class_allocate_instance to set the ROBJECT_EMBED flag on the object initially and to initialize all members of the embedded array to Qundef. This allows the inline cache to be set correctly on first use and to be used on future uses. This moves rb_class_allocate_instance to gc.c, so that it has access to newobj_of. This seems appropriate given that there are other allocating methods in this file (ex. rb_data_object_wrap, rb_imemo_new).
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* add #include guard hack卜部昌平2020-04-131-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-11/+11
| | | Split ruby.h
* Separate objspace argument for rb_gc_disable and rb_gc_enableNobuyoshi Nakada2020-02-091-0/+3
|
* Try to fix error on SolarisKazuhiro NISHIYAMA2019-12-271-1/+1
|
* decouple internal.h headers卜部昌平2019-12-261-3/+5
| | | | | | | | | | | | | | | | | | 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).
* internal/gc.h rework卜部昌平2019-12-261-35/+106
| | | | | | Improved readability by reducing the use of macros. Also moved some part of internal/compilers.h into this file, because it seems to be the right place for them.
* add several __has_something macro卜部昌平2019-12-261-2/+0
| | | | | | | With these macros implemented we can write codes just like we can assume the compiler being clang. MSC_VERSION_SINCE is defined to implement those macros, but turned out to be handy for other places. The -fdeclspec compiler flag is necessary for clang to properly handle __has_declspec().