Граф коммитов

2501 Коммитов

Автор SHA1 Сообщение Дата
Peter Zhu 90763e04ba Load external GC using command line argument
This commit changes the external GC to be loaded with the `--gc-library`
command line argument instead of the RUBY_GC_LIBRARY_PATH environment
variable because @nobu pointed out that loading binaries using environment
variables can pose a security risk.
2024-06-21 11:49:01 -04:00
Peter Zhu f5fd87b695 Make ruby_external_gc_init static
This function is not used outside of gc.c.
2024-06-20 11:34:52 -04:00
Koichi Sasada 513520a173 do not call `check_rvalue_consistency` here
in `free` is not valid object and should not call
`check_rvalue_consistency`.
2024-06-13 17:26:44 +09:00
Koichi Sasada e4385baaa2 avoid recursive calls on `check_rvalue_consistency`
`check_rvalue_consistency` uses bitmap and `RVALUE_WB_UNPROTECTED`
etc calls `check_rvalue_consistency` again.

also `rb_raw_obj_info_common()` is called from `check_rvalue_consistency`
so it should not use call `check_rvalue_consistency`.
2024-06-13 13:14:44 +09:00
Peter Zhu 7c46aa5ed4 [Bug #20577] Fix freeing symbols when RUBY_FREE_AT_EXIT
Dynamic symbols point to a fstring. When we free the symbol, we hash the
fstring to remove it from the table. However, the fstring could have
already been freed, which can cause a crash.

This commit changes it to remove the reference to the fstring before
freeing the symbol so we can avoid this crash.
2024-06-12 16:12:46 -04:00
Matt Valentine-House 96974c6c0d Simplify GC bitmap access macros
Now that we're using the inline predicate functions everywhere, the only
remaining use of the RVALUE_?_BITMAP macros is inside their respective
inline function, so we can remove them.
2024-06-12 17:09:07 +01:00
Matt Valentine-House 5cf5370116 Use RVALUE_UNCOLLECTIBLE consistently 2024-06-12 17:09:07 +01:00
Matt Valentine-House 4c38b4f70f Use RVALUE_WB_UNPROTECTED consistently 2024-06-12 17:09:07 +01:00
Matt Valentine-House cc700c3d8f Use RVALUE_MARKING consistently 2024-06-12 17:09:07 +01:00
Matt Valentine-House e006a58f07 Use RVALUE_MARKED consistently 2024-06-12 17:09:07 +01:00
Matt Valentine-House bb663fe0b2 Use RVALUE_PINNED consistently 2024-06-12 17:09:07 +01:00
Matt Valentine-House 1db19a2dbd Remove unneeded loop through size_pools
This function loops twice through the array of size pools. Once to set
up the pages list, and then again later on in the function to set the
allocatable_pages count.

We don't do anything with the size pools in between the invocation of
these loops that will affect the size pools, so this commit removes the
second loop and moves the allocatable_pages count update into the first
loop.
2024-06-12 13:54:20 +01:00
Peter Zhu 32683aa18d Remove use of symbols and arrays when freeing global table
This removes the use of symbol and array objects when freeing the global
table so we can now free symbols and arrays earlier.
2024-06-11 10:33:51 -04:00
Nobuyoshi Nakada a7d0a91009 Raise memerror when really memory exhausted
Fix segfault when `RUBY_THREAD_VM_STACK_SIZE` environment variable is
very large.
2024-06-02 09:39:20 +09:00
Nobuyoshi Nakada b6625d38d8
[DOC] Fix the description about the timing finalizers will be called 2024-05-04 01:34:35 +09:00
Peter Zhu b5cefa79dd Fix GC_DEBUG 2024-05-02 17:32:43 -04:00
Peter Zhu 6d605f1e50 Move rvalue_overhead out of RVALUE
Since we cannot read the rvalue_overhead out of the RVALUE anyways (since
it is at the end of the slot), it makes more sense to move it out of
the RVALUE.
2024-05-02 17:32:43 -04:00
Nobuyoshi Nakada e9e41ad6b0 Fix ruby_mimcalloc size when CALC_EXACT_MALLOC_SIZE
Should be `sizeof(struct malloc_obj_info) + (num * element)`, not
`num * (sizeof(struct malloc_obj_info) + element)`.
2024-05-02 00:03:00 +09:00
Peter Zhu bd419a6578 Removed unused TICK_TYPE 2
TICK_TYPE of 2 can never be used because we hard code TICK_TYPE to 1.
2024-04-30 13:04:15 -04:00
卜部昌平 bb5a538207 use of stdckdint.h
C23 is going to have this header.  The industry is already moving
towards accepting it; OSes and compilers started to implement theirs.

Why not detect its presence and if any, prefer over other ways.

See also:

- https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf
- https://reviews.freebsd.org/D41734
- https://reviews.llvm.org/D157331
- https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8441841a1b985d68245954af1ff023db121b0635
2024-04-27 21:55:28 +09:00
Peter Zhu f64c97418b Allow RUBY_GC_LIBRARY_PATH to be set in miniruby
miniruby is used by tool/runruby.rb, so we need to ensure we don't rb_bug
when RUBY_GC_LIBRARY_PATH is set so we can run tests using the make
commands. This commit changes it to warn instead.
2024-04-26 17:02:08 -04:00
Peter Zhu 41e17f5624 Fix compiler warning for ruby_external_gc_init
Fixes:

    warning: old-style function definition [-Wold-style-definition]
2024-04-26 16:58:20 -04:00
Peter Zhu 353cba4955 Use fprintf for error message when loading external GC
The error message is often long, so using a small buffer could cause it
to be truncated. rb_bug also has a 256 byte message buffer, so it could
also be truncated.
2024-04-26 11:43:14 -04:00
Peter Zhu f248e1008a Embed rb_gc_function_map_t in rb_vm_t
Avoids a pointer indirection and memory allocation.
2024-04-25 09:25:33 -04:00
Peter Zhu 214811974b Add ruby_mimcalloc
Many places call ruby_mimmalloc then MEMZERO. This can be reduced by
using ruby_mimcalloc instead.
2024-04-24 15:30:43 -04:00
Peter Zhu 057b69cfdf Pass string error buffer into dln_open
On Windows, the error exists on the stack so we should pass an error
buffer from the caller.
2024-04-24 13:10:06 -04:00
Peter Zhu 480287d140 Add macro load_external_gc_func for loading functions from external GC 2024-04-24 10:31:03 -04:00
Peter Zhu b9109b270d Get error from dln_open when USE_SHARED_GC
Before, if dln_open failed to open RUBY_GC_LIBRARY_PATH, it would segfault
because it would try to raise an error, which cannot happen because the
GC has not been initialized yet.

This commit changes dln_open to return the error that occurred so the
caller can handle the error.
2024-04-23 15:29:42 -04:00
Matt Valentine-House 4218e6bbd5 Remove unused define popcount_bits 2024-04-19 11:39:20 +01:00
Aaron Patterson 147ca9585e Implement equality for CI comparison when CC searching
When we're searching for CCs, compare the argc and flags for CI rather
than comparing pointers.  This means we don't need to store a reference
to the CI, and it also naturally "de-duplicates" CC objects.

We can observe the effect with the following code:

```ruby
require "objspace"

hash = {}

p ObjectSpace.memsize_of(Hash)

eval ("a".."zzz").map { |key|
  "hash.merge(:#{key} => 1)"
}.join("; ")

p ObjectSpace.memsize_of(Hash)
```

On master:

```
$ ruby -v test.rb
ruby 3.4.0dev (2024-04-15T16:21:41Z master d019b3baec) [arm64-darwin23]
test.rb:3: warning: assigned but unused variable - hash
3424
527736
```

On this branch:

```
$ make runruby
compiling vm.c
linking miniruby
builtin_binary.inc updated
compiling builtin.c
linking static-library libruby.3.4-static.a
ln -sf ../../rbconfig.rb .ext/arm64-darwin23/rbconfig.rb
linking ruby
ld: warning: ignoring duplicate libraries: '-ldl', '-lobjc', '-lpthread'
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems  ./test.rb
2240
2368
```

Co-authored-by: John Hawthorn <jhawthorn@github.com>
2024-04-18 09:06:33 -07:00
Peter Zhu 81240493a3 Remove unused rb_size_pool_slot_size 2024-04-18 10:19:42 -04:00
Matt Valentine-House 0727d32b56 Don't verify during gc_enter when gc is disabled.
RGENGC_CHECK_MODE >=3 fails with an incinsistency in the old object
count during ec_finalization.

This is due to inconsistency introduced to the object graph using T_DATA
finalizers.

This is explained in commit 79df14c04b,
which disabled gc during finalization to work around this.

```
    /* prohibit GC because force T_DATA finalizers can break an object graph consistency */
    dont_gc_on()
```

This object graph inconsistency also seems to break RGENGC_CHECK_MODE >=
3, when it attempt to verify the object age relationships during
finalization at VM shutdown (gc_enter is called during finalization).

This commit stops the internal consistency check during gc_enter only
when RGENGC_CHECK_MODE >= 3 and when gc is disabled.

This fixes `make btest` with `-DRGENGC_CHECK_MODE=3`
2024-04-17 23:29:23 +01:00
Matt Valentine-House 3a4035a790 Reduce the number of references to need_major_gc 2024-04-17 21:16:47 +01:00
Peter Zhu 814dedcee2 Remove unused ruby_sighandler_t 2024-04-17 14:01:59 -04:00
Peter Zhu ee6e591b6a Use unsigned long long for object ID
Since unsigned long long are minumum 64 bits, we have at least 10**17
object IDs available, so there is no chance it will overflow.
2024-04-17 13:33:17 -04:00
Peter Zhu 209e2f277e Don't allow T_NIL in gc_is_moveable_obj
gc_is_moveable_obj is only given GC managed objects, and T_NIL cannot be
a GC managed type.
2024-04-17 09:49:11 -04:00
Matt Valentine-House 2470565993 Inline single use variables 2024-04-17 13:31:45 +01:00
Peter Zhu d6debba817 Don't check for dynamic symbol in gc_is_moveable_obj
All GC managed symbols are dynamic symbols so we don't need to check it.
2024-04-16 14:34:52 -04:00
Peter Zhu e5df8897fe Don't check for thread in gc_sweep_page
We should always have a thread when we sweep so we don't need to check
that it exists.
2024-04-16 13:24:46 -04:00
Matt Valentine-House 065710c0f5 Initialize external GC Library
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
2024-04-15 19:50:47 +01:00
Peter Zhu 9bab179ca3 Don't treat flonum specially in object ID
flonum is just a special constant, so we don't need to treat it in any
special way.
2024-04-12 11:27:08 -04:00
Peter Zhu edec690e03 Refactor how object IDs work for special consts
We don't need to treat static symbols in any special way since they
can't be confused with other special consts or GC managed objects.
2024-04-12 11:27:08 -04:00
Peter Zhu f2369de2a4 Remove redundant cast
ptr is already of the VALUE type, so we don't need to cast it.
2024-04-11 12:08:03 -04:00
Peter Zhu f389a211b5 Fix indentation in switch statement in gc.c 2024-04-10 16:32:49 -04:00
Nobuyoshi Nakada b006919200 `objspace_each_pages` is also only used if GC compression is possible 2024-04-06 18:51:24 +09:00
Peter Zhu 1f84e1099e [DOC] Add nodoc for GC.remove_stress_to_class
This method is only available when compiled with GC_DEBUG_STRESS_TO_CLASS
is enabled, so it's not available on release builds of Ruby.
2024-04-05 13:46:47 -04:00
Peter Zhu 46ebc48e62 [DOC] Add nodoc for GC.add_stress_to_class
This method is only available when compiled with GC_DEBUG_STRESS_TO_CLASS
is enabled, so it's not available on release builds of Ruby.
2024-04-05 13:45:12 -04:00
Peter Zhu dbe8886f4d Remove deprecated function rb_gc_force_recycle
This function has been deprecated since Ruby 3.1, so we should remove it
for Ruby 3.4.
2024-04-05 11:39:54 -04:00
Matt Valentine-House ef19234b10 Merge rb_objspace_alloc and Init_heap.
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
2024-04-04 15:00:57 +01: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