From b84f7fda07a8e7bfad80a9faae69f071b736f144 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 24 May 2013 06:52:38 +0000 Subject: * gc.c (after_gc_sweep, garbage_collect_body): do major GC (full GC) before extending heaps. TODO: do major GC when there are many old (promoted) objects. * gc.c (after_gc_sweep): remove TODO comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- gc.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'gc.c') diff --git a/gc.c b/gc.c index 81ac411403..65232b0df7 100644 --- a/gc.c +++ b/gc.c @@ -352,6 +352,11 @@ typedef struct rb_objspace { struct { int during_minor_gc; int parent_object_is_promoted; + /* need_major_gc is setting at: + * * free_num < free_min @ after_gc_sweep() + */ + int need_major_gc; + int done_major_gc; /* for check mode */ VALUE parent_object; @@ -2247,8 +2252,14 @@ after_gc_sweep(rb_objspace_t *objspace) objspace->heap.free_num, objspace->heap.free_min); if (objspace->heap.free_num < objspace->heap.free_min) { - set_heaps_increment(objspace); - heaps_increment(objspace); + if (has_free_object && objspace->rgengc.done_major_gc == FALSE) { + objspace->rgengc.need_major_gc = TRUE; + } + else { + objspace->rgengc.done_major_gc = FALSE; + set_heaps_increment(objspace); + heaps_increment(objspace); + } } inc = ATOMIC_SIZE_EXCHANGE(malloc_increase, 0); @@ -2315,10 +2326,9 @@ gc_sweep(rb_objspace_t *objspace, int immediate_sweep) } if (!has_free_object) { - /* there is no freespace after slot_sweep() */ - /* TODO: [RGENGC] Should do major GC before adding hepas */ + /* there is no free after slot_sweep() */ set_heaps_increment(objspace); - if (!heaps_increment(objspace)) { + if (!heaps_increment(objspace)) { /* can't allocate additional free objects */ during_gc = 0; rb_memerror(); } @@ -3689,7 +3699,7 @@ garbage_collect_body(rb_objspace_t *objspace, int full_mark, int immediate_sweep int minor_gc; if (ruby_gc_stress && !ruby_disable_gc_stress) { - minor_gc = TRUE; + minor_gc = FALSE; immediate_sweep = TRUE; } else { @@ -3697,8 +3707,14 @@ garbage_collect_body(rb_objspace_t *objspace, int full_mark, int immediate_sweep minor_gc = FALSE; } else { - /* TODO: count old object size and so on */ - minor_gc = TRUE; + if (objspace->rgengc.need_major_gc) { + objspace->rgengc.done_major_gc = TRUE; + objspace->rgengc.need_major_gc = FALSE; + minor_gc = FALSE; + } + else { + minor_gc = TRUE; + } } } -- cgit v1.2.3