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
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