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

2520 Коммитов

Автор SHA1 Сообщение Дата
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
Peter Zhu fa0a62413a Don't check for dynamic symbol when reference updating
All symbols in the GC are dynamic symbols, so we don't need to check it.
2024-03-28 11:54:16 -04:00
KJ Tsanaktsidis dc9d2455b6 Add a missing asan_unpoisoning_p in gc_set_candidate_object_i
It walks the heap, and checks for T_NONE and T_ZOMBIE objects, so it
needs to unpoison these slots before accessing them when ASAN is
enabled.
2024-03-28 09:49:10 +11:00
Peter Zhu c50b6425b4 Remove st_lookup when updating object ID 2024-03-27 11:41:08 -04:00
Peter Zhu 4566843b3e Check FL_SEEN_OBJ_ID before looking up in table
This is an optimization for compaction so that we only lookup in the
obj_to_id_tbl table only when FL_SEEN_OBJ_ID is set.
2024-03-27 11:41:08 -04:00
Peter Zhu aa794cc5a2 Turn GC off at boot on Windows
This is to stop crashes like:

    .\miniruby.exe: [BUG] Segmentation fault
    ruby 3.4.0dev (2024-03-26T15:38:26Z pull/10370/merge 040ea2ae2f) [x64-mswin64_140]

    -- Control frame information -----------------------------------------------
    c:0001 p:0000 s:0003 E:000d00 DUMMY  [FINISH]

    -- Threading information ---------------------------------------------------
    Total ractor count: 1
    Ruby thread count for this ractor: 1

    -- C level backtrace information -------------------------------------------
    C:\Windows\SYSTEM32\ntdll.dll(NtWaitForSingleObject+0x14) [0x00007FFA091AFC74]
    C:\Windows\System32\KERNELBASE.dll(WaitForSingleObjectEx+0x93) [0x00007FFA05BB4513]
    D:\a\ruby\ruby\build\miniruby.exe(rb_print_backtrace+0x3e) [0x00007FF64E536EFE] d:\a\ruby\ruby\src\vm_dump.c:844
    D:\a\ruby\ruby\build\miniruby.exe(rb_vm_bugreport+0x1ae) [0x00007FF64E5370B2] d:\a\ruby\ruby\src\vm_dump.c:1154
    D:\a\ruby\ruby\build\miniruby.exe(rb_bug_for_fatal_signal+0x77) [0x00007FF64E3FF357] d:\a\ruby\ruby\src\error.c:1087
    D:\a\ruby\ruby\build\miniruby.exe(sigsegv+0x71) [0x00007FF64E4C79E5] d:\a\ruby\ruby\src\signal.c:926
    C:\Windows\System32\ucrtbase.dll(seh_filter_exe+0x233) [0x00007FFA0521CE03]
    D:\a\ruby\ruby\build\miniruby.exe(`__scrt_common_main_seh'::`1'::filt$0+0x16) [0x00007FF64E594DA0] f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:269
    C:\Windows\SYSTEM32\VCRUNTIME140.dll(_C_specific_handler+0x9f) [0x00007FF9E54AF73F]
    C:\Windows\SYSTEM32\ntdll.dll(_chkstk+0x11f) [0x00007FFA091B4C2F]
    C:\Windows\SYSTEM32\ntdll.dll(RtlWalkFrameChain+0x14bf) [0x00007FFA09114CEF]
    C:\Windows\SYSTEM32\ntdll.dll(KiUserExceptionDispatcher+0x2e) [0x00007FFA091B399E]
    D:\a\ruby\ruby\build\miniruby.exe(newobj_of+0x6d) [0x00007FF64E418615] d:\a\ruby\ruby\src\gc.c:2949
    D:\a\ruby\ruby\build\miniruby.exe(rb_wb_protected_newobj_of+0x32) [0x00007FF64E41C7DA] d:\a\ruby\ruby\src\gc.c:2974
    D:\a\ruby\ruby\build\miniruby.exe(str_new0+0x64) [0x00007FF64E4E7F48] d:\a\ruby\ruby\src\string.c:887
    D:\a\ruby\ruby\build\miniruby.exe(rb_enc_str_new+0x40) [0x00007FF64E4D89B8] d:\a\ruby\ruby\src\string.c:945
    D:\a\ruby\ruby\build\miniruby.exe(iseq_compile_each0+0xdd7) [0x00007FF64E3B4A23] d:\a\ruby\ruby\src\compile.c:10368
    D:\a\ruby\ruby\build\miniruby.exe(iseq_compile_each+0x74) [0x00007FF64E3B3C40] d:\a\ruby\ruby\src\compile.c:9971
2024-03-27 09:39:23 -04:00
Peter Zhu f14e52c8c4 Fix setting GC stress at boot when objspace not available 2024-03-27 09:39:23 -04:00
eileencodes e16086b7f2 Refactor init_copy gc attributes
This PR moves `rb_copy_wb_protected_attribute` and
`rb_gc_copy_finalizer` into a single function called
`rb_gc_copy_attributes` to be called by `init_copy`. This reduces the
surface area of the GC API.

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2024-03-26 14:29:36 -04:00
Peter Zhu 9cf754b648 Fix --debug=gc_stress flag
ruby_env_debug_option gets called after Init_gc_stress, so the
--debug=gc_stress flag never works.
2024-03-25 13:07:39 -04:00
KJ Tsanaktsidis 2535a09e85 Check ASAN fake stacks when marking non-current threads
Currently, we check the values on the machine stack & register state to
see if they're actually a pointer to an ASAN fake stack, and mark the
values on the fake stack too if required. However, we are only doing
that for the _current_ thread (the one actually running the GC), not for
any other thread in the program.

Make rb_gc_mark_machine_context (which is called for marking non-current
threads) perform the same ASAN fake stack handling that
mark_current_machine_context performs.

[Bug #20310]
2024-03-25 14:57:04 +11:00
KJ Tsanaktsidis 48d3bdddba Move asan_fake_stack_handle to EC, not thread
It's really a property of the EC; each fiber (which has its own EC) also
has its own asan_fake_stack_handle.

[Bug #20310]
2024-03-25 14:57:04 +11:00
Peter Zhu 806edd2956 Pass objspace into heap_check_moved_i 2024-03-21 10:43:07 -04:00
Peter Zhu 9a6a6b4ba6 Pass objspace into root_obj_check_moved_i 2024-03-21 10:43:07 -04:00
Peter Zhu e07441f05f Make rb_aligned_malloc private
It is not used anywhere else.
2024-03-20 10:27:41 -04:00
Peter Zhu 4469729558 Remove rb_raw_obj_info_basic
It's not used outside of gc.c.
2024-03-18 10:19:11 -04:00
Peter Zhu 185112f4ff Remove unused macro TF 2024-03-15 16:03:26 -04:00
Peter Zhu 59785680dd Remove unused macro GC_NOTIFY in gc.c 2024-03-15 15:44:05 +09:00
Peter Zhu c2170e5c2b Fix typo from gloabl_object_list to global_object_list 2024-03-14 13:52:20 -04:00
Peter Zhu 4559a161af Move gloabl_object_list from objspace to VM
This is to be consistent with the mark_object_ary that is in the VM.
2024-03-14 13:29:59 -04:00
Peter Zhu ff51dc5654 [Feature #20265] Remove rb_newobj_of and RB_NEWOBJ_OF 2024-03-14 12:53:04 -04:00
Peter Zhu 8e1831406f [Feature #20265] Remove rb_newobj and RB_NEWOBJ 2024-03-14 12:53:04 -04:00
Peter Zhu 3896f9940e Make special const and too complex shapes before T_OBJECT shapes 2024-03-13 09:55:52 -04:00
Peter Zhu 6b0434c0f7 Don't create per size pool shapes for non-T_OBJECT 2024-03-13 09:55:52 -04:00
Peter Zhu 6ad347a105 Don't directly read the SIZE_POOL_COUNT in shapes
This removes the assumption about SIZE_POOL_COUNT for shapes.
2024-03-13 09:55:52 -04:00
Peter Zhu e12bc5c572 Remove dead function rb_obj_rgengc_promoted_p 2024-03-11 11:04:20 -04:00
Peter Zhu 9f31577987 Reuse rb_gc_writebarrier_unprotect in rb_copy_wb_protected_attribute 2024-03-11 09:30:15 -04:00
Jean Boussier d4f3dcf4df Refactor VM root modules
This `st_table` is used to both mark and pin classes
defined from the C API. But `vm->mark_object_ary` already
does both much more efficiently.

Currently a Ruby process starts with 252 rooted classes,
which uses `7224B` in an `st_table` or `2016B` in an `RArray`.

So a baseline of 5kB saved, but since `mark_object_ary` is
preallocated with `1024` slots but only use `405` of them,
it's a net `7kB` save.

`vm->mark_object_ary` is also being refactored.

Prior to this changes, `mark_object_ary` was a regular `RArray`, but
since this allows for references to be moved, it was marked a second
time from `rb_vm_mark()` to pin these objects.

This has the detrimental effect of marking these references on every
minors even though it's a mostly append only list.

But using a custom TypedData we can save from having to mark
all the references on minor GC runs.

Addtionally, immediate values are now ignored and not appended
to `vm->mark_object_ary` as it's just wasted space.
2024-03-06 15:33:43 -05:00
Jean Boussier b4a69351ec Move FL_SINGLETON to FL_USER1
This frees FL_USER0 on both T_MODULE and T_CLASS.

Note: prior to this, FL_SINGLETON was never set on T_MODULE,
so checking for `FL_SINGLETON` without first checking that
`FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-06 13:11:41 -05:00
Peter Zhu 5a3ae06a09 Remove dead function rb_obj_rgengc_writebarrier_protected_p 2024-03-01 15:41:16 -05:00
Peter Zhu 6f31dd495c Don't check_rvalue_consistency in is_markable_object
is_markable_object is called by rb_objspace_markable_object_p, which
may pass a T_NONE object. check_rvalue_consistency will fail if a T_NONE
object is passed in.
2024-03-01 13:38:49 -05:00
Peter Zhu d3ae5808bb Remove each_machine_stack_value
The function is only used by rb_gc_mark_machine_stack.
2024-02-29 14:26:31 -05:00
Peter Zhu 3d61477900 Remove unused gc_mark_stack_values 2024-02-29 13:23:50 -05:00
Peter Zhu 6665ec26db Remove check for is_markable_object in gc_mark_stack_values
gc_mark_and_pin already checks for is_markable_object.
2024-02-29 13:23:50 -05:00
Peter Zhu 4c0f0b90a4 Assume that FL_FINALIZE is in finalizer_table
If FL_FINALIZE is set but not in finalizer_table, then rb_bug.
2024-02-29 11:07:53 -05:00
Peter Zhu 8a918b456c Add gc_each_object for walking the heap 2024-02-29 10:57:24 -05:00
Peter Zhu 950c60623b Delete from finalizer_table before running finalizer
The finalizer could trigger a GC, which would cause FL_FINALIZE to be
out of sync with the finalizer table.
2024-02-29 09:38:13 -05:00
Peter Zhu d5bca0668c Unset FL_FINALIZE before running the finalizer
The finalizer could trigger a GC, so FL_FINALIZE could get out of sync
with the finalizer table.
2024-02-29 09:37:38 -05:00
Peter Zhu 4b92b60f0b Use array initialization rather than for loop 2024-02-28 14:54:21 -05:00
Peter Zhu 5481dbef07 Make rb_define_finalizer_no_check private 2024-02-28 13:45:19 -05:00
Peter Zhu dcc976add9 Remove unused rb_gc_id2ref_obj_tbl 2024-02-28 12:21:38 -05:00
Peter Zhu 7b69563b36 Add check for finalizer in verify_internal_constency
This adds a check in GC.verify_internal_constency that FL_FINALIZE flags
is set if, and only if it is in finalizer_table.
2024-02-28 10:41:11 -05:00
Peter Zhu 48f433fd40 Change T_ZOMBIE flag check from an assertion
Assertions are only enable on debug builds, so it will now check for
flags of T_ZOMBIE objects on all builds in GC.verify_internal_consistency.
2024-02-28 10:41:11 -05:00
Peter Zhu e8e2415bb3 Use RB_SPECIAL_CONST_P instead of rb_special_const_p
rb_special_const_p returns a VALUE (Qtrue or Qfalse), so we shouldn't
assume that Qfalse is 0. We should instead use RB_SPECIAL_CONST_P.
2024-02-27 21:11:11 -05:00
Peter Zhu 08731182b8 Change is_garbage_object to return a bool 2024-02-27 14:52:02 -05:00
Peter Zhu 3c44f6da6c Simplify is_garbage_object 2024-02-27 14:52:02 -05:00
Peter Zhu 1f740cd111 Remove is_swept_object
The name is misleading, as it seems like the function checks whether the
object is swept or not. But the function only checks whether the page is
before or after sweeping.
2024-02-27 12:10:48 -05:00
Peter Zhu 2396b7a62f Change is_live_object to return a bool 2024-02-27 10:03:42 -05:00
Peter Zhu 9ba53cb688 Simplify is_live_object 2024-02-27 10:03:42 -05:00
Peter Zhu 78ae6dbb11 Remove rb_objspace_marked_object_p
rb_objspace_marked_object_p is no longer used in the objspace module, so
we can remove it.
2024-02-26 17:05:34 -05:00
Peter Zhu 7538703d1b Make rb_objspace_data_type_memsize private
rb_objspace_data_type_memsize is not used in the objspace module, so we
can make it private.
2024-02-26 17:05:34 -05:00
Peter Zhu c9b6cd4223 Remove unused rb_objspace_each_objects_without_setup 2024-02-26 14:34:24 -05:00
Peter Zhu 27e3e44390 Fix verify_internal_consistency_i for zombie objects
FL_FINALIZE is now kept for zombie objects.
2024-02-26 11:38:44 -05:00
Peter Zhu 83e676e5f9 Don't lookup finalizers if FL_FINALIZE flag not set
The FL_FINALIZE flag is set when there are finalizers for the object. We
can improver performance by not looking up in the table if the flag is
not set.

Using the following C extension:

    #include "ruby/ruby.h"

    static void data_free(void *_ptr) {}

    static const rb_data_type_t data_type = {
        "my_type",
        {
            NULL,
            data_free,
        },
        0, 0, 0
    };

    static VALUE data_alloc(VALUE klass) {
        return TypedData_Wrap_Struct(klass, &data_type, (void *)1);
    }

    void Init_myext(void) {
        VALUE my_klass = rb_define_class("MyClass", rb_cObject);
        rb_define_alloc_func(my_klass, data_alloc);
    }

And the following benchmark:

    require "benchmark"

    final_objs = 1_000_000.times.map do
      o = Object.new
      ObjectSpace.define_finalizer(o, proc {})
      o
    end

    puts(Benchmark.measure do
      100_000_000.times do
        MyClass.new
      end
    end)

Before:

    10.974190   0.355037  11.329227 ( 11.416772)

After:

    7.664310   0.347598   8.011908 (  8.268969)
2024-02-26 09:20:05 -05:00
Peter Zhu e65315a725 Extract imemo functions from gc.c into imemo.c 2024-02-22 11:35:09 -05:00
Peter Zhu 330830dd1a Add IMEMO_NEW
Rather than exposing that an imemo has a flag and four fields, this
changes the implementation to only expose one field (the klass) and
fills the rest with 0. The type will have to fill in the values themselves.
2024-02-21 11:33:05 -05:00
Peter Zhu 402690c3b6 Fix incomplete switch statement in imemo_memsize
The switch statement is not exhaustive, meaning the "unreachable"
comment was not correct. This commit fixes it by making the list
exhaustive and adding an rb_bug in the default case.
2024-02-21 10:13:36 -05:00
John Hawthorn 1c97abaaba De-dup identical callinfo objects
Previously every call to vm_ci_new (when the CI was not packable) would
result in a different callinfo being returned this meant that every
kwarg callsite had its own CI.

When calling, different CIs result in different CCs. These CIs and CCs
both end up persisted on the T_CLASS inside cc_tbl. So in an eval loop
this resulted in a memory leak of both types of object. This also likely
resulted in extra memory used, and extra time searching, in non-eval
cases.

For simplicity in this commit I always allocate a CI object inside
rb_vm_ci_lookup, but ideally we would lazily allocate it only when
needed. I hope to do that as a follow up in the future.
2024-02-20 18:55:00 -08:00
Peter Zhu 97d4363d3b [DOC] Improve docs for GC.latest_compact_info 2024-02-20 17:39:46 -05:00
Peter Zhu c184aa8740 Use rb_gc_mark_and_move for imemo 2024-02-20 10:39:30 -05:00
Peter Zhu 24645cff0d Removed duplicated variable in push_mark_stack 2024-02-16 13:27:16 -05:00
Peter Zhu 4411cdeef9 Fix typo in gc.c 2024-02-16 11:44:27 -05:00
Peter Zhu 28709d591d Remove unused argument in cc_table_free 2024-02-14 16:25:05 -05:00
Peter Zhu ae8db4b65a Remove unused function rb_cc_table_free 2024-02-14 15:52:15 -05:00
Peter Zhu 1d3b306753 Move rb_class_allocate_instance from gc.c to object.c 2024-02-14 13:43:02 -05:00
Alan Wu 5add999dee Comment about not marking RSYMBOL(obj)->fstr [ci skip] 2024-02-13 14:49:54 -05:00
Peter Zhu 190a55d27f Drill newobj cache instead of ractor 2024-02-12 09:43:38 -05:00
Peter Zhu a50e35888b Free all remaining objects in rb_objspace_free_objects
rb_objspace_call_finalizer didn't free fibers and neither did
rb_objspace_free_objects, which caused fibers to be reported as leaked
when using RUBY_FREE_AT_EXIT. This commit changes rb_objspace_free_objects
to free all remaining Ruby objects.
2024-02-06 10:54:05 -05:00
KJ Tsanaktsidis 4f4f3a6dec Don't check __asan_region_is_poisoned in objspace_each_objects
This returns whether or not _any_ piece of memory in the range is
poisoned, not if _all_ of it is. That means that currently, with ASAN
enabled, pages which contain a single poisoned object are skipped
entirely from being iterated with objspace_each* family of functions.

[Bug #20220]
2024-02-06 22:23:42 +11:00
Peter Zhu d0b774cfb8 Remove null checks for xfree
xfree can handle null values, so we don't need to check it.
2024-01-19 10:25:02 -05:00
KJ Tsanaktsidis 61da90c1b8 Mark asan fake stacks during machine stack marking
ASAN leaves a pointer to the fake frame on the stack; we can use the
__asan_addr_is_in_fake_stack API to work out the extent of the fake
stack and thus mark any VALUEs contained therein.

[Bug #20001]
2024-01-19 09:55:12 +11:00
Peter Zhu cc7b19e048 [DOC] Improve docs for GC.compact 2024-01-15 11:27:31 -05:00
Alan Wu e59dd7094f Pass more T_DATA to obj_free() under RUBY_FREE_AT_EXIT
T_DATA without a pointer or free function may still have ivars set on
them that need to be freed. The following leaked generic ivars for
example:

    converter = Encoding::Converter.allocate
    converter.instance_variable_set(:@foo, 1)

    STACK OF 1 INSTANCE OF 'ROOT LEAK: <malloc in objspace_xmalloc0>':
    <snip>
    12  miniruby    0x10286ec50 ivar_set + 140  variable.c:1850
    11  miniruby    0x102876afc generic_ivar_set + 136  variable.c:1668
2024-01-12 13:28:36 -05:00
KJ Tsanaktsidis ac0ba3c07e Revert "Allow each_stack_location to accept context for the callback"
This reverts commit 179228cd83.
2024-01-12 17:58:54 +11:00
KJ Tsanaktsidis 688a6ff510 Revert "Mark asan fake stacks during machine stack marking"
This reverts commit d10bc3a2b8.
2024-01-12 17:58:54 +11:00
KJ Tsanaktsidis d10bc3a2b8 Mark asan fake stacks during machine stack marking
ASAN leaves a pointer to the fake frame on the stack; we can use the
__asan_addr_is_in_fake_stack API to work out the extent of the fake
stack and thus mark any VALUEs contained therein.

[Bug #20001]
2024-01-12 17:29:48 +11:00
KJ Tsanaktsidis 179228cd83 Allow each_stack_location to accept context for the callback
This is preparing for a more specialised, asan-aware version of
gc_mark_maybe which needs some additional context passed through.

[Bug #20001]
2024-01-12 17:29:48 +11:00
KJ Tsanaktsidis 25f5b83689 Fix crash when printing RGENGC_DEBUG=5 output from GC
I was trying to debug an (unrelated) issue in the GC, and wanted to turn
on the trace-level GC output by compiling it with -DRGENGC_DEBUG=5.
Unfortunately, this actually causes a crash in newobj_init() because the
code there tries to log the obj_info() of the newly created object.
However, the object is not actually sufficiently set up for some of the
things that obj_info() tries to do:

* The instance variable table for a class is not yet initialized, and
  when using variable-length RVALUES, said ivar table is embedded in
  as-yet unitialized memory after the struct RValue. Attempting to read
  this, as obj_info() does, causes a crash.
* T_DATA variables need to dereference their ->type field to print out
  the underlying C type name, which is not set up until newobj_fill() is
  called.

To fix this, create a new method `obj_info_basic`, which dumps out only
the parts of the object that are valid before the object is fully
initialized.

[Fixes #18795]
2024-01-11 10:44:57 +11:00
Peter Zhu 8940922d18 [DOC] Improve doc for GC.latest_compact_info 2024-01-10 09:46:19 -05:00
Peter Zhu d9bad91c34 [DOC] Fix docs for GC.compact
GC.compact returns GC.latest_compact_info and not GC.latest_gc_info.
2024-01-07 22:26:12 -05:00
Nobuyoshi Nakada c30b8ae947
Adjust styles and indents [ci skip] 2024-01-08 00:50:41 +09:00
Rian McGuire 7db35e10c3 Fix GC.measure_total_time regression
Commit 93ac7405b8 introduced a regression
where measurements would still be taken after setting
GC.measure_total_time = false.

Fixes [Bug #20157]
2024-01-06 17:36:35 +11:00
Peter Zhu 70618a48f7 Fix off-by-one error for declarative marking
The for loops for marking and reference updating declaratively marked
TypedData objects did not mark/reference update the very last element.

When RGENGC_CHECK_MODE is turned on, this caused the test in Enumerator
to fail with:

    tool/lib/test/unit/testcase.rb:173:in `rescue in run': failed to allocate memory (NoMemoryError)
2023-12-24 20:37:59 -05:00