Skip to content

Commit

Permalink
use only eden_heaps on GC.compact.
Browse files Browse the repository at this point in the history
`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).
  • Loading branch information
ko1 committed May 28, 2019
1 parent cfd839c commit 7f211bf
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gc.c
Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down

0 comments on commit 7f211bf

Please sign in to comment.