Skip to content

Commit dc5e2ea

Browse files
committed
Refactor update_global_event_hook
It seems more readable to put JIT invalidation code together.
1 parent e377875 commit dc5e2ea

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

vm_trace.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,27 @@ update_global_event_hook(rb_event_flag_t prev_events, rb_event_flag_t new_events
9191
bool enable_c_call = (prev_events & RUBY_EVENT_C_CALL) == 0 && (new_events & RUBY_EVENT_C_CALL);
9292
bool enable_c_return = (prev_events & RUBY_EVENT_C_RETURN) == 0 && (new_events & RUBY_EVENT_C_RETURN);
9393

94+
// Modify ISEQs or CCs to enable tracing
9495
if (first_time_iseq_events_p) {
95-
// :class events are triggered only in ISEQ_TYPE_CLASS, but mjit_target_iseq_p ignores such iseqs.
96-
// Thus we don't need to cancel JIT-ed code for :class events.
97-
if (new_iseq_events != RUBY_EVENT_CLASS) {
98-
// Stop calling all JIT-ed code. We can't rewrite existing JIT-ed code to trace_ insns for now.
99-
mjit_cancel_all("TracePoint is enabled");
100-
}
101-
10296
// write all ISeqs only when new events are added for the first time
10397
rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events);
10498
}
105-
else {
106-
// if c_call or c_return is activated:
107-
if (enable_c_call || enable_c_return) {
108-
rb_clear_attr_ccs();
109-
}
99+
// if c_call or c_return is activated
100+
else if (enable_c_call || enable_c_return) {
101+
rb_clear_attr_ccs();
110102
}
111103

112104
ruby_vm_event_flags = new_events;
113105
ruby_vm_event_enabled_global_flags |= new_events;
114106
rb_objspace_set_event_hook(new_events);
115107

108+
// Invalidate JIT code as needed
109+
if (first_time_iseq_events_p && new_iseq_events != RUBY_EVENT_CLASS) {
110+
// Stop calling all JIT-ed code. We can't rewrite existing JIT-ed code to trace_ insns for now.
111+
// :class events are triggered only in ISEQ_TYPE_CLASS, but mjit_target_iseq_p ignores such iseqs.
112+
// Thus we don't need to cancel JIT-ed code for :class events.
113+
mjit_cancel_all("TracePoint is enabled");
114+
}
116115
if (first_time_iseq_events_p || enable_c_call || enable_c_return) {
117116
// Invalidate all code when ISEQs are modified to use trace_* insns above.
118117
// Also invalidate when enabling c_call or c_return because generated code

0 commit comments

Comments
 (0)