summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-08-16 16:02:16 -0400
committerPeter Zhu <[email protected]>2024-08-19 10:58:36 -0400
commitcb2848772210f8e00956a24db650f8b06786fd3c (patch)
tree0335728d1ac426aecdd046ac038d2b6fb9934cee
parent786d0006524b0ca282a05593ca3dff3633890af7 (diff)
Make assertions allow incremental GC when disabled
When assertions are enabled, the following code triggers an assertion error: GC.disable GC.start(immediate_mark: false, immediate_sweep: false) 10_000_000.times { Object.new } This is because the GC.start ignores that the GC is disabled and will start incremental marking and lazy sweeping. But the assertions in gc_marks_continue and gc_sweep_continue assert that GC is not disabled. This commit changes it for the assertion to pass if the GC was triggered from a method.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11391
-rw-r--r--gc/default.c4
-rw-r--r--test/ruby/test_gc.rb10
2 files changed, 12 insertions, 2 deletions
diff --git a/gc/default.c b/gc/default.c
index 93f116a276..cf0d9b882a 100644
--- a/gc/default.c
+++ b/gc/default.c
@@ -4182,7 +4182,7 @@ gc_sweep_rest(rb_objspace_t *objspace)
static void
gc_sweep_continue(rb_objspace_t *objspace, rb_size_pool_t *sweep_size_pool, rb_heap_t *heap)
{
- GC_ASSERT(dont_gc_val() == FALSE);
+ GC_ASSERT(dont_gc_val() == FALSE || objspace->profile.latest_gc_info & GPR_FLAG_METHOD);
if (!GC_ENABLE_LAZY_SWEEP) return;
gc_sweeping_enter(objspace);
@@ -5985,7 +5985,7 @@ gc_marks_step(rb_objspace_t *objspace, size_t slots)
static bool
gc_marks_continue(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t *heap)
{
- GC_ASSERT(dont_gc_val() == FALSE);
+ GC_ASSERT(dont_gc_val() == FALSE || objspace->profile.latest_gc_info & GPR_FLAG_METHOD);
bool marking_finished = true;
gc_marking_enter(objspace);
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index a05da28f7e..9029f2bda8 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -856,6 +856,16 @@ class TestGc < Test::Unit::TestCase
ensure
GC.enable unless disabled
end
+
+ begin
+ disabled = GC.disable
+ c = GC.count
+ GC.start(immediate_mark: false, immediate_sweep: false)
+ 10_000.times { Object.new }
+ assert_equal 1, GC.count - c
+ ensure
+ GC.enable unless disabled
+ end
end
def test_vm_object