summaryrefslogtreecommitdiff
path: root/gc.c
AgeCommit message (Collapse)Author
2024-08-29Change each_location to accept data instead of objspacePeter Zhu
The callers were abusing each_location and passing data into the objspace argument. Notes: Merged: https://github.com/ruby/ruby/pull/11481
2024-08-29Move checks for special const for markingPeter Zhu
This commit moves checks to RB_SPECIAL_CONST_P out of the GC implmentation and into gc.c. Notes: Merged: https://github.com/ruby/ruby/pull/11478
2024-08-29Move marking code together in gc.cPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11478
2024-08-22Don't use gc_impl.h inside of gc/gc.hPeter Zhu
Using gc_impl.h inside of gc/gc.h will cause gc/gc.h to use the functions in gc/default.c when builing with shared GC support because gc/gc.h is included into gc.c before the rb_gc_impl functions are overridden by the preprocessor. Notes: Merged: https://github.com/ruby/ruby/pull/11423
2024-08-15Fix GC_ASSERT for gc.c and gc/default.cPeter Zhu
gc.c mistakenly defined GC_ASSERT as blank, which caused it to be a no-op. This caused all assertions in gc.c and gc/default.c to not do anything. This commit fixes it by moving the definition of GC_ASSERT to gc/gc.h. Notes: Merged: https://github.com/ruby/ruby/pull/11377
2024-08-14[DOC] Update comment about how object ID is calculatedPeter Zhu
The object ID no longer treats symbols in a special way so we can simplify the comment about how it is calculated. Notes: Merged: https://github.com/ruby/ruby/pull/11346
2024-08-13Don't set stack end in rb_gc_mark_rootsPeter Zhu
We don't need to set the stack end in rb_gc_mark_roots because it is already set in mark_current_machine_context. Notes: Merged: https://github.com/ruby/ruby/pull/11355
2024-08-09Remove rb_gc_impl_objspace_markPeter Zhu
It's not necessary for the GC implementation to call rb_gc_mark_roots which calls back into the GC implementation's rb_gc_impl_objspace_mark. Notes: Merged: https://github.com/ruby/ruby/pull/11325
2024-08-08Make YJIT a GC root rather than an object (#11343)Peter Zhu
YJIT currently uses the YJIT root object to mark objects during GC and update references during compaction. This object otherwise serves no purpose. This commit changes it YJIT to be step when marking the GC root. This saves some memory from being allocated from the system and the GC. Notes: Merged-By: maximecb <[email protected]>
2024-07-26Fix a -Wmaybe-uninitializedAlan Wu
With the body of functions available, GCC noticed that lev is uninitialized in rb_gc_vm_lock_no_barrier() in single ractor mode.
2024-07-26Put the default GC implementation back into gc.oAlan Wu
We discovered that having gc.o and gc_impl.o in separate translation units diminishes codegen quality with GCC 11 on x86-64. This commit solves that problem by including default/gc.c into gc.c, letting the optimizer have visibility into the body of functions again in builds not using link-time optimization, which are common. This effectively restores things to the way they were before [Feature #20470] from the optimizer's perspective while maintaining the ability to build gc/default.c as a DSO. There were a few functions duplicated across gc.c and gc/default.c. Extract them and put them into gc/gc.h.
2024-07-22newobj_of(): Use parameter instead of GET_RACTOR()Alan Wu
No point repeating the work callers to this function already do. Notes: Merged: https://github.com/ruby/ruby/pull/11224
2024-07-22Add newline when printing dlopen error messagePeter Zhu
2024-07-19Move frozen check out of rb_gc_impl_undefine_finalizerPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11199
2024-07-19Make rb_gc_impl_undefine_finalizer return voidPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11199
2024-07-19Move return value of rb_define_finalizer outPeter Zhu
Moves return value logic of rb_define_finalizer out from rb_gc_impl_define_finalizer. Notes: Merged: https://github.com/ruby/ruby/pull/11199
2024-07-19Make define_final call rb_define_finalizerPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11199
2024-07-15Add gc/gc.h for functions in gc.c and used by GC implementationsPeter Zhu
2024-07-12Provide GC.config to disable major GC collectionsMatt Valentine-House
This feature provides a new method `GC.config` that configures internal GC configuration variables provided by an individual GC implementation. Implemented in this PR is the option `full_mark`: a boolean value that will determine whether the Ruby GC is allowed to run a major collection while the process is running. It has the following semantics This feature configures Ruby's GC to only run minor GC's. It's designed to give users relying on Out of Band GC complete control over when a major GC is run. Configuring `full_mark: false` does two main things: * Never runs a Major GC. When the heap runs out of space during a minor and when a major would traditionally be run, instead we allocate more heap pages, and mark objspace as needing a major GC. * Don't increment object ages. We don't promote objects during GC, this will cause every object to be scanned on every minor. This is an intentional trade-off between minor GC's doing more work every time, and potentially promoting objects that will then never be GC'd. The intention behind not aging objects is that users of this feature should use a preforking web server, or some other method of pre-warming the oldgen (like Nakayoshi fork)before disabling Majors. That way most objects that are going to be old will have already been promoted. This will interleave major and minor GC collections in exactly the same what that the Ruby GC runs in versions previously to this. This is the default behaviour. * This new method has the following extra semantics: - `GC.config` with no arguments returns a hash of the keys of the currently configured GC - `GC.config` with a key pair (eg. `GC.config(full_mark: true)` sets the matching config key to the corresponding value and returns the entire known config hash, including the new values. If the key does not exist, `nil` is returned * When a minor GC is run, Ruby sets an internal status flag to determine whether the next GC will be a major or a minor. When `full_mark: false` this flag is ignored and every GC will be a minor. This status flag can be accessed at `GC.latest_gc_info(:needs_major_by)`. Any value other than `nil` means that the next collection would have been a major. Thus it's possible to use this feature to check at a predetermined time, whether a major GC is necessary and run one if it is. eg. After a request has finished processing. ```ruby if GC.latest_gc_info(:needs_major_by) GC.start(full_mark: true) end ``` [Feature #20443]
2024-07-12Add gc/gc_impl.h for GC implementation headersPeter Zhu
2024-07-12give up USE_GC_MALLOC_OBJ_INFO_DETAILS卜部昌平
This feature is no longer possible under current design; now that our GC is pluggable, we cannot assume what was achieved by this compiler flag is always possble by the dynamically-loaded GC implementation.
2024-07-10Allow miniruby to load shared GCPeter Zhu
Since dln.c is replaced with dmydln.c for miniruby, we cannot load shared GC for miniruby. This means that many tests do not have the shared GC loaded and many tests fail because of the warning that emits in miniruby. This commit changes shared GC to directly use dlopen for loading the shared GC.
2024-07-05Change external GC to use directory at configurePeter Zhu
This commit changes the external GC API to use `--with-shared-gc=DIR` at configure time with a directory of the external GC and uses `RUBY_GC_LIBRARY` environment variable to load the external GC at runtime.
2024-07-05Revert "Load external GC using command line argument"Peter Zhu
This reverts commit 8ddb1110c283c5cb59b6582383f36fdbcc43ab19.
2024-07-03Remove unused gc_raw_obj_info_basicPeter Zhu
2024-07-03Remove unused obj_info_basicPeter Zhu
2024-07-03Fix ASAN buildsPeter Zhu
2024-07-03Fix compilation with RGENGC_CHECK_MODE=2Peter Zhu
2024-07-03[Feature #20470] Implement support for USE_SHARED_GCPeter Zhu
This commit implements support to load Ruby's current GC as a DSO.
2024-07-03[Feature #20470] Split GC into gc_impl.cPeter Zhu
This commit splits gc.c into two files: - gc.c now only contains code not specific to Ruby GC. This includes code to mark objects (which the GC implementation may choose not to use) and wrappers for internal APIs that the implementation may need to use (e.g. locking the VM). - gc_impl.c now contains the implementation of Ruby's GC. This includes marking, sweeping, compaction, and statistics. Most importantly, gc_impl.c only uses public APIs in Ruby and a limited set of functions exposed in gc.c. This allows us to build gc_impl.c independently of Ruby and plug Ruby's GC into itself.
2024-06-21Load external GC using command line argumentPeter Zhu
This commit changes the external GC to be loaded with the `--gc-library` command line argument instead of the RUBY_GC_LIBRARY_PATH environment variable because @nobu pointed out that loading binaries using environment variables can pose a security risk.
2024-06-20Make ruby_external_gc_init staticPeter Zhu
This function is not used outside of gc.c.
2024-06-13do not call `check_rvalue_consistency` hereKoichi Sasada
in `free` is not valid object and should not call `check_rvalue_consistency`.
2024-06-13avoid recursive calls on `check_rvalue_consistency`Koichi Sasada
`check_rvalue_consistency` uses bitmap and `RVALUE_WB_UNPROTECTED` etc calls `check_rvalue_consistency` again. also `rb_raw_obj_info_common()` is called from `check_rvalue_consistency` so it should not use call `check_rvalue_consistency`.
2024-06-12[Bug #20577] Fix freeing symbols when RUBY_FREE_AT_EXITPeter Zhu
Dynamic symbols point to a fstring. When we free the symbol, we hash the fstring to remove it from the table. However, the fstring could have already been freed, which can cause a crash. This commit changes it to remove the reference to the fstring before freeing the symbol so we can avoid this crash.
2024-06-12Simplify GC bitmap access macrosMatt Valentine-House
Now that we're using the inline predicate functions everywhere, the only remaining use of the RVALUE_?_BITMAP macros is inside their respective inline function, so we can remove them.
2024-06-12Use RVALUE_UNCOLLECTIBLE consistentlyMatt Valentine-House
2024-06-12Use RVALUE_WB_UNPROTECTED consistentlyMatt Valentine-House
2024-06-12Use RVALUE_MARKING consistentlyMatt Valentine-House
2024-06-12Use RVALUE_MARKED consistentlyMatt Valentine-House
2024-06-12Use RVALUE_PINNED consistentlyMatt Valentine-House
2024-06-12Remove unneeded loop through size_poolsMatt Valentine-House
This function loops twice through the array of size pools. Once to set up the pages list, and then again later on in the function to set the allocatable_pages count. We don't do anything with the size pools in between the invocation of these loops that will affect the size pools, so this commit removes the second loop and moves the allocatable_pages count update into the first loop.
2024-06-11Remove use of symbols and arrays when freeing global tablePeter Zhu
This removes the use of symbol and array objects when freeing the global table so we can now free symbols and arrays earlier.
2024-06-02Raise memerror when really memory exhaustedNobuyoshi Nakada
Fix segfault when `RUBY_THREAD_VM_STACK_SIZE` environment variable is very large.
2024-05-04[DOC] Fix the description about the timing finalizers will be calledNobuyoshi Nakada
2024-05-02Fix GC_DEBUGPeter Zhu
2024-05-02Move rvalue_overhead out of RVALUEPeter Zhu
Since we cannot read the rvalue_overhead out of the RVALUE anyways (since it is at the end of the slot), it makes more sense to move it out of the RVALUE.
2024-05-02Fix ruby_mimcalloc size when CALC_EXACT_MALLOC_SIZENobuyoshi Nakada
Should be `sizeof(struct malloc_obj_info) + (num * element)`, not `num * (sizeof(struct malloc_obj_info) + element)`.
2024-04-30Removed unused TICK_TYPE 2Peter Zhu
TICK_TYPE of 2 can never be used because we hard code TICK_TYPE to 1.
2024-04-27use of stdckdint.h卜部昌平
C23 is going to have this header. The industry is already moving towards accepting it; OSes and compilers started to implement theirs. Why not detect its presence and if any, prefer over other ways. See also: - https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf - https://reviews.freebsd.org/D41734 - https://reviews.llvm.org/D157331 - https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8441841a1b985d68245954af1ff023db121b0635