Commit graph

22 commits

Author SHA1 Message Date
Peter Zhu
de45755de8 Use an identity hash instead of array for stress_to_class 2025-01-29 13:22:04 -05:00
Peter Zhu
5e644e80e9 Fix GC.add_stress_to_class and GC.remove_stress_to_class
These methods were accidentally removed in [Feature #20470]. This commit
adds them back.
2025-01-29 13:22:04 -05:00
Nobuyoshi Nakada
be44d5677d
Suppress unused-value warnings 2025-01-29 16:57:16 +09:00
Peter Zhu
cb9aeb283b Fix gc_update_references_weak_table_i for ASAN
If the object is a T_MOVED, then it is poisoned in ASAN, so we need to
unpoison it before checking the type.
2025-01-27 13:26:26 -05:00
Peter Zhu
98b36f6f36 Use rb_gc_vm_weak_table_foreach for reference updating
We can use rb_gc_vm_weak_table_foreach for reference updating of weak tables
in the default GC.
2025-01-27 10:28:36 -05:00
Peter Zhu
89240eb2fb Add generic ivar reference updating step
Previously, generic ivars worked differently than the other global tables
during compaction. The other global tables had their references updated
through iteration during rb_gc_update_vm_references. Generic ivars updated
the keys when the object moved and updated the values while reference
updating the object. This is inefficient as this required one lookup for
every moved object and one lookup for every object with generic ivars.

Instead, this commit changes it to iterate over the generic ivar table to
update both the keys and values.
2025-01-22 08:54:52 -05:00
Jean Boussier
22e9fa81ca gc/default/default.c: don't call malloc_usable_size when hint is present
Depending on the allocator, `malloc_usable_size` may be very cheap or quite
expensive. On `macOS` for instance, it's about as expensive as `malloc`.

In many case we call `objspace_malloc_size` with as size we initially
requested as `hint`. The real usable size may be a few bytes bigger,
but since we only use that data to feed GC heuristics, I don't think
it's very important to be perfectly accurate.

It would make sense to call `malloc_usable_size` after growing a String
or Array to use the extra capacity, but here we don't do that, so
the call isn't worth its cost.
2025-01-05 17:04:54 +01:00
Peter Zhu
b8c4af24f9 Use rb_darray_insert_without_gc for heap_pages darray
rb_darray_insert could trigger a GC, which would cause problems if it
freed pages while a new page was being inserted.

For example, the following script fails:

    GC.stress = true
    GC.auto_compact = :empty

    10.times do
      GC.verify_compaction_references(expand_heap: true, toward: :empty)
    end

It errors out with:

    'GC.verify_compaction_references': malloc: possible integer overflow (8*18446744073709551603) (ArgumentError)
2025-01-02 11:03:04 -05:00
Peter Zhu
f9cd9a1b55 Revert "Remove with_gc functions in darray"
This reverts commit 24a7407960.
2025-01-02 11:03:04 -05:00
Peter Zhu
a58675386c Prefix asan_poison_object with rb 2024-12-19 09:14:34 -05:00
Peter Zhu
fcd44eee09 Fix compaction in ASAN with RGENGC_CHECK_MODE enabled 2024-12-19 09:14:34 -05:00
Peter Zhu
16750a47d0 Don't calculate the aligned slot when unlocking page
If we try to use GET_PAGE_HEADER, it can trigger the read barrier. If we
try to align on the slot then we end up unlocking the heap page of a
lower memory address.
2024-12-19 09:14:34 -05:00
Peter Zhu
f02e31294c Don't unpoison a NULL object 2024-12-19 09:14:34 -05:00
Peter Zhu
a126560196 Unpoison memory before accessing next element of freelist 2024-12-19 09:14:34 -05:00
Peter Zhu
d28368d27f Move special constant check in rb_gc_location to gc.c 2024-12-16 13:32:35 -05:00
John Hawthorn
36f49eb2b4 Fix compilation with MALLOC_ALLOCATED_SIZE
Previously compilation failed with -DMALLOC_ALLOCATED_SIZE=1

Co-authored-by: Matthew Draper <matthew@trebex.net>
2024-12-11 16:58:35 -08:00
Nobuyoshi Nakada
f243733564
[Bug #20941] Bail out when recursing no memory 2024-12-11 16:12:04 +09:00
Peter Zhu
eedb30d385 Use rb_gc_enable/rb_gc_disable_no_rest instead of ruby_disable_gc
We should use the rb_gc_enable/rb_gc_disable_no_rest APIs instead of
directly setting the ruby_disable_gc variable.
2024-12-05 16:21:37 -05:00
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
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
卜部昌平
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
d61933e503 Use extconf to build external GC modules
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
2024-11-25 13:05:23 +00:00