summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2023-09-03 17:02:57 -0700
committerJohn Hawthorn <john@hawthorn.email>2023-09-07 13:51:56 -0700
commit094f336a274ce83bc9868c7f9be0962b54ec46a7 (patch)
tree7d4291dc8d9fa0836a7f3c076aa671e054857e89 /gc.c
parentaed52151043561dbe9657abd07f1abfcd97df817 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8378
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/gc.c b/gc.c
index c71fdd10ed..d2cce59aac 100644
--- a/gc.c
+++ b/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);