From 02b216e5a70235f42f537e895d6f1afd05d8916a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 28 May 2020 15:02:26 -0700 Subject: Combine sweeping and moving This commit combines the sweep step with moving objects. With this commit, we can do: ```ruby GC.start(compact: true) ``` This code will do the following 3 steps: 1. Fully mark the heap 2. Sweep + Move objects 3. Update references By default, this will compact in order that heap pages are allocated. In other words, objects will be packed towards older heap pages (as opposed to heap pages with more pinned objects like `GC.compact` does). --- gc.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gc.rb') diff --git a/gc.rb b/gc.rb index dd5781b603..23ed12ffdc 100644 --- a/gc.rb +++ b/gc.rb @@ -30,12 +30,12 @@ module GC # Note: These keyword arguments are implementation and version dependent. They # are not guaranteed to be future-compatible, and may be ignored if the # underlying implementation does not support them. - def self.start full_mark: true, immediate_mark: true, immediate_sweep: true - __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep + def self.start full_mark: true, immediate_mark: true, immediate_sweep: true, compact: false + __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep, compact end def garbage_collect full_mark: true, immediate_mark: true, immediate_sweep: true - __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep + __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep, false end # call-seq: @@ -188,7 +188,7 @@ end module ObjectSpace def garbage_collect full_mark: true, immediate_mark: true, immediate_sweep: true - __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep + __builtin_gc_start_internal full_mark, immediate_mark, immediate_sweep, false end module_function :garbage_collect -- cgit v1.2.1