summaryrefslogtreecommitdiff
path: root/gc.c
AgeCommit message (Collapse)Author
2025-01-16Add not null checks to rb_gc_vm_weak_table_foreachPeter Zhu
If the tables are null (which happens when a GC is ran at boot), it will segfault when trying to iterate. Notes: Merged: https://github.com/ruby/ruby/pull/12591
2025-01-16Un-constify `mark_current_machine_context` on wasmNobuyoshi Nakada
As `SET_STACK_END` updates `ec->machine.stack_end`, it cannot be const.
2025-01-15Use existing vm variable for frozen strings in rb_gc_vm_weak_table_foreachPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12582
2025-01-02Move rbimpl_size_add_overflow from gc.c to memory.hPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12459
2024-12-25[Bug #20981] Bring back `rb_undefine_finalizer`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12468
2024-12-23Disable GC during RUBY_INTERNAL_EVENT_NEWOBJPeter Zhu
We must disable GC when running RUBY_INTERNAL_EVENT_NEWOBJ hooks because the callback could call xmalloc which could potentially trigger a GC, and a lot of code is unsafe to trigger a GC right after an object has been allocated because they perform initialization for the object and assume that the GC does not trigger before then. Notes: Merged: https://github.com/ruby/ruby/pull/12419
2024-12-22Allow variables in modular_gc_dirNobuyoshi Nakada
Such as `$(ruby_version)`, `$(arch)` and so on. Notes: Merged: https://github.com/ruby/ruby/pull/12428
2024-12-22Support RUBY_MODULAR_GC with LOAD_RELATIVENobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12428
2024-12-20Don't print bug report in asan_death_callback when no VMPeter Zhu
If we don't have the VM (e.g. printing memory leaks in LSAN after shutdown) then we will crash when we try to print the bug report. This issue was reported in: https://github.com/ruby/ruby/pull/12309#issuecomment-2555766525 Notes: Merged: https://github.com/ruby/ruby/pull/12413
2024-12-20Memerror is fatal if VM cannot be unlocked.Matt Valentine-House
[Bug #20942] If we've raised a memerror while the VM is locked, and the tag we're jumping to has been locked at a different level to the current lock (ie. we've locked the VM again since the tag we're jumping to) then we should consider this memerror fatal and exit, since the tag cannot unlock the VM. Co-Authored-By: Peter Zhu <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/12393
2024-12-19Prefix asan_poison_object with rbPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-19Make asan_poison_object poison the whole slotPeter Zhu
This change poisons the whole slot of the object rather than just the flags. This allows ASAN to find any reads/writes into the slot after it has been freed. Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-12-17Assert Ruby object in rb_gc_locationPeter Zhu
rb_gc_location doesn't check that the object is actually a Ruby object and only checks if the object looks like a T_MOVED. This may have unexpected outcomes if the object is not a Ruby object (e.g. a piece of malloc memory may be corrupted). Notes: Merged: https://github.com/ruby/ruby/pull/12371
2024-12-16Don't directly use rb_gc_impl_location in gc.cPeter Zhu
Use the wrapper gc_location_internal instead that checks for special constants. Notes: Merged: https://github.com/ruby/ruby/pull/12359
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-16Check whether object is valid in allocation_info_tracer_compactPeter Zhu
When reference updating ObjectSpace.trace_object_allocations, we need to check whether the object is valid or not because it does not mark the object so the object may be dead. This can cause a segmentation fault if the object is on a free heap page. For example, the following script crashes: require "objspace" objs = [] ObjectSpace.trace_object_allocations do 1_000_000.times do objs << Object.new end end objs = nil # Free pages that the objs were on GC.start # Run compaction and check that it doesn't crash GC.compact Notes: Merged: https://github.com/ruby/ruby/pull/12360
2024-12-12Call rb_bug_without_die when ASAN error reportedPeter Zhu
This will give us the Ruby stack trace when an ASAN error is reported. Notes: Merged: https://github.com/ruby/ruby/pull/12309
2024-12-11[Bug #20941] Bail out when recursing no memoryNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12307
2024-12-06Add rb_gc_impl_active_gc_name to gc/gc_impl.hPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12271
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-12-04Use BUILDING_SHARED_GC instead of RB_AMALGAMATED_DEFAULT_GCPeter Zhu
We can use the BUILDING_SHARED_GC flag to check if we're building gc_impl.h as a shared GC or building the default GC. Notes: Merged: https://github.com/ruby/ruby/pull/12243
2024-12-04[Bug #20928] Fix build when `malloc_usable_size` is availableNobuyoshi Nakada
Copy from gc/default/default.c and revert the part of 51bd81651794. Notes: Merged: https://github.com/ruby/ruby/pull/12260
2024-12-03Move external_gc_loaded_p to gc_functionsPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12242
2024-11-29RUBY_DEBUG: Verify PC correctness every allocJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/12204
2024-11-29prefer ruby_memerror instead卜部昌平
This could be out of GVL Notes: Merged: https://github.com/ruby/ruby/pull/12188
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-25define rb_current_ec_set in all casesMatt Valentine-House
Notes: Merged: https://github.com/ruby/ruby/pull/12149
2024-11-25Place all non-default GC API behind USE_SHARED_GCMatt Valentine-House
So that it doesn't get included in the generated binaries for builds that don't support loading shared GC modules Co-Authored-By: Peter Zhu <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/12149
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
2024-11-24Fix a build failure with muslEarlopain
``` compiling gc.c In file included from gc.c:80: /usr/include/sys/prctl.h:88:8: error: redefinition of 'struct prctl_mm_map' 88 | struct prctl_mm_map { | ^~~~~~~~~~~~ In file included from gc.c:79: /usr/include/linux/prctl.h:134:8: note: originally defined here 134 | struct prctl_mm_map { | ^~~~~~~~~~~~ ``` The first include is not needed and is what causes this issue. Two other places in ruby exclusively use the sys import. See https://github.com/seccomp/libseccomp/issues/19 for a similar problem. Notes: Merged: https://github.com/ruby/ruby/pull/12154
2024-11-21Annotate anonymous mmapKunshan Wang
Use PR_SET_VMA_ANON_NAME to set human-readable names for anonymous virtual memory areas mapped by `mmap()` when compiled and run on Linux 5.17 or higher. This makes it convenient for developers to debug mmap. Notes: Merged: https://github.com/ruby/ruby/pull/12119
2024-11-17Fix format modifier for `size_t`Nobuyoshi Nakada
Also fix the message, just `RB_GC_MAX_NAME_LEN` chars long is OK.
2024-11-15`rb_bug` prints a newline after the given message [ci skip]Nobuyoshi Nakada
2024-11-14rb_bug if rb_gc_impl_active_gc_name is too longMatt Valentine-House
This avoids the need to malloc, and reduces the complexity of truncating the long string for display in RUBY_DESCRIPTION. The developer of a GC implementation should be responsible for giving it a succinct name. Notes: Merged: https://github.com/ruby/ruby/pull/11872
2024-11-14Include the currently active GC in RUBY_DESCRIPTIONMatt Valentine-House
This will add +MOD_GC to the version string and Ruby description when Ruby is compiled with shared gc support. When shared GC support is compiled in and a GC module has been loaded using RUBY_GC_LIBRARY, the version string will include the name of the currently active GC as reported by the rb_gc_active_gc_name function in the form +MOD_GC[gc_name] [Feature #20794] Notes: Merged: https://github.com/ruby/ruby/pull/11872
2024-11-14Expose GC.config[:implementation], to query the currently active GCMatt Valentine-House
And a default and readonly key to the GC.config hash that names the current GC implementation. This is provided by each implementation by the API function rb_gc_impl_active_gc_name Notes: Merged: https://github.com/ruby/ruby/pull/11872
2024-10-23Move error handling for GC.stat_heap to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11932
2024-10-23Make rb_gc_impl_stat_heap return a VALUE instead of size_tPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11932
2024-10-23Move error handling for GC.stat to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11932
2024-10-23Make rb_gc_impl_stat return a VALUE instead of size_tPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11932
2024-10-23Move error handling for GC.latest_gc_info to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11932
2024-10-21Don't clear out flags in rb_gc_obj_freePeter Zhu
If there's a crash after rb_gc_obj_free, it's hard to debug because the flags have been cleared out already. Notes: Merged: https://github.com/ruby/ruby/pull/11925
2024-10-18Move object processing in Process.warmup to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11904
2024-10-11Improve RUBY_GC_LIBRARYPeter Zhu
Instead of passing the full GC SO file name to RUBY_GC_LIBRARY, we now only need to pass the GC name. For example, before we needed to pass `RUBY_GC_LIBRARY=librubygc.default.so` but now we only need to pass `RUBY_GC_LIBRARY=default`. Notes: Merged: https://github.com/ruby/ruby/pull/11866
2024-10-10Move return value of rb_gc_impl_config_set to gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11870
2024-10-08Cast via `uintptr_t` function pointer between object pointerNobuyoshi Nakada
- ISO C forbids conversion of function pointer to object pointer type - ISO C forbids conversion of object pointer to function pointer type
2024-10-08Improve error message in load_external_gc_funcPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11817
2024-10-05Non-zero exit when error in loading shared GCPeter Zhu
Before this commit, when there is an error in loading the shared GC, an error was outputted but it did not exit, causing it to segfault later on. Notes: Merged: https://github.com/ruby/ruby/pull/11784
2024-10-03Rename size_pool -> heapMatt Valentine-House
Now that we've inlined the eden_heap into the size_pool, we should rename the size_pool to heap. So that Ruby contains multiple heaps, with different sized objects. The term heap as a collection of memory pages is more in memory management nomenclature, whereas size_pool was a name chosen out of necessity during the development of the Variable Width Allocation features of Ruby. The concept of size pools was introduced in order to facilitate different sized objects (other than the default 40 bytes). They wrapped the eden heap and the tomb heap, and some related state, and provided a reasonably simple way of duplicating all related concerns, to provide multiple pools that all shared the same structure but held different objects. Since then various changes have happend in Ruby's memory layout: * The concept of tomb heaps has been replaced by a global free pages list, with each page having it's slot size reconfigured at the point when it is resurrected * the eden heap has been inlined into the size pool itself, so that now the size pool directly controls the free_pages list, the sweeping page, the compaction cursor and the other state that was previously being managed by the eden heap. Now that there is no need for a heap wrapper, we should refer to the collection of pages containing Ruby objects as a heap again rather than a size pool Notes: Merged: https://github.com/ruby/ruby/pull/11771
2024-10-02Deduplicate RGENGC_CHECK_MODE into gc/gc.hPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11764