Commit graph

2586 commits

Author SHA1 Message Date
Peter Zhu
c45503f957 Add rb_gc_impl_active_gc_name to gc/gc_impl.h 2024-12-06 10:22:03 -05:00
Peter Zhu
ce1ad1b816 Standardize on the name "modular GC"
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".
2024-12-05 10:33:26 -05:00
Peter Zhu
62b51d9ad7 Use BUILDING_SHARED_GC instead of RB_AMALGAMATED_DEFAULT_GC
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.
2024-12-04 10:25:43 -05:00
Nobuyoshi Nakada
86c01b6aa0 [Bug #20928] Fix build when malloc_usable_size is available
Copy from gc/default/default.c and revert the part of 51bd816517.
2024-12-04 17:49:55 +09:00
Peter Zhu
3a90663776 Move external_gc_loaded_p to gc_functions 2024-12-03 16:16:13 -05:00
John Hawthorn
a505cd32fb RUBY_DEBUG: Verify PC correctness every alloc 2024-11-29 20:37:27 -08:00
卜部昌平
705714be3e prefer ruby_memerror instead
This could be out of GVL
2024-11-29 23:19:05 +09:00
卜部昌平
25ad7e8e6c rb_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.
2024-11-29 23:19:05 +09:00
Matt Valentine-House
f127bcb829 define rb_current_ec_set in all cases 2024-11-25 13:05:23 +00:00
Matt Valentine-House
551be8219e Place all non-default GC API behind USE_SHARED_GC
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 <peter@peterzhu.ca>
2024-11-25 13:05:23 +00:00
Matt Valentine-House
d61933e503 Use extconf to build external GC modules
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
2024-11-25 13:05:23 +00:00
Earlopain
3826019f31 Fix a build failure with musl
```
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.
2024-11-24 17:47:06 +09:00
Kunshan Wang
8ae7c22972 Annotate anonymous mmap
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.
2024-11-21 13:48:05 -05:00
Nobuyoshi Nakada
36d02dc33e
Fix format modifier for size_t
Also fix the message, just `RB_GC_MAX_NAME_LEN` chars long is OK.
2024-11-17 22:45:07 +09:00
Nobuyoshi Nakada
b4d8e90c2a
rb_bug prints a newline after the given message [ci skip] 2024-11-15 14:52:31 +09:00
Matt Valentine-House
6795fc4981 rb_bug if rb_gc_impl_active_gc_name is too long
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.
2024-11-14 10:46:36 +00:00
Matt Valentine-House
ee290c94a3 Include the currently active GC in RUBY_DESCRIPTION
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]
2024-11-14 10:46:36 +00:00
Matt Valentine-House
fa10441981 Expose GC.config[:implementation], to query the currently active GC
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
2024-11-14 10:46:36 +00:00
Peter Zhu
5460d5b119 Move error handling for GC.stat_heap to gc.c 2024-10-23 13:18:09 -04:00
Peter Zhu
d3aaca9785 Make rb_gc_impl_stat_heap return a VALUE instead of size_t 2024-10-23 13:18:09 -04:00
Peter Zhu
c0b50d05c7 Move error handling for GC.stat to gc.c 2024-10-23 13:18:09 -04:00
Peter Zhu
9dea0fae25 Make rb_gc_impl_stat return a VALUE instead of size_t 2024-10-23 13:18:09 -04:00
Peter Zhu
c2af84b244 Move error handling for GC.latest_gc_info to gc.c 2024-10-23 13:18:09 -04:00
Peter Zhu
5131fb5dbe Don't clear out flags in rb_gc_obj_free
If there's a crash after rb_gc_obj_free, it's hard to debug because the
flags have been cleared out already.
2024-10-21 12:48:53 -04:00
Peter Zhu
3ddaf24cd2 Move object processing in Process.warmup to gc.c 2024-10-18 09:06:46 -04:00
Peter Zhu
d641b7d172 Improve RUBY_GC_LIBRARY
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`.
2024-10-11 08:56:36 -04:00
Peter Zhu
3d8fe462df Move return value of rb_gc_impl_config_set to gc.c 2024-10-10 14:34:54 -04:00
Nobuyoshi Nakada
9a90cd2284 Cast via uintptr_t function pointer between object pointer
- ISO C forbids conversion of function pointer to object pointer type
- ISO C forbids conversion of object pointer to function pointer type
2024-10-08 23:29:49 +09:00
Peter Zhu
7cdbf93a89 Improve error message in load_external_gc_func 2024-10-08 09:48:48 -04:00
Peter Zhu
a1c222801d Non-zero exit when error in loading shared GC
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.
2024-10-05 13:58:10 -04:00
Matt Valentine-House
8e7df4b7c6 Rename size_pool -> heap
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
2024-10-03 21:20:09 +01:00
Peter Zhu
bf8a8820ba Deduplicate RGENGC_CHECK_MODE into gc/gc.h 2024-10-02 11:47:45 -04:00
Peter Zhu
30507a4aed Move RUBY_INTERNAL_EVENT_FREEOBJ into GC implementation
Instead of calling rb_gc_event_hook inside of rb_gc_obj_free, it should
be up to the GC implementation to call the event.
2024-09-30 14:23:32 -04:00
Nobuyoshi Nakada
c30a3ed027
Fix the last character index in an assertion
Also, when `RUBY_DEBUG` is enabled, objects allocated in shared-gc
fail at `rb_ractor_confirm_belonging`, so assert it always.
2024-09-30 18:17:42 +09:00
Nobuyoshi Nakada
28a01e306a Ruby exception cannot work here
Just show error messages then ignore the invalid library.
2024-09-30 10:27:30 +09:00
Nobuyoshi Nakada
a0838a3902
Raise fatal error instead of BUG
Failures due to the external setting is not a bug of ruby itself.
2024-09-30 00:20:35 +09:00
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