Skip to content

Commit

Permalink
Fix transient heap mode
Browse files Browse the repository at this point in the history
Make sure the transient heap is in the right mode when we finish warming
the heap.  Also ensure the GC isn't allowed to run while we iterate and
mutate the heap.
  • Loading branch information
tenderlove authored and byroot committed Apr 4, 2023
1 parent ba6ccd8 commit 87253d0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion gc.c
Expand Up @@ -9885,10 +9885,26 @@ rb_gc_prepare_heap(void)
{
gc_start_internal(NULL, Qtrue, Qtrue, Qtrue, Qtrue, Qtrue);

/* The transient heap need to be evacuated before we promote objects */
/* Flush any postponed jobs.
* Transient heap uses postponed jobs to mark things, so we need to
* give it a chance to finish what it was doing. */
rb_postponed_job_flush(GET_VM());

/* The transient heap need to be evacuated before we promote objects.
* First put the transient heap in marking mode so that we can
* evacuate everything. Then evacuate everything. Then finish up
* marking mode so that the transient heap is in the right mode
* for the next GC. */
rb_transient_heap_start_marking(true);
rb_transient_heap_evacuate();
rb_transient_heap_finish_marking();

/* Finally, promote everyone to old gen, but don't let the GC run
* while we iterate over the heap. */
VALUE gc_disabled = rb_gc_disable_no_rest();
rb_objspace_each_objects(gc_promote_object_i, NULL);
if (gc_disabled != Qtrue) rb_gc_enable();
rb_transient_heap_verify();
}

static int
Expand Down

0 comments on commit 87253d0

Please sign in to comment.