summaryrefslogtreecommitdiff
path: root/gc.c
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] Fix formatting for GC.compactPeter Zhu2022-12-201-1/+1
|
* [DOC] Escape all usages of GCPeter Zhu2022-12-201-7/+7
| | | | | RDoc was making every usage of the word "GC" link to the page for GC (which is the same page).
* [DOC] Fix call-seq for GC methodsPeter Zhu2022-12-201-1/+1
| | | | | RDoc parses the last arrow in the call-seq as the arrow for the return type. It was getting confused over the arrow in the hash.
* [DOC] Fix formatting for GC#latest_compact_infoPeter Zhu2022-12-201-1/+1
|
* Fix thrashing of major GC when size pool is smallPeter Zhu2022-12-201-6/+12
| | | | | | | | If a size pooll is small, then `min_free_slots < heap_init_slots` is true. This means that min_free_slots will be set to heap_init_slots. This causes `swept_slots < min_free_slots` to be true in a later if statement. The if statement could trigger a major GC which could cause major GC thrashing.
* Fix misfire of compaction read barrierPeter Zhu2022-12-191-1/+1
| | | | | | | | gc_compact_move incorrectly returns false when destination heap is full after sweeping. It returns false even if destination heap is different than source heap (returning false means that the source heap has finished compacting). This causes the source page to get locked, which causes a read barrier fire when we try to compact the source heap again.
* Fix buffer overrun when re-embedding objectsPeter Zhu2022-12-191-4/+2
| | | | | | | | | | | We eagerly set the new shape of an object when moving an object during compaction. This new shape may have a different capacity than the current original shape capacity. This means that we cannot copy from the original buffer using size of the new capacity. Instead, we should use the ivar count (which is less than or equal to both the new and original capacities). Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
* Hard crash when allocating in GC when RUBY_DEBUGPeter Zhu2022-12-171-3/+3
| | | | | Not all builds have RGENGC_CHECK_MODE set, so it should also crash when RUBY_DEBUG is set.
* Move check for GC to xmalloc and xcallocPeter Zhu2022-12-171-7/+14
| | | | Moves the check earlier to before we actually perform the allocation.
* Don't allow allocating memory during GCPeter Zhu2022-12-161-12/+48
| | | | | | | | | Allocating memory (xmalloc and xrealloc) during GC could cause GC to trigger, which would crash with `[BUG] during_gc != 0`. This is an intermittent bug which could be hard to debug. This commit changes it so that any memory allocation during GC will emit a warning. When debug flags are enabled it will also cause a crash.
* Refactor to only attempt to move movable objectsPeter Zhu2022-12-151-30/+33
| | | | | | Moves check for gc_is_moveable_obj from try_move to gc_compact_plane. Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
* Fix Object Movement allocation in GCMatt Valentine-House2022-12-151-5/+36
| | | | | | | | | | | | | | | | | | | When moving Objects between size pools we have to assign a new shape. This happened during updating references - we tried to create a new shape tree that mirrored the existing tree, but based on the root shape of the new size pool. This causes allocations to happen if the new tree doesn't already exist, potentially triggering a GC, during GC. This commit changes object movement to look for a pre-existing new tree during object movement, and if that tree does not exist, we don't move the object to the new pool. This allows us to remove the shape allocation from update references. Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
* Transition complex objects to "too complex" shapeJemma Issroff2022-12-151-14/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an object becomes "too complex" (in other words it has too many variations in the shape tree), we transition it to use a "too complex" shape and use a hash for storing instance variables. Without this patch, there were rare cases where shape tree growth could "explode" and cause performance degradation on what would otherwise have been cached fast paths. This patch puts a limit on shape tree growth, and gracefully degrades in the rare case where there could be a factorial growth in the shape tree. For example: ```ruby class NG; end HUGE_NUMBER.times do NG.new.instance_variable_set(:"@unique_ivar_#{_1}", 1) end ``` We consider objects to be "too complex" when the object's class has more than SHAPE_MAX_VARIATIONS (currently 8) leaf nodes in the shape tree and the object introduces a new variation (a new leaf node) associated with that class. For example, new variations on instances of the following class would be considered "too complex" because those instances create more than 8 leaves in the shape tree: ```ruby class Foo; end 9.times { Foo.new.instance_variable_set(":@uniq_#{_1}", 1) } ``` However, the following class is *not* too complex because it only has one leaf in the shape tree: ```ruby class Foo def initialize @a = @b = @c = @d = @e = @f = @g = @h = @i = nil end end 9.times { Foo.new } `` This case is rare, so we don't expect this change to impact performance of most applications, but it needs to be handled. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Revert "Fix Object Movement allocation in GC"Peter Zhu2022-12-151-36/+5
| | | | | | This reverts commit 9c54466e299aa91af225bc2d92a3d7755730948f. We're seeing crashes in Shopify CI after this commit.
* Fix Object Movement allocation in GCMatt Valentine-House2022-12-151-5/+36
| | | | | | | | | | | | | | | | | | | When moving Objects between size pools we have to assign a new shape. This happened during updating references - we tried to create a new shape tree that mirrored the existing tree, but based on the root shape of the new size pool. This causes allocations to happen if the new tree doesn't already exist, potentially triggering a GC, during GC. This commit changes object movement to look for a pre-existing new tree during object movement, and if that tree does not exist, we don't move the object to the new pool. This allows us to remove the shape allocation from update references. Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
* fix indentation: gc_compact_destination_poolMatt Valentine-House2022-12-131-11/+11
| | | | | | [ci skip] Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
* [DOC] Don't document private methods in objspacePeter Zhu2022-12-121-0/+1
|
* Expose need_major_gc via GC.latest_gc_info (#6791)Mirek Klimos2022-12-101-2/+17
|
* Remove unused counter for heap_page->pinned_slotsMatt Valentine-House2022-12-091-1/+0
|
* Increment max_iv_count on class based on number of set_iv in initialize (#6788)Jemma Issroff2022-11-221-1/+1
| | | | | | We can loosely predict the number of ivar sets on a class based on the number of iv set instructions in the initialize method. This should give us a more accurate estimate to use for initial size pool allocation, which should in turn give us more cache hits.
* Add RVALUE_OVERHEAD and move ractor_belonging_idPeter Zhu2022-11-211-14/+39
| | | | | | | This commit adds RVALUE_OVERHEAD for storing metadata at the end of the slot. This commit moves the ractor_belonging_id in debug builds from the flags to RVALUE_OVERHEAD which frees the 16 bits in the headers for object shapes.
* Differentiate T_OBJECT shapes from other objectsAaron Patterson2022-11-181-1/+7
| | | | | | | We would like to differentiate types of objects via their shape. This commit adds a special T_OBJECT shape when we allocate an instance of T_OBJECT. This allows us to avoid testing whether an object is an instance of a T_OBJECT or not, we can just check the shape.
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-6/+6
|
* Remove numiv from RObjectJemma Issroff2022-11-101-17/+5
| | | | | | | Since object shapes store the capacity of an object, we no longer need the numiv field on RObjects. This gives us one extra slot which we can use to give embedded objects one more instance variable (for a total of 3 ivs). This commit removes the concept of numiv from RObject.
* Transition shape when object's capacity changesJemma Issroff2022-11-101-13/+54
| | | | | | | | | | | | | | | | This commit adds a `capacity` field to shapes, and adds shape transitions whenever an object's capacity changes. Objects which are allocated out of a bigger size pool will also make a transition from the root shape to the shape with the correct capacity for their size pool when they are allocated. This commit will allow us to remove numiv from objects completely, and will also mean we can guarantee that if two objects share shapes, their IVs are in the same positions (an embedded and extended object cannot share shapes). This will enable us to implement ivar sets in YJIT using object shapes. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* [wasm] Scan machine stack based on `ec->machine.stack_{start,end}`Yuta Saito2022-11-061-2/+4
| | | | | | | | fiber machine stack is placed outside of C stack allocated by wasm-ld, so highest stack address recorded by `rb_wasm_record_stack_base` is invalid when running on non-main fiber. Therefore, we should scan `stack_{start,end}` which always point a valid stack range in any context.
* Increment max_iv_count on class in gc marking, not gc freeingJemma Issroff2022-11-041-10/+11
| | | | | | | We were previously incrementing the max_iv_count on a class in gc freeing. By the time we free an object though, we're not guaranteed its class is still valid. Instead, we can do this when marking and we're guaranteed the object still knows its class.
* Implement object shapes for T_CLASS and T_MODULE (#6637)John Hawthorn2022-10-311-13/+10
| | | | | | | | * Avoid RCLASS_IV_TBL in marshal.c * Avoid RCLASS_IV_TBL for class names * Avoid RCLASS_IV_TBL for autoload * Avoid RCLASS_IV_TBL for class variables * Avoid copying RCLASS_IV_TBL onto ICLASSes * Use object shapes for Class and Module IVs
* fix ASAN error in GCAaron Patterson2022-10-281-0/+2
|
* Rename `iv_count` on shapes to `next_iv_index`Jemma Issroff2022-10-211-1/+1
| | | | | | `iv_count` is a misleading name because when IVs are unset, the new shape doesn't decrement this value. `next_iv_count` is an accurate, and more descriptive name.
* Remove unused class serialJemma Issroff2022-10-211-3/+0
| | | | | | | | Before object shapes, we were using class serial to invalidate inline caches. Now that we use shape_id for inline cache keys, the class serial is unnecessary. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Check writebarrier arguments only when RGENGC_CHECK_MODE [ci skip]Nobuyoshi Nakada2022-10-211-2/+4
| | | | | | The commit 575ae50d16a03ed23357ec4ea0dbf7167fc26c8c was for debugging the failure triggered by f55212bce939f736559709a8cd16c409772389c8, and it was fixed at the commit 39f7eddec4c55711d56f05b085992a83bf23159e.
* Check writebarrier argumentsNobuyoshi Nakada2022-10-201-2/+2
|
* Stop zeroing memory on allocation / copyAaron Patterson2022-10-191-25/+8
| | | | | | | Shapes gives us an almost exact count of instance variables on an object. Since we know the number of instance variables that have been set, we will never access slots that haven't been initialized with an IV.
* Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975)Sergey Fedorov2022-10-191-0/+21
|
* More precisely iterate over Object instance variablesAaron Patterson2022-10-151-2/+2
| | | | | | Shapes provides us with an (almost) exact count of instance variables. We only need to check for Qundef when an IV has been "undefined" Prefer to use ROBJECT_IV_COUNT when iterating IVs
* Use `roomof` macro for rounding up divisionsNobuyoshi Nakada2022-10-141-1/+1
|
* Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff2022-10-111-38/+12
| | | | This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
* Add IO#timeout attribute and use it for blocking IO operations. (#5653)Samuel Williams2022-10-071-0/+1
|
* [Bug #19028] Suppress GCC 12 `-Wuse-after-free` false warningNobuyoshi Nakada2022-10-041-1/+1
| | | | | | | | GCC 12 introduced a new warning flag `-Wuse-after-free`, however it has a false positive at `realloc` when optimization is disabled, since the memory requested for reallocation is guaranteed to not be touched. This workaround is very unclear why the false warning is suppressed by a statement-expression GCC extension.
* Revert "This commit implements the Object Shapes technique in CRuby."Aaron Patterson2022-09-301-12/+38
| | | | This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
* This commit implements the Object Shapes technique in CRuby.Jemma Issroff2022-09-281-38/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email>
* Always use the longer version of `TRY_WITH_GC`Nobuyoshi Nakada2022-09-281-18/+12
|
* Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson2022-09-261-143/+72
| | | | | | | | | | Revert "* expand tabs. [ci skip]" This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275. Revert "This commit implements the Object Shapes technique in CRuby." This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
* * expand tabs. [ci skip]git2022-09-271-2/+2
| | | | | Tabs were expanded because the file did not have any tab indentation in unedited lines. Please update your editor config, and use misc/expand_tabs.rb in the pre-commit hook.
* This commit implements the Object Shapes technique in CRuby.Jemma Issroff2022-09-261-74/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email>
* Rework vm_core to use `int first_lineno` struct member.Samuel Williams2022-09-261-3/+2
|
* Skip poisoned regionsNobuyoshi Nakada2022-08-091-1/+2
| | | | | | | | | Poisoned regions cannot be accessed without unpoisoning outside gc.c. Specifically, debug.gem is terminated by AddressSanitizer. ``` SUMMARY: AddressSanitizer: use-after-poison iseq_collector.c:39 in iseq_i ```
* Lock the VM for rb_gc_writebarrier_unprotectPeter Zhu2022-07-281-13/+17
| | | | | When using Ractors, rb_gc_writebarrier_unprotect requries a VM lock since it modifies the bitmaps.
* Make array slices views rather than copiesPeter Zhu2022-07-281-0/+14
| | | | | | Before this commit, if the slice fits in VWA, it would make a copy rather than a view. This is slower as it requires a memcpy of the contents.