summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-05-28 10:26:23 +0900
committerKoichi Sasada <ko1@atdot.net>2019-05-28 10:31:02 +0900
commit7f211bfe6c5e4a763412406e5e257ea275ca53da (patch)
tree07bd1b57604c75249d3ff60e6d4b1bba42ac019f /gc.c
parentcfd839c140707852340a840e9e164e0f211fbb42 (diff)
use only eden_heaps on GC.compact.
`heap_pages_sorted` includes eden and tomb pages, so we should not use tomb pages for GC.compact (or we should move all of tomb pages into eden pages). Now, I choose only eden pages. If we allow to move Zombie objects (objects waiting for finalizers), we should use both type of pages (TODO).
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index c2695bbe3b..a633b6e5f9 100644
--- a/gc.c
+++ b/gc.c
@@ -7557,6 +7557,21 @@ compare_free_slots(const void *left, const void *right, void *dummy)
typedef int page_compare_func_t(const void *, const void *, void *);
+static struct heap_page **
+allocate_page_list(rb_objspace_t *objspace, page_compare_func_t *comparator)
+{
+ size_t n = heap_eden->total_pages;
+ struct heap_page *page, **page_list = calloc(n, sizeof(struct heap_page *));
+ int i = 0;
+
+ list_for_each(&heap_eden->pages, page, page_node) {
+ page_list[i++] = page;
+ }
+ ruby_qsort(page_list, n, sizeof(struct heap_page *), comparator, NULL);
+
+ return page_list;
+}
+
static VALUE
gc_compact_heap(rb_objspace_t *objspace, page_compare_func_t *comparator)
{
@@ -7569,9 +7584,7 @@ gc_compact_heap(rb_objspace_t *objspace, page_compare_func_t *comparator)
memset(objspace->rcompactor.considered_count_table, 0, T_MASK * sizeof(size_t));
memset(objspace->rcompactor.moved_count_table, 0, T_MASK * sizeof(size_t));
- page_list = calloc(heap_allocated_pages, sizeof(struct heap_page *));
- memcpy(page_list, heap_pages_sorted, heap_allocated_pages * sizeof(struct heap_page *));
- ruby_qsort(page_list, heap_allocated_pages, sizeof(struct heap_page *), comparator, NULL);
+ page_list = allocate_page_list(objspace, comparator);
init_cursors(objspace, &free_cursor, &scan_cursor, page_list);