ruby-changes:55716
From: Aaron <ko1@a...>
Date: Tue, 14 May 2019 06:56:56 +0900 (JST)
Subject: [ruby-changes:55716] Aaron Patterson: a1ecf07dff (trunk): turn T_MOVED in to a linked list
https://git.ruby-lang.org/ruby.git/commit/?id=a1ecf07dff From a1ecf07dff7530f8f53fb456b2e38a8a039cb561 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Thu, 9 May 2019 15:04:35 -0700 Subject: turn T_MOVED in to a linked list diff --git a/gc.c b/gc.c index 55af437..bd00824 100644 --- a/gc.c +++ b/gc.c @@ -7312,8 +7312,8 @@ update_id_to_obj(st_data_t *key, st_data_t *value, st_data_t arg, int exists) https://github.com/ruby/ruby/blob/trunk/gc.c#L7312 } } -static void -gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free) +static VALUE +gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free, VALUE moved_list) { int marked; int wb_unprotected; @@ -7392,7 +7392,10 @@ gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free) https://github.com/ruby/ruby/blob/trunk/gc.c#L7392 /* Assign forwarding address */ src->as.moved.flags = T_MOVED; src->as.moved.destination = (VALUE)dest; + src->as.moved.next = moved_list; GC_ASSERT(BUILTIN_TYPE((VALUE)dest) != T_NONE); + + return (VALUE)src; } struct heap_cursor { @@ -7489,13 +7492,15 @@ int compare_pinned(const void *left, const void *right, void *dummy) https://github.com/ruby/ruby/blob/trunk/gc.c#L7492 return right_count - left_count; } -static void +static VALUE gc_compact_heap(rb_objspace_t *objspace) { struct heap_cursor free_cursor; struct heap_cursor scan_cursor; struct heap_page **page_list; + VALUE moved_list; + moved_list = Qfalse; memset(objspace->rcompactor.considered_count_table, 0, T_MASK * sizeof(size_t)); memset(objspace->rcompactor.moved_count_table, 0, T_MASK * sizeof(size_t)); @@ -7558,7 +7563,7 @@ gc_compact_heap(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L7563 GC_ASSERT(BUILTIN_TYPE(scan_cursor.slot) != T_NONE); GC_ASSERT(BUILTIN_TYPE(scan_cursor.slot) != T_MOVED); - gc_move(objspace, (VALUE)scan_cursor.slot, (VALUE)free_cursor.slot); + moved_list = gc_move(objspace, (VALUE)scan_cursor.slot, (VALUE)free_cursor.slot, moved_list); GC_ASSERT(BUILTIN_TYPE(free_cursor.slot) != T_MOVED); GC_ASSERT(BUILTIN_TYPE(free_cursor.slot) != T_NONE); @@ -7569,6 +7574,8 @@ gc_compact_heap(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L7574 } } free(page_list); + + return moved_list; } static void @@ -8195,13 +8202,17 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L8202 gc_verify_compaction_references(VALUE mod) { rb_objspace_t *objspace = &rb_objspace; + VALUE moved_list; if (dont_gc) return Qnil; /* Ensure objects are pinned */ rb_gc(); - gc_compact_heap(objspace); + /* Double heap size */ + heap_add_pages(objspace, heap_eden, heap_allocated_pages); + + moved_list = gc_compact_heap(objspace); heap_eden->freelist = NULL; gc_update_references(objspace); @@ -8214,6 +8225,14 @@ gc_verify_compaction_references(VALUE mod) https://github.com/ruby/ruby/blob/trunk/gc.c#L8225 gc_verify_internal_consistency(mod); +#if __has_feature(address_sanitizer) + while (moved_list) { + VALUE current = moved_list; + moved_list = RANY(moved_list)->as.moved.next; + poison_object(current); + } +#endif + /* GC after compaction to eliminate T_MOVED */ rb_gc(); diff --git a/internal.h b/internal.h index 0ce1dcd..4d3a506 100644 --- a/internal.h +++ b/internal.h @@ -838,6 +838,7 @@ struct RHash { https://github.com/ruby/ruby/blob/trunk/internal.h#L838 struct RMoved { VALUE flags; VALUE destination; + VALUE next; }; /* missing/setproctitle.c */ -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/