mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
take VM lock when mutating the heap
This commit is contained in:
parent
193edbde91
commit
68a3a2d90f
1 changed files with 30 additions and 22 deletions
52
gc.c
52
gc.c
|
@ -8524,29 +8524,33 @@ gc_sort_heap_by_empty_slots(rb_execution_context_t *ec, VALUE self)
|
||||||
|
|
||||||
gc_rest(objspace);
|
gc_rest(objspace);
|
||||||
|
|
||||||
list_for_each(&heap_eden->pages, page, page_node) {
|
RB_VM_LOCK_ENTER();
|
||||||
page_list[i++] = page;
|
{
|
||||||
GC_ASSERT(page != NULL);
|
list_for_each(&heap_eden->pages, page, page_node) {
|
||||||
}
|
page_list[i++] = page;
|
||||||
GC_ASSERT(total_pages > 0);
|
GC_ASSERT(page != NULL);
|
||||||
GC_ASSERT((size_t)i == total_pages);
|
|
||||||
|
|
||||||
/* Sort the heap so "filled pages" are first. `heap_add_page` adds to the
|
|
||||||
* head of the list, so empty pages will end up at the start of the heap */
|
|
||||||
ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_free_slots, NULL);
|
|
||||||
|
|
||||||
/* Reset the eden heap */
|
|
||||||
list_head_init(&objspace->eden_heap.pages);
|
|
||||||
heap_eden->free_pages = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < total_pages; i++) {
|
|
||||||
list_add(&heap_eden->pages, &page_list[i]->page_node);
|
|
||||||
if (page_list[i]->free_slots != 0) {
|
|
||||||
heap_add_freepage(heap_eden, page_list[i]);
|
|
||||||
}
|
}
|
||||||
}
|
GC_ASSERT(total_pages > 0);
|
||||||
|
GC_ASSERT((size_t)i == total_pages);
|
||||||
|
|
||||||
free(page_list);
|
/* Sort the heap so "filled pages" are first. `heap_add_page` adds to the
|
||||||
|
* head of the list, so empty pages will end up at the start of the heap */
|
||||||
|
ruby_qsort(page_list, total_pages, sizeof(struct heap_page *), compare_free_slots, NULL);
|
||||||
|
|
||||||
|
/* Reset the eden heap */
|
||||||
|
list_head_init(&objspace->eden_heap.pages);
|
||||||
|
heap_eden->free_pages = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < total_pages; i++) {
|
||||||
|
list_add(&heap_eden->pages, &page_list[i]->page_node);
|
||||||
|
if (page_list[i]->free_slots != 0) {
|
||||||
|
heap_add_freepage(heap_eden, page_list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(page_list);
|
||||||
|
}
|
||||||
|
RB_VM_LOCK_LEAVE();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -8556,7 +8560,11 @@ gc_double_heap_size(rb_execution_context_t *ec, VALUE self)
|
||||||
{
|
{
|
||||||
rb_objspace_t *objspace = &rb_objspace;
|
rb_objspace_t *objspace = &rb_objspace;
|
||||||
|
|
||||||
heap_add_pages(objspace, heap_eden, heap_allocated_pages);
|
RB_VM_LOCK_ENTER();
|
||||||
|
{
|
||||||
|
heap_add_pages(objspace, heap_eden, heap_allocated_pages);
|
||||||
|
}
|
||||||
|
RB_VM_LOCK_LEAVE();
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue