зеркало из https://github.com/github/ruby.git
GC: Only force alloc slowpath for NEWOBJ hook
Previously, configuring any GC event hook would cause all allocations to go through the newobj slowpath. We should only need to do that when the newobj specifically is subscribed to. This renames flags.has_hook to flags.has_newobj_hook, to make this new usage clear. newobj_of0 was the only place which previously checked this flag.
This commit is contained in:
Родитель
aed5215104
Коммит
094f336a27
8
gc.c
8
gc.c
|
@ -747,7 +747,7 @@ typedef struct rb_objspace {
|
|||
unsigned int during_compacting : 1;
|
||||
unsigned int during_reference_updating : 1;
|
||||
unsigned int gc_stressful: 1;
|
||||
unsigned int has_hook: 1;
|
||||
unsigned int has_newobj_hook: 1;
|
||||
unsigned int during_minor_gc : 1;
|
||||
unsigned int during_incremental_marking : 1;
|
||||
unsigned int measure_gc : 1;
|
||||
|
@ -2466,7 +2466,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);
|
||||
objspace->flags.has_newobj_hook = !!(objspace->hook_events & RUBY_INTERNAL_EVENT_NEWOBJ);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2476,7 +2476,7 @@ gc_event_hook_body(rb_execution_context_t *ec, rb_objspace_t *objspace, const rb
|
|||
EXEC_EVENT_HOOK(ec, event, ec->cfp->self, 0, 0, 0, data);
|
||||
}
|
||||
|
||||
#define gc_event_hook_available_p(objspace) ((objspace)->flags.has_hook)
|
||||
#define gc_event_newobj_hook_needed_p(objspace) ((objspace)->flags.has_newobj_hook)
|
||||
#define gc_event_hook_needed_p(objspace, event) ((objspace)->hook_events & (event))
|
||||
|
||||
#define gc_event_hook_prep(objspace, event, data, prep) do { \
|
||||
|
@ -2836,7 +2836,7 @@ newobj_of0(VALUE klass, VALUE flags, int wb_protected, rb_ractor_t *cr, size_t a
|
|||
|
||||
if (!UNLIKELY(during_gc ||
|
||||
ruby_gc_stressful ||
|
||||
gc_event_hook_available_p(objspace)) &&
|
||||
gc_event_newobj_hook_needed_p(objspace)) &&
|
||||
wb_protected) {
|
||||
obj = newobj_alloc(objspace, cr, size_pool_idx, false);
|
||||
newobj_init(klass, flags, wb_protected, objspace, obj);
|
||||
|
|
Загрузка…
Ссылка в новой задаче