ruby-changes:40265
From: ko1 <ko1@a...>
Date: Thu, 29 Oct 2015 16:26:56 +0900 (JST)
Subject: [ruby-changes:40265] ko1:r52346 (trunk): * gc.c: introduce rb_wb_unprotected_newobj_of() and
ko1 2015-10-29 16:26:44 +0900 (Thu, 29 Oct 2015) New Revision: 52346 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52346 Log: * gc.c: introduce rb_wb_unprotected_newobj_of() and rb_wb_protected_newobj_of(), pass the WB_PROTECTED information explicitly. * internal.h: use introduced functions by NEWOBJ_OF(). `flag' is immediate value, so that C compilers can solve them at compile time. * include/ruby/ruby.h: add a commnent about that. Modified files: trunk/ChangeLog trunk/gc.c trunk/include/ruby/ruby.h trunk/internal.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 52345) +++ include/ruby/ruby.h (revision 52346) @@ -765,7 +765,7 @@ VALUE rb_obj_setup(VALUE obj, VALUE klas https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L765 #define RB_NEWOBJ(obj,type) type *(obj) = (type*)rb_newobj() #define RB_NEWOBJ_OF(obj,type,klass,flags) type *(obj) = (type*)rb_newobj_of(klass, flags) #define NEWOBJ(obj,type) RB_NEWOBJ(obj,type) -#define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags) +#define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags) /* core has special NEWOBJ_OF() in internal.h */ #define OBJSETUP(obj,c,t) rb_obj_setup(obj, c, t) /* use NEWOBJ_OF instead of NEWOBJ()+OBJSETUP() */ #define CLONESETUP(clone,obj) rb_clone_setup(clone,obj) #define DUPSETUP(dup,obj) rb_dup_setup(dup,obj) Index: ChangeLog =================================================================== --- ChangeLog (revision 52345) +++ ChangeLog (revision 52346) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 29 16:20:26 2015 Koichi Sasada <ko1@a...> + + * gc.c: introduce rb_wb_unprotected_newobj_of() and + rb_wb_protected_newobj_of(), pass the WB_PROTECTED + information explicitly. + + * internal.h: use introduced functions by NEWOBJ_OF(). + `flag' is immediate value, so that C compilers can + solve them at compile time. + + * include/ruby/ruby.h: add a commnent about that. + Thu Oct 29 14:52:03 2015 Koichi Sasada <ko1@a...> * gc.c: add rb_objspace::flags::has_hook to represent hook availability. Index: gc.c =================================================================== --- gc.c (revision 52345) +++ gc.c (revision 52346) @@ -1705,12 +1705,15 @@ gc_event_hook_body(rb_thread_t *th, rb_o https://github.com/ruby/ruby/blob/trunk/gc.c#L1705 } while (0) static inline VALUE -newobj_init(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace, VALUE obj, int hook_needed) +newobj_init(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected, rb_objspace_t *objspace, VALUE obj, int hook_needed) { - if (RGENGC_CHECK_MODE > 0) assert(BUILTIN_TYPE(obj) == T_NONE); + if (RGENGC_CHECK_MODE > 0) { + assert(BUILTIN_TYPE(obj) == T_NONE); + assert((flags & FL_WB_PROTECTED) == 0); + } /* OBJSETUP */ - RBASIC(obj)->flags = flags & ~FL_WB_PROTECTED; + RBASIC(obj)->flags = flags; RBASIC_SET_CLASS_RAW(obj, klass); RANY(obj)->as.values.v1 = v1; RANY(obj)->as.values.v2 = v2; @@ -1732,13 +1735,13 @@ newobj_init(VALUE klass, VALUE flags, VA https://github.com/ruby/ruby/blob/trunk/gc.c#L1735 #endif #if USE_RGENGC - if (UNLIKELY((flags & FL_WB_PROTECTED) == 0)) { + if (UNLIKELY(wb_protected == FALSE)) { MARK_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), obj); } #endif #if RGENGC_PROFILE - if (flags & FL_WB_PROTECTED) { + if (wb_protected) { objspace->profile.total_generated_normal_object_count++; #if RGENGC_PROFILE >= 2 objspace->profile.generated_normal_object_count_types[BUILTIN_TYPE(obj)]++; @@ -1787,10 +1790,10 @@ newobj_init(VALUE klass, VALUE flags, VA https://github.com/ruby/ruby/blob/trunk/gc.c#L1790 return obj; } -NOINLINE(static VALUE newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace)); +NOINLINE(static VALUE newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected, rb_objspace_t *objspace)); static VALUE -newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace) +newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected, rb_objspace_t *objspace) { VALUE obj; @@ -1809,11 +1812,11 @@ newobj_slowpath(VALUE klass, VALUE flags https://github.com/ruby/ruby/blob/trunk/gc.c#L1812 } obj = heap_get_freeobj(objspace, heap_eden); - return newobj_init(klass, flags, v1, v2, v3, objspace, obj, gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ)); + return newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj, gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ)); } static inline VALUE -newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3) +newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected) { rb_objspace_t *objspace = &rb_objspace; VALUE obj; @@ -1831,30 +1834,41 @@ newobj_of(VALUE klass, VALUE flags, VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L1834 ruby_gc_stressful || gc_event_hook_available_p(objspace)) && (obj = heap_get_freeobj_head(objspace, heap_eden)) != Qfalse)) { - return newobj_init(klass, flags, v1, v2, v3, objspace, obj, FALSE); + return newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj, FALSE); } else { - return newobj_slowpath(klass, flags, v1, v2, v3, objspace); + return newobj_slowpath(klass, flags, v1, v2, v3, wb_protected, objspace); } } VALUE rb_newobj(void) { - return newobj_of(0, T_NONE, 0, 0, 0); + return newobj_of(0, T_NONE, 0, 0, 0, FALSE); +} + +VALUE +rb_wb_unprotected_newobj_of(VALUE klass, VALUE flags) +{ + return newobj_of(klass, flags, 0, 0, 0, FALSE); +} + +VALUE +rb_wb_protected_newobj_of(VALUE klass, VALUE flags) +{ + return newobj_of(klass, flags, 0, 0, 0, TRUE); } VALUE rb_newobj_of(VALUE klass, VALUE flags) { - return newobj_of(klass, flags, 0, 0, 0); + return newobj_of(klass, flags & ~FL_WB_PROTECTED, 0, 0, 0, flags & FL_WB_PROTECTED); } NODE* rb_node_newnode(enum node_type type, VALUE a0, VALUE a1, VALUE a2) { - VALUE flags = 0; - NODE *n = (NODE *)newobj_of(0, T_NODE | flags, a0, a1, a2); + NODE *n = (NODE *)newobj_of(0, T_NODE, a0, a1, a2, FALSE); /* TODO: node also should be wb protected */ nd_set_type(n, type); return n; } @@ -1865,7 +1879,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1879 rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0) { VALUE flags = T_IMEMO | (type << FL_USHIFT) | FL_WB_PROTECTED; - return newobj_of(v0, flags, v1, v2, v3); + return newobj_of(v0, flags, v1, v2, v3, TRUE); } #if IMEMO_DEBUG @@ -1882,7 +1896,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1896 rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) { if (klass) Check_Type(klass, T_CLASS); - return newobj_of(klass, T_DATA, (VALUE)dmark, (VALUE)dfree, (VALUE)datap); + return newobj_of(klass, T_DATA, (VALUE)dmark, (VALUE)dfree, (VALUE)datap, FALSE); } #undef rb_data_object_alloc @@ -1903,7 +1917,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L1917 rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type) { if (klass) Check_Type(klass, T_CLASS); - return newobj_of(klass, T_DATA | (type->flags & ~T_MASK), (VALUE)type, (VALUE)1, (VALUE)datap); + return newobj_of(klass, T_DATA, (VALUE)type, (VALUE)1, (VALUE)datap, type->flags & RUBY_FL_WB_PROTECTED); } #undef rb_data_typed_object_alloc Index: internal.h =================================================================== --- internal.h (revision 52345) +++ internal.h (revision 52346) @@ -814,6 +814,18 @@ void ruby_sized_xfree(void *x, size_t si https://github.com/ruby/ruby/blob/trunk/internal.h#L814 void rb_gc_resurrect(VALUE ptr); +VALUE rb_wb_protected_newobj_of(VALUE, VALUE); +VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE); + +/* optimized version of NEWOBJ() */ +#undef NEWOBJF_OF +#undef RB_NEWOBJ_OF +#define RB_NEWOBJ_OF(obj,type,klass,flags) \ + type *(obj) = (type*)(((flags) & FL_WB_PROTECTED) ? \ + rb_wb_protected_newobj_of(klass, (flags) & ~FL_WB_PROTECTED) : \ + rb_wb_unprotected_newobj_of(klass, flags)) +#define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags) + /* hash.c */ struct st_table *rb_hash_tbl_raw(VALUE hash); VALUE rb_hash_has_key(VALUE hash, VALUE key); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/