Skip to content

Commit

Permalink
* gc.c: add rb_objspace::flags::has_hook to represent hook availability.
Browse files Browse the repository at this point in the history
* 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).




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Oct 29, 2015
1 parent 438f36d commit a3e8848
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Thu Oct 29 14:52:03 2015 Koichi Sasada <ko1@atdot.net>

* 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@ruby-lang.org>

* vm_core.h (rb_thread_struct): move forward declarations before
Expand Down
18 changes: 11 additions & 7 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ typedef struct rb_objspace {
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
Expand Down Expand Up @@ -1685,6 +1686,7 @@ rb_objspace_set_event_hook(const rb_event_flag_t event)
{
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
Expand All @@ -1693,7 +1695,8 @@ gc_event_hook_body(rb_thread_t *th, rb_objspace_t *objspace, const rb_event_flag
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)) { \
Expand All @@ -1702,7 +1705,7 @@ gc_event_hook_body(rb_thread_t *th, rb_objspace_t *objspace, const rb_event_flag
} 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);

Expand All @@ -1729,7 +1732,7 @@ newobj_init(rb_objspace_t *objspace, VALUE klass, VALUE flags, VALUE v1, VALUE v
#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
Expand Down Expand Up @@ -1806,7 +1809,7 @@ newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objsp
}

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
Expand All @@ -1824,10 +1827,11 @@ newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3)
}
}
#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);
Expand Down

0 comments on commit a3e8848

Please sign in to comment.