28 Commits

Author SHA1 Message Date
Peter Zhu
d67d1530a8 Create rb_darray_realloc_mul_add 2025-01-02 11:03:04 -05:00
Peter Zhu
bd70534e97 Change rb_darray_realloc_mul_add_without_gc to check for overflow 2025-01-02 11:03:04 -05:00
Peter Zhu
e596516182 Create rb_darray_calloc_mul_add 2025-01-02 11:03:04 -05:00
Peter Zhu
2e3b2d5eb2 Change rb_darray_calloc_mul_add_without_gc to check for overflow 2025-01-02 11:03:04 -05: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 24a740796050b72aa2d35339ba2a317d4eda7b75.
2025-01-02 11:03:04 -05:00
Peter Zhu
07e89bde46 Fix MEMMOVE in rb_darray_insert
Ruby's MEMMOVE takes in the element data type for the third argument, not
the size of the element. What this did was do sizeof(sizeof( ... )) which
always returned sizeof(size_t).
2024-12-24 09:40:12 -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
b66d6e48c8 Switch sorted list of pages in the GC to a darray 2024-09-09 10:15:21 -04:00
Peter Zhu
6bf519ba81 Remove unneeded rb_darray_append_impl 2024-09-06 09:56:59 -04:00
Peter Zhu
733d50f0a5 Remove dependency on gc.h for darray.h 2024-04-15 13:44:31 -04:00
Peter Zhu
24a7407960 Remove with_gc functions in darray
We can wrap in DURING_GC_COULD_MALLOC_REGION instead.
2024-04-02 13:26:24 -04:00
Peter Zhu
11ffee88b5 Replace assert with RUBY_ASSERT in darray.h
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
2024-02-12 15:07:47 -05:00
Peter Zhu
bfb395c620 Implement weak references in the GC
[Feature #19783]

This commit adds support for weak references in the GC through the
function `rb_gc_mark_weak`. Unlike strong references, weak references
does not mark the object, but rather lets the GC know that an object
refers to another one. If the child object is freed, the pointer from
the parent object is overwritten with `Qundef`.

Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-08-25 09:01:21 -04:00
Peter Zhu
633243958c Add _without_gc functions to darray
These functions manipulate darray without the possibility of triggering
GC, which is used for places that cannot trigger GC. These functions
crash when the allocation fails.
2023-08-25 09:01:21 -04:00
Peter Zhu
11deab7906 Remove unused code in darray.h 2023-07-21 15:44:24 -04:00
John Bampton
c43fbe4ebd
Fix spelling (#7405) 2023-02-28 10:05:30 -08:00
Peter Zhu
fe7c02c744 Remove _with_gc functions in darray
darray was used in YJIT which required the functions to not trigger GC.
YJIT has now moved to Rust and does not use darray anymore, so we can
remove the functions that don't trigger GC and only keep the ones that
trigger GC.
2022-05-03 09:07:39 -04:00
Peter Zhu
969ad5802d Change feature_index from fake Array to darray
Using a fake (malloc) RArray is not friendly for the garbage
collector. Fake RArray does not have a heap page, so it causes Variable
Width Allocation to crash when we try to implement it on Arrays.

This commit changes feature_index from a RArray to a darray.
2022-02-16 09:50:29 -05:00
Peter Zhu
71afa8164d Change darray size to size_t and add functions that use GC malloc
Changes size and capacity of darray to size_t to support more
elements.

Adds functions to darray that use GC allocation functions.
2022-02-16 09:50:29 -05:00
Maxime Chevalier-Boisvert
11599e5e1e Add rb_darray_clear() for Kevin. Fix some warnings. 2021-10-20 18:19:40 -04:00
Maxime Chevalier-Boisvert
0cc73ca2a9 Malloc branch entries (#112)
* Malloc branch entries

* Add ASM comment for stack overflow check

* WIP

* Fix branch GC code. Add rb_darray_remove_unordered().

* Fix block end_pos after branch rewriting. Remove dst_patched bits.
2021-10-20 18:19:33 -04:00
Maxime Chevalier-Boisvert
fe3bd57007 Remove trailing whitespaces 2021-10-20 18:19:31 -04:00
Alan Wu
7de8ce4efc YJIT: Use 2D array to group block versions
For deferred compilation, we sometimes want to care about the order of
the block versions. Use an array instead of a linked list to do that.
2021-10-20 18:19:31 -04:00
Alan Wu
9ce2771697 darray: fix strict aliasing issue 2021-10-20 18:19:30 -04:00
Alan Wu
2240932b64 Add rb_darray_make 2021-10-20 18:19:30 -04:00
Alan Wu
47e05fca10 darray: fix buffer size calculation for element with strict alignment 2021-10-20 18:19:30 -04:00
Alan Wu
c02517bacb Tie lifetime of uJIT blocks to iseqs
* Tie lifetime of uJIT blocks to iseqs

   Blocks weren't being freed when iseqs are collected.

* Add rb_dary. Use it for method dependency table

* Keep track of blocks per iseq

  Remove global version_tbl

* Block version bookkeeping fix

* dary -> darray

* free ujit_blocks

* comment about size of ujit_blocks
2021-10-20 18:19:29 -04:00