ruby-changes:40263
From: ko1 <ko1@a...>
Date: Thu, 29 Oct 2015 15:17:19 +0900 (JST)
Subject: [ruby-changes:40263] ko1:r52344 (trunk): * gc.c: add rb_objspace::flags::has_hook to represent hook availability.
ko1 2015-10-29 15:17:07 +0900 (Thu, 29 Oct 2015) New Revision: 52344 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52344 Log: * gc.c: add rb_objspace::flags::has_hook to represent hook availability. * gc.c: add gc_event_hook_available_p(objspace) to check that flag. * gc.c (newobj_of): use gc_event_hook_available_p() instead of checking gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ). for performance. * gc.c (newobj_init): add UNLIKELY() for FL_WB_PROTECTED flag. * gc.c (newobj_init): change parameters order (trivial change). Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52343) +++ ChangeLog (revision 52344) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Oct 29 14:52:03 2015 Koichi Sasada <ko1@a...> + + * gc.c: add rb_objspace::flags::has_hook to represent hook availability. + + * gc.c: add gc_event_hook_available_p(objspace) to check that flag. + + * gc.c (newobj_of): use gc_event_hook_available_p() instead of + checking gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ). + for performance. + + * gc.c (newobj_init): add UNLIKELY() for FL_WB_PROTECTED flag. + + * gc.c (newobj_init): change parameters order (trivial change). + Thu Oct 29 14:45:15 2015 Nobuyoshi Nakada <nobu@r...> * vm_core.h (rb_thread_struct): move forward declarations before Index: gc.c =================================================================== --- gc.c (revision 52343) +++ gc.c (revision 52344) @@ -496,6 +496,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L496 unsigned int dont_incremental : 1; unsigned int during_gc : 1; unsigned int gc_stressful: 1; + unsigned int has_hook: 1; #if USE_RGENGC unsigned int during_minor_gc : 1; #endif @@ -1685,6 +1686,7 @@ rb_objspace_set_event_hook(const rb_even https://github.com/ruby/ruby/blob/trunk/gc.c#L1686 { rb_objspace_t *objspace = &rb_objspace; objspace->hook_events = event & RUBY_INTERNAL_EVENT_OBJSPACE_MASK; + objspace->flags.has_hook = (objspace->hook_events != 0); } static void @@ -1693,7 +1695,8 @@ gc_event_hook_body(rb_thread_t *th, rb_o https://github.com/ruby/ruby/blob/trunk/gc.c#L1695 EXEC_EVENT_HOOK(th, event, th->cfp->self, 0, 0, data); } -#define gc_event_hook_needed_p(objspace, event) ((objspace)->hook_events & (event)) +#define gc_event_hook_available_p(objspace) ((objspace)->flags.has_hook) +#define gc_event_hook_needed_p(objspace, event) (UNLIKELY((objspace)->hook_events & (event))) #define gc_event_hook(objspace, event, data) do { \ if (gc_event_hook_needed_p(objspace, event)) { \ @@ -1702,7 +1705,7 @@ 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(rb_objspace_t *objspace, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, VALUE obj, int hook_needed) +newobj_init(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace, VALUE obj, int hook_needed) { if (RGENGC_CHECK_MODE > 0) assert(BUILTIN_TYPE(obj) == T_NONE); @@ -1729,7 +1732,7 @@ newobj_init(rb_objspace_t *objspace, VAL https://github.com/ruby/ruby/blob/trunk/gc.c#L1732 #endif #if USE_RGENGC - if ((flags & FL_WB_PROTECTED) == 0) { + if (UNLIKELY((flags & FL_WB_PROTECTED) == 0)) { MARK_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), obj); } #endif @@ -1806,7 +1809,7 @@ newobj_slowpath(VALUE klass, VALUE flags https://github.com/ruby/ruby/blob/trunk/gc.c#L1809 } obj = heap_get_freeobj(objspace, heap_eden); - return newobj_init(objspace, klass, flags, v1, v2, v3, obj, gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ)); + return newobj_init(klass, flags, v1, v2, v3, objspace, obj, gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ)); } static inline VALUE @@ -1824,10 +1827,11 @@ newobj_of(VALUE klass, VALUE flags, VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L1827 } } #endif - - if (LIKELY(!(during_gc || ruby_gc_stressful) && gc_event_hook_needed_p(objspace, RUBY_INTERNAL_EVENT_NEWOBJ) == FALSE && + if (LIKELY(!(during_gc || + ruby_gc_stressful || + gc_event_hook_available_p(objspace)) && (obj = heap_get_freeobj_head(objspace, heap_eden)) != Qfalse)) { - return newobj_init(objspace, klass, flags, v1, v2, v3, obj, FALSE); + return newobj_init(klass, flags, v1, v2, v3, objspace, obj, FALSE); } else { return newobj_slowpath(klass, flags, v1, v2, v3, objspace); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/