Commit graph

209 commits

Author SHA1 Message Date
Peter Zhu
7ccad5b9f8 darray.h does not depend on internal/bits.h
darray.h no longer depends on internal/bits.h, so we can remove it.
2024-12-05 14:12:56 -05:00
Matt Valentine-House
d8dbc2dcba [ruby/mmtk] Support setting the mmtk thread count with MMTK_THREADS
e4d6b56824
2024-12-05 16:28:02 +00: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
卜部昌平
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
Nobuyoshi Nakada
9a5f6a45c6 Fix up gc/extconf_base.rb
- Add flags to appropriate variables.

- Use `append_cflags` to append a flag safely, instead of appending
  blindly.
2024-11-26 19:06:21 +09: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
Peter Zhu
770ca58cd3 [ruby/mmtk] Use extconf.rb for external GC compilation
This commit adds extconf.rb for both the default GC and and MMTk to build
the external GC. This allows common.mk to not need to contain any
implementation-specific build configuration.

db6a29b4a9
2024-11-22 09:55:25 +00:00
Peter Zhu
19840dfd71 [ruby/mmtk] [Feature #20860] Implement Mark-Sweep with MMTK
This commit implements the mark-sweep algorithm using MMTk and allows
customizing the plan using MMTK_PLAN.

6fea5e5ffc

Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
2024-11-22 09:55:24 +00:00
Peter Zhu
211aef1bc0 [ruby/mmtk] [Feature #20860] Implement NoGC with MMTk
This commit only supports initializing MMTk with NoGC and object
allocation.

39aa10e537

Co-Authored-By: Kunshan Wang <wks1986@gmail.com>
2024-11-22 09:55:23 +00: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
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
Matt Valentine-House
01e509c45b Remove RGENGC_FORCE_MAJOR_GC flag
[Bug #20762]
2024-11-05 15:36:34 +00:00
kojix2
550ac2f2ed
[DOC] Fix typos 2024-10-31 12:44:50 +09:00
Peter Zhu
990a53825e Remove useless freelist unlock/lock in gc_ref_update 2024-10-25 15:36:35 -04: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
3d8fe462df Move return value of rb_gc_impl_config_set to gc.c 2024-10-10 14:34:54 -04:00
Peter Zhu
2bb7cbff30 Directly call rb_gc_impl_writebarrier_unprotect 2024-10-10 09:41:09 -04:00
Peter Zhu
fc40bd7cbd Directly call rb_gc_impl_copy_finalizer 2024-10-10 09:41:09 -04:00
Peter Zhu
216d087f50 Disable -Wunused-function for shared GC in gc/gc.h
Shared GC might not use the private functions in gc/gc.h, so they will
show up as warnings for unused functions. This commit disables
-Wunused-function for these functions when building as shared GC.
2024-10-07 09:39:07 -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
Matt Valentine-House
b58a364522 Inline eden_heap into size_pool
After the individual tomb_heaps were removed in favour of a global list
of empty pages, the only instance of rb_heap_t left is the eden_heap
within each size pool.

This PR inlines the heap fields directly into rb_size_pool_t to remove
indirection and remove the SIZE_POOL_EDEN_HEAP macro
2024-10-03 21:20:09 +01:00
Matt Valentine-House
b421964b9d Remove unused macros 2024-10-03 12:49:24 +01:00
Matt Valentine-House
d3e2d23c60 Fix compilation when RGENGC_CHECK_MODE >= 4
the mark_function_data callback was moved from the ractor to the VM.
2024-10-02 20:43:35 +01:00
Peter Zhu
bf8a8820ba Deduplicate RGENGC_CHECK_MODE into gc/gc.h 2024-10-02 11:47:45 -04:00
Peter Zhu
3932d8a87a Replace heap_eden_total_slots with objspace_available_slots 2024-10-01 08:48:51 -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
Peter Zhu
2a58092360 Remove unneeded prototype for objspace_available_slots 2024-09-30 12:58:43 -04:00
Peter Zhu
f6dcab5f50 Assert that objects in write barrier are not dead 2024-09-23 10:36:48 -04:00
KJ Tsanaktsidis
02b36f7572 Unpoison page->freelist before trying to assert on it
Otherwise trying to deref the pointer can cause an ASAN crash, even
though the only reason we're dereferencing it is so that we can assert
on it.
2024-09-23 10:11:54 +10:00
Peter Zhu
2882408dcb Remove unneeded function prototype for rb_gc_impl_mark 2024-09-20 10:58:19 -04:00
Peter Zhu
167fba52f0 Remove rb_gc_impl_initial_stress_set 2024-09-19 08:21:10 -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
5de7517bcb Use unsigned long long for marking and sweeping time 2024-09-17 15:22:43 -04:00
Peter Zhu
50d4840bd9 Move desired_compaction_pages_i inside of GC_CAN_COMPILE_COMPACTION
Fixes the following warning on WebAssembly:

    gc/default.c:7306:1: warning: unused function 'desired_compaction_pages_i' [-Wunused-function]
    desired_compaction_pages_i(struct heap_page *page, void *data)
2024-09-16 15:58:27 -04:00
Peter Zhu
50564f8882 ASAN unpoison whole heap page after adding to size pool 2024-09-16 09:27:29 -04:00
Peter Zhu
46ba3752c2 Don't return inside of asan_unpoisoning_object 2024-09-16 09:27:29 -04:00
Peter Zhu
c5a782dfb0 Replace with asan_unpoisoning_object 2024-09-16 09:27:29 -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