From 8f77cfb308061ff49de0a47e82816c8dafa27963 Mon Sep 17 00:00:00 2001 From: tmm1 Date: Sun, 8 Dec 2013 02:28:04 +0000 Subject: [PATCH] gc.c: promote long-lived NODE_CREF objects to oldgen * include/ruby/ruby.h: add RGENGC_WB_PROTECTED_NODE_CREF setting In a large app, this reduces the size of remembered_shady_object_count by 80%. [Bug #9225] [ruby-core:58947] * gc.c (rb_node_newnode): add FL_WB_PROTECTED flag to NODE_CREF * class.c (rewrite_cref_stack): insert OBJ_WRITE for NODE_CREF * iseq.c (set_relation): ditto * iseq.c (rb_iseq_clone): ditto * vm_eval.c (rb_yield_refine_block): ditto * vm_insnhelper.c (vm_cref_push): ditto * vm_insnhelper.h (COPY_CREF): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ class.c | 2 +- gc.c | 3 ++- include/ruby/ruby.h | 3 +++ iseq.c | 6 +++--- vm_eval.c | 2 +- vm_insnhelper.c | 4 ++-- vm_insnhelper.h | 6 +++--- 8 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7765672839..2bc9327aef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sun Dec 8 11:21:00 2013 Aman Gupta + + * include/ruby/ruby.h: add RGENGC_WB_PROTECTED_NODE_CREF setting + In a large app, this reduces the size of + remembered_shady_object_count by 80%. [Bug #9225] [ruby-core:58947] + * gc.c (rb_node_newnode): add FL_WB_PROTECTED flag to NODE_CREF + * class.c (rewrite_cref_stack): insert OBJ_WRITE for NODE_CREF + * iseq.c (set_relation): ditto + * iseq.c (rb_iseq_clone): ditto + * vm_eval.c (rb_yield_refine_block): ditto + * vm_insnhelper.c (vm_cref_push): ditto + * vm_insnhelper.h (COPY_CREF): ditto + Sun Dec 8 10:45:05 2013 Aman Gupta * hash.c (hash_aset_str): revert r43870 due to performance issue diff --git a/class.c b/class.c index 7e036936b7..66495eb676 100644 --- a/class.c +++ b/class.c @@ -239,7 +239,7 @@ rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref while (node) { if (node->nd_clss == old_klass) { new_node = NEW_CREF(new_klass); - new_node->nd_next = node->nd_next; + OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next); *new_cref_ptr = new_node; return; } diff --git a/gc.c b/gc.c index b4b5466274..7f1a4983d9 100644 --- a/gc.c +++ b/gc.c @@ -1344,7 +1344,8 @@ rb_newobj_of(VALUE klass, VALUE flags) NODE* rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2) { - NODE *n = (NODE *)newobj_of(0, T_NODE, a0, a1, a2); + VALUE flags = (RGENGC_WB_PROTECTED_NODE_CREF && type == NODE_CREF ? FL_WB_PROTECTED : 0); + NODE *n = (NODE *)newobj_of(0, T_NODE | flags, a0, a1, a2); nd_set_type(n, type); return n; } diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 05c53fb838..9af062ec94 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -740,6 +740,9 @@ VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type); #ifndef RGENGC_WB_PROTECTED_BIGNUM #define RGENGC_WB_PROTECTED_BIGNUM 1 #endif +#ifndef RGENGC_WB_PROTECTED_NODE_CREF +#define RGENGC_WB_PROTECTED_NODE_CREF 1 +#endif struct RBasic { VALUE flags; diff --git a/iseq.c b/iseq.c index df1c16132f..469ae117c8 100644 --- a/iseq.c +++ b/iseq.c @@ -215,7 +215,7 @@ set_relation(rb_iseq_t *iseq, const VALUE parent) NODE *cref = NEW_CREF(th->top_wrapper); cref->nd_refinements = Qnil; cref->nd_visi = NOEX_PRIVATE; - cref->nd_next = iseq->cref_stack; + OBJ_WRITE(cref, &cref->nd_next, iseq->cref_stack); ISEQ_SET_CREF(iseq, cref); } iseq->local_iseq = iseq; @@ -1930,10 +1930,10 @@ rb_iseq_clone(VALUE iseqval, VALUE newcbase) } if (newcbase) { ISEQ_SET_CREF(iseq1, NEW_CREF(newcbase)); - iseq1->cref_stack->nd_refinements = iseq0->cref_stack->nd_refinements; + OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_refinements, iseq0->cref_stack->nd_refinements); iseq1->cref_stack->nd_visi = iseq0->cref_stack->nd_visi; if (iseq0->cref_stack->nd_next) { - iseq1->cref_stack->nd_next = iseq0->cref_stack->nd_next; + OBJ_WRITE(iseq1->cref_stack, &iseq1->cref_stack->nd_next, iseq0->cref_stack->nd_next); } OBJ_WRITE(iseq1, &iseq1->klass, newcbase); } diff --git a/vm_eval.c b/vm_eval.c index d3dbf2e581..903a6b7f04 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1546,7 +1546,7 @@ rb_yield_refine_block(VALUE refinement, VALUE refinements) } cref = vm_cref_push(th, refinement, NOEX_PUBLIC, blockptr); cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; - cref->nd_refinements = refinements; + OBJ_WRITE(cref, &cref->nd_refinements, refinements); return vm_yield_with_cref(th, 0, NULL, cref); } diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 05608fd159..28d0ea31c6 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -285,10 +285,10 @@ vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr) cref->nd_visi = noex; if (blockptr) { - cref->nd_next = vm_get_cref0(blockptr->iseq, blockptr->ep); + OBJ_WRITE(cref, &cref->nd_next, vm_get_cref0(blockptr->iseq, blockptr->ep)); } else if (cfp) { - cref->nd_next = vm_get_cref0(cfp->iseq, cfp->ep); + OBJ_WRITE(cref, &cref->nd_next, vm_get_cref0(cfp->iseq, cfp->ep)); } /* TODO: why cref->nd_next is 1? */ if (cref->nd_next && cref->nd_next != (void *) 1 && diff --git a/vm_insnhelper.h b/vm_insnhelper.h index c637407cbc..048fdc4e80 100644 --- a/vm_insnhelper.h +++ b/vm_insnhelper.h @@ -174,7 +174,7 @@ enum vm_regan_acttype { /**********************************************************/ #define COPY_CREF_OMOD(c1, c2) do { \ - (c1)->nd_refinements = (c2)->nd_refinements; \ + OBJ_WRITE((c1), &(c1)->nd_refinements, (c2)->nd_refinements); \ if (!NIL_P((c2)->nd_refinements)) { \ (c1)->flags |= NODE_FL_CREF_OMOD_SHARED; \ (c2)->flags |= NODE_FL_CREF_OMOD_SHARED; \ @@ -184,9 +184,9 @@ enum vm_regan_acttype { #define COPY_CREF(c1, c2) do { \ NODE *__tmp_c2 = (c2); \ COPY_CREF_OMOD(c1, __tmp_c2); \ - (c1)->nd_clss = __tmp_c2->nd_clss; \ + OBJ_WRITE((c1), &(c1)->nd_clss, __tmp_c2->nd_clss); \ (c1)->nd_visi = __tmp_c2->nd_visi;\ - (c1)->nd_next = __tmp_c2->nd_next; \ + OBJ_WRITE((c1), &(c1)->nd_next, __tmp_c2->nd_next); \ if (__tmp_c2->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { \ (c1)->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; \ } \