Commit graph

2550 commits

Author SHA1 Message Date
Peter Zhu
167fba52f0 Remove rb_gc_impl_initial_stress_set 2024-09-19 08:21:10 -04:00
Peter Zhu
f8e1c93fe1 Move more of GC.latest_gc_info into Ruby 2024-09-18 12:58:05 -04:00
Peter Zhu
5df5eba465 Change rb_gc_impl_get_measure_total_time to return a bool 2024-09-18 10:18:47 -04:00
Peter Zhu
5307c65c76 Make rb_gc_impl_set_measure_total_time return void 2024-09-17 16:35:52 -04:00
Peter Zhu
dc61c7fc7d Rename rb_gc_impl_get_profile_total_time to rb_gc_impl_get_total_time 2024-09-17 15:22:43 -04:00
Peter Zhu
2af080bd30 Change rb_gc_impl_get_profile_total_time to return unsigned long long 2024-09-17 15:22:43 -04:00
Peter Zhu
0fc8422a05 Move checks for heap traversal to rb_gc_mark_weak
If we are during heap traversal, we don't want to call rb_gc_impl_mark_weak.
This commit moves that check from rb_gc_impl_mark_weak to rb_gc_mark_weak.
2024-09-12 16:03:28 -04:00
Peter Zhu
92b7b78e06 Assert that we are during GC when marking 2024-09-12 16:03:28 -04:00
Peter Zhu
661f64e876 Add variable objspace in RB_GC_MARK_OR_TRAVERSE 2024-09-12 16:03:28 -04:00
Peter Zhu
606db2c423 Move special const checks to rb_gc_mark_weak 2024-09-12 16:03:28 -04:00
Nobuyoshi Nakada
a2ae7450d7
Suppress discards qualifiers warning with ASN 2024-09-09 16:25:43 +09:00
Jonathan Calvert
c1a510a8df
[Bug #20718] Free non-RTypedData objects
Allow objects that are not of type `RTypedData` to use the default
free function, as `RTYPEDDATA_EMBEDDED_P` can return a false positive
when casting non-`RTypedData` objects.
2024-09-07 12:19:47 +09:00
Peter Zhu
ef42e04a1a Don't traverse garbage objects in heap traversal
The object could be garbage (e.g. T_NONE, T_MOVED, or T_ZOMBIE) so we
don't want to traverse those.
2024-09-03 13:44:09 -04:00
Peter Zhu
3c63a01295 Move responsibility of heap walking into Ruby
This commit removes the need for the GC implementation to implement heap
walking and instead Ruby will implement it.
2024-09-03 10:05:38 -04:00
Peter Zhu
89bbb9a888 Fix call to each_location_ptr for ASAN 2024-08-30 10:45:25 -04:00
Peter Zhu
ca7b3d467d Combine gc_mark_locations and each_stack_location
Also renames the new function each_location_ptr to be consistent with
each_location.
2024-08-30 10:03:17 -04:00
Peter Zhu
e3f00df227 Drop support for Motorola 68000
The last Motorla 68000 architecture CPU was released 1994, so we can
probably drop support for it.
2024-08-30 10:03:17 -04:00
Peter Zhu
22d9260f05 Remove unused ec argument in each_stack_location 2024-08-29 16:03:48 -04:00
Peter Zhu
1f114464fc Change each_stack_location to accept data instead of objspace
The callers were abusing each_stack_location and passing data into the objspace
argument.
2024-08-29 14:37:01 -04:00
Peter Zhu
c162da69e7 Change each_location to accept data instead of objspace
The callers were abusing each_location and passing data into the objspace
argument.
2024-08-29 14:37:01 -04:00
Peter Zhu
6b08a50a62 Move checks for special const for marking
This commit moves checks to RB_SPECIAL_CONST_P out of the GC implmentation
and into gc.c.
2024-08-29 09:11:40 -04:00
Peter Zhu
ddd2b17845 Move marking code together in gc.c 2024-08-29 09:11:40 -04:00
Peter Zhu
165635049a Don't use gc_impl.h inside of gc/gc.h
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.
2024-08-22 13:50:17 -04:00
Peter Zhu
8312c5be74 Fix GC_ASSERT for gc.c and gc/default.c
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.
2024-08-15 10:38:24 -04:00
Peter Zhu
264175dbb9 [DOC] Update comment about how object ID is calculated
The object ID no longer treats symbols in a special way so we can simplify
the comment about how it is calculated.
2024-08-14 10:51:02 -04:00
Peter Zhu
b80b839926 Don't set stack end in rb_gc_mark_roots
We don't need to set the stack end in rb_gc_mark_roots because it is
already set in mark_current_machine_context.
2024-08-13 15:53:14 -04:00
Peter Zhu
c91ec7ba1e Remove rb_gc_impl_objspace_mark
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.
2024-08-09 10:27:40 -04:00
Peter Zhu
0bff07644b
Make YJIT a GC root rather than an object (#11343)
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.
2024-08-08 12:19:35 -04:00
Alan Wu
a06cfa7e89 Fix a -Wmaybe-uninitialized
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-26 11:44:34 -04:00
Alan Wu
0ada02abe2 Put the default GC implementation back into gc.o
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-26 11:44:34 -04:00
Alan Wu
5617fec1f8 newobj_of(): Use parameter instead of GET_RACTOR()
No point repeating the work callers to this function already do.
2024-07-22 20:00:59 -04:00
Peter Zhu
5e3b8010ed Add newline when printing dlopen error message 2024-07-22 10:25:44 -04:00
Peter Zhu
51505f70e3 Move frozen check out of rb_gc_impl_undefine_finalizer 2024-07-19 08:53:32 -04:00
Peter Zhu
4b05d2dbb0 Make rb_gc_impl_undefine_finalizer return void 2024-07-19 08:53:32 -04:00
Peter Zhu
e8aa9daa5b Move return value of rb_define_finalizer out
Moves return value logic of rb_define_finalizer out from
rb_gc_impl_define_finalizer.
2024-07-19 08:53:32 -04:00
Peter Zhu
0936e3d545 Make define_final call rb_define_finalizer 2024-07-19 08:53:32 -04:00
Peter Zhu
461a7b8316 Add gc/gc.h for functions in gc.c and used by GC implementations 2024-07-15 08:57:14 -04:00
Matt Valentine-House
f543c68e1c Provide GC.config to disable major GC collections
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-12 14:43:33 +01:00
Peter Zhu
00d0ddd48a Add gc/gc_impl.h for GC implementation headers 2024-07-12 08:41:33 -04:00
卜部昌平
fa6bf1da57 give 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-12 10:21:07 +09:00
Peter Zhu
64988e66d7 Allow miniruby to load shared GC
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-10 14:28:10 -04:00
Peter Zhu
e2ceded2c6 Change external GC to use directory at configure
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-05 14:05:58 -04:00
Peter Zhu
8fd2df529b Revert "Load external GC using command line argument"
This reverts commit 8ddb1110c2.
2024-07-05 14:05:58 -04:00
Peter Zhu
6ac05ddb8a Remove unused gc_raw_obj_info_basic 2024-07-03 14:45:01 -04:00
Peter Zhu
05f840d641 Remove unused obj_info_basic 2024-07-03 14:44:31 -04:00
Peter Zhu
f88841b8f3 Fix ASAN builds 2024-07-03 14:40:10 -04:00
Peter Zhu
cbc40aca3a Fix compilation with RGENGC_CHECK_MODE=2 2024-07-03 11:48:12 -04:00
Peter Zhu
ae8ef06580 [Feature #20470] Implement support for USE_SHARED_GC
This commit implements support to load Ruby's current GC as a DSO.
2024-07-03 09:03:40 -04:00
Peter Zhu
51bd816517 [Feature #20470] Split GC into gc_impl.c
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-07-03 09:03:40 -04:00
Peter Zhu
90763e04ba Load external GC using command line argument
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-21 11:49:01 -04:00