Commit graph

209 commits

Author SHA1 Message Date
Peter Zhu
7b6e07ea93 Add rb_gc_object_metadata API
This function replaces the internal rb_obj_gc_flags API. rb_gc_object_metadata
returns an array of name and value pairs, with the last element having
0 for the name.
2025-02-19 09:47:28 -05:00
Yuta Saito
eac35edfd1 [wasm] Stop using mprotect(PROT_NONE) on WASI
we had been using a stub weak definition of `mprotect` in wasm/missing.c
so far, but wasi-sdk 23 added mprotect emulation to wasi-libc[^1], so the
emulation is now linked instead. However, the emulation doesn't support
PROT_NONE and fails with ENOSYS, so we need to avoid calling mprotect
completely on WASI.

[^1]: 7528b13170
2025-02-19 11:46:12 +09:00
Peter Zhu
b74077c19e [ruby/mmtk] Set Immix as the default plan
e52b973611
2025-02-10 20:37:10 +00:00
Daisuke Aritomo
c7e35e5534 gc.c: Remove no-op code
In this context, `vm_locked` is a argument variable, and is not used
later in the function.
2025-02-10 14:21:10 -05:00
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
feec48ae2b Fix rb_gc_vm_weak_table_foreach compatibility for MMTK 2025-01-27 10:28:36 -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
9e5ff79c5b Optionally traverse non-weak references in rb_gc_vm_weak_table_foreach
For moving garbage collectors, we may want to combine liveliness checking
with reference updating for performance. This commit allows for non-weak
references to be passed into the callback function when weak_only is false.
2025-01-27 10:28:36 -05:00
Peter Zhu
4df16051be [ruby/mmtk] Remove unused lazy_static dependency
f47a1e2d17
2025-01-22 16:07:04 +00: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
Peter Zhu
be66448311 [ruby/mmtk] Bump mmtk-core
Fixes a bug where there is an infinite loop when MMTK_HEAP_MIN is small.

12c7ede20b
2025-01-21 17:02:18 +00:00
Peter Zhu
5fceba6614 [ruby/mmtk] Add mmtk_heap_max to GC.config
6a78ffaf16
2025-01-17 15:44:24 +00:00
Peter Zhu
179899c616 [ruby/mmtk] Add mmtk_heap_min to GC.config
5bbac70c69
2025-01-16 21:40:31 +00:00
Peter Zhu
d1a30359b1 [ruby/mmtk] Bump mmtk-core
52b857ea04
2025-01-16 16:20:05 +00:00
Peter Zhu
2538f4d521 [ruby/mmtk] Add mmtk_heap_mode to GC.config
810f897603
2025-01-16 16:20:04 +00:00
Peter Zhu
ab1565ebe3 [ruby/mmtk] Add mmtk_plan to GC.config
67da9ea5b8
2025-01-15 18:08:03 +00:00
Peter Zhu
e02c7491e9 [ruby/mmtk] Fix mmtk.h
dbb4036be9
2025-01-15 17:55:32 +00:00
Peter Zhu
cb6476a34e [ruby/mmtk] Bump mmtk-core
https://github.com/mmtk/mmtk-core/pull/1261 fixes an issue where the following
script causes a Rust panic:

    GC.disable
    10_000.times { Object.new }
    puts GC.stat

6191ee994a
2025-01-15 15:13:36 +00:00
Peter Zhu
f1e32914eb [ruby/mmtk] Add mmtk_worker_count to GC.config
836a9059cb
2025-01-14 20:59:39 +00:00
Peter Zhu
f5fa1ee5f6 [ruby/mmtk] Exit with error message if MMTK_PLAN is invalid
79ce2008a3
2025-01-14 17:17:44 +00:00
Peter Zhu
2bcbc80fa2 [ruby/mmtk] Exit with error message if MMTK_HEAP_MODE is invalid
c8b1f4c156
2025-01-14 17:07:21 +00:00
Nobuyoshi Nakada
1758137ead Simplify gc/mmtk/extconf.rb
- Split static recipes to depend file.
- Modify makefile configurations in the block to `create_makefile`.
- Expand rust sources in extconf.rb instead of GNU make extension.

TODO: pass `CARGO_TARGET_DIR` without shell syntax.
2025-01-14 10:21:57 -05:00
Peter Zhu
ed4b1f9c1a [ruby/mmtk] Exit with error message if MMTK_HEAP_MAX is invalid
4a24d55d91
2025-01-13 20:08:20 +00:00
Peter Zhu
f821a127ea [ruby/mmtk] Exit with error message if MMTK_HEAP_MIN is invalid
1d2f7b9cfc
2025-01-13 20:08:20 +00:00
Peter Zhu
3b9b41d046 [ruby/mmtk] Exit with error message if MMTK_THREADS is invalid
5c5c454f65
2025-01-13 20:08:19 +00:00
Peter Zhu
85a25116cc [ruby/mmtk] Enable immix_non_moving feature
63ab563e04
2025-01-13 16:44:36 +00:00
Peter Zhu
f76d40789d [ruby/mmtk] Enable UNIQUE_OBJECT_ENQUEUING in MMTk
UNIQUE_OBJECT_ENQUEUING guarantees that object marking is atomic so that
an object cannot be marked more than once.

2f97fd8207
2025-01-09 19:08:49 +00:00
Peter Zhu
4ce82f1c33 [ruby/mmtk] Bump mmtk-core to
68bf1b6382

ba1ec69bf6
2025-01-09 19:08:49 +00:00
Peter Zhu
2da91080d3 [ruby/mmtk] Fix libmmtk_ruby.a building in extconf.rb
Since libmmtk_ruby.a was a PHONY target, it caused the shared object to
not be rebuilt even though libmmtk_ruby.a was updated.

076f0a97a6
2025-01-09 17:34:02 +00:00
Peter Zhu
4a78d74039 [ruby/mmtk] Remove unused Ruby SHA reference in Cargo.toml
02b9439ea6
2025-01-07 22:17:31 +00:00
Peter Zhu
2b713f08a3 [ruby/mmtk] Bump mmtk-core version
0de72c03ba
2025-01-07 15:37:41 +00: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
84eff67644 [DOC] Add gc/README.md 2024-12-19 13:20:31 -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
de7feb0538 [ruby/mmtk] Also remove .rustc_info.json in clean-mmtk target
4b67c8b4da
2024-12-09 19:11:49 +00:00
Peter Zhu
ea7e34fd5d [ruby/mmtk] Add target clean-mmtk to clean Rust debug and release directories
1f71cb873c
2024-12-09 18:37:07 +00:00
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
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