summaryrefslogtreecommitdiff
path: root/gc.c
AgeCommit message (Collapse)Author
2021-11-22Removes unused HEAP_PAGE_BITMAP_PLANES constant from gc.cJemma Issroff
Notes: Merged: https://github.com/ruby/ruby/pull/4154
2021-11-22Make RCLASS_EXT(c)->subclasses a doubly linked listMatt Valentine-House
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 Notes: Merged: https://github.com/ruby/ruby/pull/5125
2021-11-19gc.c: Fix a compile error on some crossbuildsYusuke Endoh
http://rubyci.s3.amazonaws.com/crossruby/crossruby-master-wasm32_emscripten/log/20211118T233311Z.log.html.gz#make ``` compiling gc.c gc.c:10629:47: error: implicit conversion loses integer precision: 'unsigned long long' to 'size_t' (aka 'unsigned long') [-Werror,-Wshorten-64-to-32] SET(time, objspace->profile.total_time_ns / (1000 * 1000) /* ns -> ms */); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gc.c:10624:9: note: expanded from macro 'SET' return attr; \ ~~~~~~ ^~~~ gc.c:10629:47: error: implicit conversion loses integer precision: 'unsigned long long' to 'unsigned long' [-Werror,-Wshorten-64-to-32] SET(time, objspace->profile.total_time_ns / (1000 * 1000) /* ns -> ms */); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gc.c:10626:68: note: expanded from macro 'SET' rb_hash_aset(hash, gc_stat_symbols[gc_stat_sym_##name], SIZET2NUM(attr)); ~~~~~~~~~ ^~~~ 2 errors generated. ```
2021-11-19GC measurement featureKoichi Sasada
* `GC.measure_total_time = true` enables total time measurement (default: true) * `GC.measure_total_time` returns current flag. * `GC.total_time` returns measured total time in nano seconds. * `GC.stat(:time)` (and Hash) returns measured total time in milli seconds. Notes: Merged: https://github.com/ruby/ruby/pull/4757
2021-11-19support `GC.stat(:time)` take 2Koichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/4757
2021-11-15`Primitive.mandatory_only?` for fast pathKoichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/5112
2021-11-11Remove RCLASS(obj)->ptr when RVARGC is enabledMatt Valentine-House
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 Notes: Merged: https://github.com/ruby/ruby/pull/5101
2021-11-11fix a memory leak introduced in 8bbd319Matt Valentine-House
This commit fixes a memory leak introduced in an early part of the variable width allocation project that would prevent the rb_classext_t struct from being free'd when the class is swept. Notes: Merged: https://github.com/ruby/ruby/pull/5103
2021-11-08[Feature #18290] Deprecate rb_gc_force_recycle and remove ↵Peter Zhu
invalidate_mark_stack_chunk This commit deprecates rb_gc_force_recycle and coverts it to a no-op function. Also removes invalidate_mark_stack_chunk since only rb_gc_force_recycle uses it. Notes: Merged: https://github.com/ruby/ruby/pull/4363
2021-10-29make obj_free return true when it frees an objectMatt Valentine-House
Previously obj_free returned true when it could not free a slot because of a finalizer, and false when it successfully frees a slot. Notes: Merged: https://github.com/ruby/ruby/pull/5055
2021-10-29Prefer size pool heap macros over direct accessMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/5054
2021-10-28Fix a warningKazuhiro NISHIYAMA
``` ../gc.c:2342:45: warning: comparison of integers of different signs: 'short' and 'size_t' (aka 'unsigned long') [-Wsign-compare] GC_ASSERT(size_pools[pool_id].slot_size == slot_size); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ ``` Add cast to short, because `GC_ASSERT`s in `size_pool_for_size` already use cast to short.
2021-10-28Fix a warningKazuhiro NISHIYAMA
``` ../gc.c:2342:25: warning: array subscript is of type 'char' [-Wchar-subscripts] GC_ASSERT(size_pools[pool_id].slot_size == slot_size); ^~~~~~~~ ```
2021-10-27Align `RFloat` at VALUE boundaryNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5027
2021-10-25[Feature #18239] Implement VWA for stringsPeter Zhu
This commit adds support for embedded strings with variable capacity and uses Variable Width Allocation to allocate strings. Notes: Merged: https://github.com/ruby/ruby/pull/4933
2021-10-25[Feature #18239] Refactor RVARGC alloc functionsPeter Zhu
The allocation functions no longer assume that one RVALUE needs to be allocated. Notes: Merged: https://github.com/ruby/ruby/pull/4933
2021-10-24Suppress false warning for freed pointerNobuyoshi Nakada
2021-10-21Push compaction page alignment check downAaron Patterson
It seems like `gc_verify_compaction_references` is not protected in case alignment is wrong. This commit pushes the alignment check down to `gc_start_internal` so that anyone trying to compact will check page alignment I think this method may be getting called on PowerPC and the alignment might be wrong. http://rubyci.s3.amazonaws.com/ppc64le/ruby-master/log/20211021T190006Z.fail.html.gz Notes: Merged: https://github.com/ruby/ruby/pull/5001
2021-10-20Partial revert of ceebc7fc98dAaron Patterson
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.
2021-10-20MicroJIT: generate less code for CFUNCsAlan Wu
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.
2021-10-20Print errno when mprotect failsAaron Patterson
Trying to figure out the problem on s390x. Notes: Merged: https://github.com/ruby/ruby/pull/4996
2021-10-04Move rb_ractor_p definitionS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4422 Merged-By: nobu <nobu@ruby-lang.org>
2021-10-03Using NIL_P macro instead of `== Qnil`S.H
Notes: Merged: https://github.com/ruby/ruby/pull/4925 Merged-By: nobu <nobu@ruby-lang.org>
2021-10-03Cast to void pointer to suppress -Wformat-pedantic in RUBY_DEBUG_LOGNobuyoshi Nakada
2021-09-27Introduce `RBIMPL_NONNULL_ARG` macroNobuyoshi Nakada
Runtime assertion for the argument declared as non-null. This macro does nothing if `RBIMPL_ATTR_NONNULL` is effective, otherwise asserts that the argument is non-null. Notes: Merged: https://github.com/ruby/ruby/pull/4898 Merged-By: nobu <nobu@ruby-lang.org>
2021-09-20Fix malloc_increase is not correctly calculatedPeter Zhu
Commit 123eeb1c1a904923754ce65148dbef045b56e083 added incremental GC which moved resetting malloc_increase, oldmalloc_increase to before marking. However, during_minor_gc is not set until gc_marks_start. So the value will be from the last GC run, rather than the current one. Before the incremental GC commit, this code was in gc_before_sweep which ran before sweep (after marking) so the value during_minor_gc was correct. Notes: Merged: https://github.com/ruby/ruby/pull/4860
2021-09-15Fix total_freed_objects for invalidated pagesPeter Zhu
When the object is moved back into the T_MOVED, the flags of the T_MOVED is not copied, so the FL_FROM_FREELIST flag is lost. This causes total_freed_objects to always be incremented. Notes: Merged: https://github.com/ruby/ruby/pull/4841
2021-09-15Don't overwrite free_slots count during sweepingPeter Zhu
gc_compact_finish may invalidate pages, which may move objects from this page to other pages, which updates the free_slots of this page. Notes: Merged: https://github.com/ruby/ruby/pull/4831
2021-09-15Update the free_slots count of the original pagePeter Zhu
When invalidating a page during compaction, the free_slots count should be updated for the page of the object and not the page of the forwarding address (since the object gets moved back to the forwarding address). Notes: Merged: https://github.com/ruby/ruby/pull/4831
2021-09-11Using RB_BIGNUM_TYPE_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4805
2021-09-10suppress GCC's -Wnonnull-compare卜部昌平
This particular NULL check must be a good thing to do both statically and dynamically. Notes: Merged: https://github.com/ruby/ruby/pull/4815
2021-09-05Replace RBOOL macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4791
2021-09-01Remove heap_is_swept_object functionPeter Zhu
is_swept_object just calls heap_is_swept_object so remove heap_is_swept_object. Notes: Merged: https://github.com/ruby/ruby/pull/4799
2021-08-27Fix memory leak in Variable Width AllocationPeter Zhu
Force recycled objects could create a freelist for the page. At the start of sweeping we should append to the freelist to avoid permanently losing the slots on the freelist. Notes: Merged: https://github.com/ruby/ruby/pull/4786
2021-08-25[Feature #18045] Implement size classes for GCPeter Zhu
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> Notes: Merged: https://github.com/ruby/ruby/pull/4773
2021-08-25[Feature #18045] Remove T_PAYLOADPeter Zhu
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> Notes: Merged: https://github.com/ruby/ruby/pull/4773
2021-08-23Replace intptr_t with uintptr_t in gc.cPeter Zhu
Pointers may be large to the point where intptr_t would be negative. This is problematic when doing comparisons of pointers. Notes: Merged: https://github.com/ruby/ruby/pull/4765
2021-08-23Revert "[Feature #18045] Implement size classes for GC"Peter Zhu
This reverts commits 48ff7a9f3e47bffb3e4d067a12ba9b936261caa0 and b2e2cf2dedd104acad8610721db5e4d341f135ef because it is causing crashes in SPARC solaris and i386 debian. Notes: Merged: https://github.com/ruby/ruby/pull/4764
2021-08-23[Feature #18045] Implement size classes for GCPeter Zhu
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> Notes: Merged: https://github.com/ruby/ruby/pull/4680
2021-08-23[Feature #18045] Remove T_PAYLOADPeter Zhu
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> Notes: Merged: https://github.com/ruby/ruby/pull/4680
2021-08-20Turned the reminder comment to a compile-time messageNobuyoshi Nakada
2021-08-20Undefine the alloc function for T_DATA classesMike Dalessio
which have not undefined or redefined it. When a `T_DATA` object is created whose class has not undefined or redefined the alloc function, the alloc function now gets undefined by Data_Wrap_Struct et al. Optionally, a future release may also warn that this being done. This should help developers of C extensions to meet the requirements explained in "doc/extension.rdoc". Without a check like this, there is no easy way for an author of a C extension to see where they have made a mistake. Notes: Merged: https://github.com/ruby/ruby/pull/4604
2021-08-16`SIZE_MAX` is not `size_t` on emscriptenNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4745
2021-08-11Make during_compacting flag in GC one bitPeter Zhu
Commit c32218de1ba094223420a4ea017707f48d0009c5 turned during_compacting flag to 2 bits to support the case when there is no write barrier. But commit 32b7dcfb56a417c1d1c354102351fc1825d653bf changed compaction to always enable the write barrier. This commit cleans up some of the leftover code. Notes: Merged: https://github.com/ruby/ruby/pull/4730
2021-08-08Make bit flags `reason` unsignedNobuyoshi Nakada
2021-08-08Suppress warnings when GC_ENABLE_INCREMENTAL_MARK == 0Nobuyoshi Nakada
2021-08-02Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4695 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-29Do not check pending interrupts when running finalizersJeremy Evans
This fixes cases where exceptions raised using Thread#raise are swallowed by finalizers and not delivered to the running thread. This could cause issues with finalizers that rely on pending interrupts, but that case is expected to be rarer. Fixes [Bug #13876] Fixes [Bug #15507] Co-authored-by: Koichi Sasada <ko1@atdot.net> Notes: Merged: https://github.com/ruby/ruby/pull/4366
2021-07-23Suppress exception message in finalizer [Feature #17798]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4670
2021-07-23Show exception in finalizer [Feature #17798]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4670