[前][次][番号順一覧][スレッド一覧]

ruby-changes:70198

From: Koichi <ko1@a...>
Date: Tue, 14 Dec 2021 12:32:11 +0900 (JST)
Subject: [ruby-changes:70198] 1578421962 (master): reduce `rb_clear_attr_ccs()` call

https://git.ruby-lang.org/ruby.git/commit/?id=1578421962

From 1578421962024f7fafc94418da9e1ecab31c49b2 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 14 Dec 2021 10:24:27 +0900
Subject: reduce `rb_clear_attr_ccs()` call

`rb_clear_attr_ccs()` should be called only when c_call or c_return
is activated.
---
 vm_trace.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/vm_trace.c b/vm_trace.c
index f1c0bb2598d..3f589d3778d 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -78,9 +78,9 @@ rb_hook_list_free(rb_hook_list_t *hooks) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L78
 void rb_clear_attr_ccs(void);
 
 static void
-update_global_event_hook(rb_event_flag_t vm_events)
+update_global_event_hook(rb_event_flag_t prev_events, rb_event_flag_t new_events)
 {
-    rb_event_flag_t new_iseq_events = vm_events & ISEQ_TRACE_EVENTS;
+    rb_event_flag_t new_iseq_events = new_events & ISEQ_TRACE_EVENTS;
     rb_event_flag_t enabled_iseq_events = ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS;
 
     if (new_iseq_events & ~enabled_iseq_events) {
@@ -95,14 +95,18 @@ update_global_event_hook(rb_event_flag_t vm_events) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L95
 	rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events);
     }
     else {
-        rb_clear_attr_ccs();
+        // if c_call or c_return is activated:
+        if (((prev_events & RUBY_EVENT_C_CALL)   == 0 && (new_events & RUBY_EVENT_C_CALL)) ||
+            ((prev_events & RUBY_EVENT_C_RETURN) == 0 && (new_events & RUBY_EVENT_C_RETURN))) {
+            rb_clear_attr_ccs();
+        }
     }
 
-    ruby_vm_event_flags = vm_events;
-    ruby_vm_event_enabled_global_flags |= vm_events;
-    rb_objspace_set_event_hook(vm_events);
+    ruby_vm_event_flags = new_events;
+    ruby_vm_event_enabled_global_flags |= new_events;
+    rb_objspace_set_event_hook(new_events);
 
-    if (vm_events & RUBY_EVENT_TRACEPOINT_ALL) {
+    if (new_events & RUBY_EVENT_TRACEPOINT_ALL) {
         // Invalidate all code if listening for any TracePoint event.
         // Internal events fire inside C routines so don't need special handling.
         // Do this last so other ractors see updated vm events when they wake up.
@@ -137,13 +141,14 @@ alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L141
 static void
 hook_list_connect(VALUE list_owner, rb_hook_list_t *list, rb_event_hook_t *hook, int global_p)
 {
+    rb_event_flag_t prev_events = list->events;
     hook->next = list->hooks;
     list->hooks = hook;
     list->events |= hook->events;
 
     if (global_p) {
         /* global hooks are root objects at GC mark. */
-        update_global_event_hook(list->events);
+        update_global_event_hook(prev_events, list->events);
     }
     else {
         RB_OBJ_WRITTEN(list_owner, Qundef, hook->data);
@@ -196,7 +201,7 @@ clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L201
 {
     rb_event_hook_t *hook, **nextp = &list->hooks;
     VM_ASSERT(list->need_clean == TRUE);
-
+    rb_event_flag_t prev_events = list->events;
     list->events = 0;
     list->need_clean = FALSE;
 
@@ -213,7 +218,7 @@ clean_hooks(const rb_execution_context_t *ec, rb_hook_list_t *list) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L218
 
     if (list == rb_ec_ractor_hooks(ec)) {
         /* global events */
-        update_global_event_hook(list->events);
+        update_global_event_hook(prev_events, list->events);
     }
     else {
         /* local events */
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]