summaryrefslogtreecommitdiff
path: root/gc/default/default.c
AgeCommit message (Collapse)Author
5 daysCount metadata entries automatically from the names listNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13181
5 daysUpdate `RB_GC_OBJECT_METADATA_ENTRY_COUNT`Jean Boussier
In cb1ea54bbf6cdf49c53f42720fec1a151069810c I added one more metadata flag, but didn't notice `RB_GC_OBJECT_METADATA_ENTRY_COUNT` had to be incremented. This should fix ASAN builds. Interestingly, bdb25959fb047af0358f33d7327b7752dca14aa4 already caused the count to be off by one, so I had to increment it by 2. Notes: Merged: https://github.com/ruby/ruby/pull/13179
6 daysobjspace_dump: Include `shareable` flagJean Boussier
Given that the currently planned ractor local GC implementation performance will heavilly be influenced by the number of shareable objects it would be valuable to be able to know how many of them are in the heap.
7 daysEagerly store a copy of `object_id` in finalizer table.Jean Boussier
This makes the finalizer table fully self contained, so GC no longer need to delay cleaning the `obj_to_id_tbl`. Notes: Merged: https://github.com/ruby/ruby/pull/13155
7 daysrb_gc_impl_define_finalizer: unlock on early returnJean Boussier
8 daysAdd missing lock in `rb_gc_impl_define_finalizer`Jean Boussier
`objspace->finalizer_table` must be synchronized, otherwise concurrent insertion from multiple ractors will cause a crash. Repro: ```ruby ractors = 5.times.map do |i| Ractor.new do 100_000.times.map do o = Object.new ObjectSpace.define_finalizer(o, ->(id) {}) o end end end ractors.each(&:take) ``` Notes: Merged: https://github.com/ruby/ruby/pull/13151
2025-04-15Lazily create `objspace->id_to_obj_tbl`Jean Boussier
This inverse table is only useful if `ObjectSpace._id2ref` is used, which is extremely rare. The only notable exception is the `drb` gem and even then it has an option not to rely on `_id2ref`. So if we assume this table will never be looked up, we can just not maintain it, and if it turns out `_id2ref` is called, we can lock the VM and re-build it. ``` compare-ruby: ruby 3.5.0dev (2025-04-10T09:44:40Z master 684cfa42d7) +YJIT +PRISM [arm64-darwin24] built-ruby: ruby 3.5.0dev (2025-04-10T10:13:43Z lazy-id-to-obj d3aa9626cc) +YJIT +PRISM [arm64-darwin24] warming up.. | |compare-ruby|built-ruby| |:----------|-----------:|---------:| |baseline | 26.364M| 25.974M| | | 1.01x| -| |object_id | 10.293M| 14.202M| | | -| 1.38x| ``` Notes: Merged: https://github.com/ruby/ruby/pull/13115
2025-04-07Grow GC heaps independentlyPeter Zhu
[Bug #21214] If we allocate objects where one heap holds transient objects and another holds long lived objects, then the heap with transient objects will grow along the heap with long lived objects, causing higher memory usage. For example, we can see this issue in this script: def allocate_small_object = [] def allocate_large_object = Array.new(10) arys = Array.new(1_000_000) do # Allocate 10 small transient objects 10.times { allocate_small_object } # Allocate 1 large object that is persistent allocate_large_object end pp GC.stat pp GC.stat_heap Before this change: heap_live_slots: 2837243 {0 => {slot_size: 40, heap_eden_pages: 1123, heap_eden_slots: 1838807}, 2 => {slot_size: 160, heap_eden_pages: 2449, heap_eden_slots: 1001149}, } After this change: heap_live_slots: 1094474 {0 => {slot_size: 40, heap_eden_pages: 58, heap_eden_slots: 94973}, 2 => {slot_size: 160, heap_eden_pages: 2449, heap_eden_slots: 1001149}, } Notes: Merged: https://github.com/ruby/ruby/pull/13061
2025-03-31Don't preserve `object_id` when moving object to another RactorJean Boussier
That seemed like the logical thing to do to me, but ko1 disagree. Notes: Merged: https://github.com/ruby/ruby/pull/13008
2025-03-31Ractor: Fix moving embedded objectsJean Boussier
[Bug #20271] [Bug #20267] [Bug #20255] `rb_obj_alloc(RBASIC_CLASS(obj))` will always allocate from the basic 40B pool, so if `obj` is larger than `40B`, we'll create a corrupted object when we later copy the shape_id. Instead we can use the same logic than ractor copy, which is to use `rb_obj_clone`, and later ask the GC to free the original object. We then must turn it into a `T_OBJECT`, because otherwise just changing its class to `RactorMoved` leaves a lot of ways to keep using the object, e.g.: ``` a = [1, 2, 3] Ractor.new{}.send(a, move: true) [].concat(a) # Should raise, but wasn't. ``` If it turns out that `rb_obj_clone` isn't performant enough for some uses, we can always have carefully crafted specialized paths for the types that would benefit from it. Notes: Merged: https://github.com/ruby/ruby/pull/13008
2025-03-25Prefer FL_TEST_RAW() in GC on known on-heap objectsAlan Wu
Was reading some assembly and noticed the dead branches generated for FL_TEST(). Just a quick basic pass to change the obvious places; there may be other opportunities. Notes: Merged: https://github.com/ruby/ruby/pull/12980 Merged-By: XrXr
2025-03-25Make ruby_autocompact_compare_func staticPeter Zhu
It's not used outside of default.c. Notes: Merged: https://github.com/ruby/ruby/pull/12964
2025-03-25Make ruby_enable_autocompact staticPeter Zhu
It's not used outside of defaut.c Notes: Merged: https://github.com/ruby/ruby/pull/12964
2025-03-13Move object_id to flags for ObjectSpace dumpsPeter Zhu
Moving object_id dumping from ObjectSpace to the GC flags allows ObjectSpace to not assume the FL_SEEN_OBJ_ID flag and instead move it to the responsibility of the GC. Notes: Merged: https://github.com/ruby/ruby/pull/12915
2025-02-19Fix value of RB_GC_OBJECT_METADATA_ENTRY_COUNTPeter Zhu
There are 7 entries in RB_GC_OBJECT_METADATA_ENTRY_COUNT.
2025-02-19Add age to rb_gc_object_metadataPeter Zhu
This will allow ObjectSpace.dump to output the age of the object. Notes: Merged: https://github.com/ruby/ruby/pull/12777
2025-02-19Add rb_gc_object_metadata APIPeter Zhu
This function replaces the internal rb_obj_gc_flags API. rb_gc_object_metadata returns an array of name and value pairs, with the last element having 0 for the name. Notes: Merged: https://github.com/ruby/ruby/pull/12777
2025-02-19[wasm] Stop using mprotect(PROT_NONE) on WASIYuta Saito
we had been using a stub weak definition of `mprotect` in wasm/missing.c so far, but wasi-sdk 23 added mprotect emulation to wasi-libc[^1], so the emulation is now linked instead. However, the emulation doesn't support PROT_NONE and fails with ENOSYS, so we need to avoid calling mprotect completely on WASI. [^1]: https://github.com/WebAssembly/wasi-libc/commit/7528b13170462c82e367d91ae0ecead84e470ceb Notes: Merged: https://github.com/ruby/ruby/pull/12776
2025-02-10gc.c: Remove no-op codeDaisuke Aritomo
In this context, `vm_locked` is a argument variable, and is not used later in the function. Notes: Merged: https://github.com/ruby/ruby/pull/12718
2025-01-29Use an identity hash instead of array for stress_to_classPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12664
2025-01-29Fix GC.add_stress_to_class and GC.remove_stress_to_classPeter Zhu
These methods were accidentally removed in [Feature #20470]. This commit adds them back. Notes: Merged: https://github.com/ruby/ruby/pull/12664
2025-01-29Suppress unused-value warningsNobuyoshi Nakada
2025-01-27Fix gc_update_references_weak_table_i for ASANPeter Zhu
If the object is a T_MOVED, then it is poisoned in ASAN, so we need to unpoison it before checking the type. Notes: Merged: https://github.com/ruby/ruby/pull/12644
2025-01-27Use rb_gc_vm_weak_table_foreach for reference updatingPeter Zhu
We can use rb_gc_vm_weak_table_foreach for reference updating of weak tables in the default GC. Notes: Merged: https://github.com/ruby/ruby/pull/12629
2025-01-22Add generic ivar reference updating stepPeter Zhu
Previously, generic ivars worked differently than the other global tables during compaction. The other global tables had their references updated through iteration during rb_gc_update_vm_references. Generic ivars updated the keys when the object moved and updated the values while reference updating the object. This is inefficient as this required one lookup for every moved object and one lookup for every object with generic ivars. Instead, this commit changes it to iterate over the generic ivar table to update both the keys and values. Notes: Merged: https://github.com/ruby/ruby/pull/12607
2025-01-05gc/default/default.c: don't call `malloc_usable_size` when hint is presentJean Boussier
Depending on the allocator, `malloc_usable_size` may be very cheap or quite expensive. On `macOS` for instance, it's about as expensive as `malloc`. In many case we call `objspace_malloc_size` with as size we initially requested as `hint`. The real usable size may be a few bytes bigger, but since we only use that data to feed GC heuristics, I don't think it's very important to be perfectly accurate. It would make sense to call `malloc_usable_size` after growing a String or Array to use the extra capacity, but here we don't do that, so the call isn't worth its cost. Notes: Merged: https://github.com/ruby/ruby/pull/12490
2025-01-02Use rb_darray_insert_without_gc for heap_pages darrayPeter Zhu
rb_darray_insert could trigger a GC, which would cause problems if it freed pages while a new page was being inserted. For example, the following script fails: GC.stress = true GC.auto_compact = :empty 10.times do GC.verify_compaction_references(expand_heap: true, toward: :empty) end It errors out with: 'GC.verify_compaction_references': malloc: possible integer overflow (8*18446744073709551603) (ArgumentError) Notes: Merged: https://github.com/ruby/ruby/pull/12459
2025-01-02Revert "Remove with_gc functions in darray"Peter Zhu
This reverts commit 24a740796050b72aa2d35339ba2a317d4eda7b75. Notes: Merged: https://github.com/ruby/ruby/pull/12459
2024-12-19Prefix asan_poison_object with rbPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Fix compaction in ASAN with RGENGC_CHECK_MODE enabledPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Don't calculate the aligned slot when unlocking pagePeter Zhu
If we try to use GET_PAGE_HEADER, it can trigger the read barrier. If we try to align on the slot then we end up unlocking the heap page of a lower memory address. Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Don't unpoison a NULL objectPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Unpoison memory before accessing next element of freelistPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-16Move special constant check in rb_gc_location to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12359
2024-12-11Fix compilation with MALLOC_ALLOCATED_SIZEJohn Hawthorn
Previously compilation failed with -DMALLOC_ALLOCATED_SIZE=1 Co-authored-by: Matthew Draper <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/12313
2024-12-11[Bug #20941] Bail out when recursing no memoryNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12307
2024-12-05Use rb_gc_enable/rb_gc_disable_no_rest instead of ruby_disable_gcPeter Zhu
We should use the rb_gc_enable/rb_gc_disable_no_rest APIs instead of directly setting the ruby_disable_gc variable. Notes: Merged: https://github.com/ruby/ruby/pull/12264
2024-12-05darray.h does not depend on internal/bits.hPeter Zhu
darray.h no longer depends on internal/bits.h, so we can remove it. Notes: Merged: https://github.com/ruby/ruby/pull/12270
2024-12-05Standardize on the name "modular GC"Peter Zhu
We have name fragmentation for this feature, including "shared GC", "modular GC", and "external GC". This commit standardizes the feature name to "modular GC" and the implementation to "GC library". Notes: Merged: https://github.com/ruby/ruby/pull/12261
2024-11-29rb_gc_impl_malloc can return NULL卜部昌平
Let there be rooms for each GC implementations how to handle multi threaded situations. They can be totally reentrant, or can have their own mutex, or can rely on rb_thread_call_with_gvl. In any ways the allocator (has been, but now officially is) expected to run properly without a GVL. This means there need be a way for them to inform the interpreter about their allocation failures, without relying on raising exceptions. Let them do so by returning NULL. Notes: Merged: https://github.com/ruby/ruby/pull/12188
2024-11-25Use extconf to build external GC modulesMatt Valentine-House
Co-Authored-By: Peter Zhu <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/12149