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

ruby-changes:69068

From: Aaron <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:44 +0900 (JST)
Subject: [ruby-changes:69068] 71cef74432 (master): Clear JIT code when tracepoints get enabled

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

From 71cef74432ef67edfd5635a9b9f8dffbbc33d392 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Mon, 19 Jul 2021 11:12:51 -0700
Subject: Clear JIT code when tracepoints get enabled

Clear out any JIT code on iseqs when tracepoints get enabled.  We can't
handle tracepoints right now, so we'll just try to recompile later.
---
 bootstraptest/test_yjit.rb | 42 ++++++++++++++++++++++++++++++++++++++++++
 iseq.c                     | 11 +++++++++++
 2 files changed, 53 insertions(+)

diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 0ca293f59a..9bce707cb5 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1,3 +1,45 @@ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_yjit.rb#L1
+# Check that global tracepoints work
+assert_equal 'true', %q{
+  def foo
+    1
+  end
+
+  foo
+  foo
+  foo
+
+  called = false
+
+  tp = TracePoint.new(:return) { |event|
+    if event.method_id == :foo
+      called = true
+    end
+  }
+  tp.enable
+  foo
+  tp.disable
+  called
+}
+
+# Check that local tracepoints work
+assert_equal 'true', %q{
+  def foo
+    1
+  end
+
+  foo
+  foo
+  foo
+
+  called = false
+
+  tp = TracePoint.new(:return) { |_| called = true }
+  tp.enable(target: method(:foo))
+  foo
+  tp.disable
+  called
+}
+
 # Make sure that optional param methods return the correct value
 assert_equal '1', %q{
   def m(ary = [])
diff --git a/iseq.c b/iseq.c
index 9432056f53..fe9ae59dad 100644
--- a/iseq.c
+++ b/iseq.c
@@ -3293,6 +3293,8 @@ rb_iseq_trace_flag_cleared(const rb_iseq_t *iseq, size_t pos) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3293
     encoded_iseq_trace_instrument(&iseq_encoded[pos], 0, false);
 }
 
+typedef VALUE (*jit_func_t)(struct rb_execution_context_struct *, struct rb_control_frame_struct *);
+
 static int
 iseq_add_local_tracepoint(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line)
 {
@@ -3303,6 +3305,11 @@ iseq_add_local_tracepoint(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, https://github.com/ruby/ruby/blob/trunk/iseq.c#L3305
 
     VM_ASSERT(ISEQ_EXECUTABLE_P(iseq));
 
+#if USE_MJIT
+    // Force write the jit function to NULL
+    *((jit_func_t *)(&body->jit_func)) = 0;
+#endif
+
     for (pc=0; pc<body->iseq_size;) {
         const struct iseq_insn_info_entry *entry = get_insn_info(iseq, pc);
         rb_event_flag_t pc_events = entry->events;
@@ -3438,6 +3445,10 @@ rb_iseq_trace_set(const rb_iseq_t *iseq, rb_event_flag_t turnon_events) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3445
             rb_event_flag_t pc_events = rb_iseq_event_flags(iseq, pc);
             pc += encoded_iseq_trace_instrument(&iseq_encoded[pc], pc_events & enabled_events, true);
 	}
+#if USE_MJIT
+        // Force write the jit function to NULL
+        *((jit_func_t *)(&body->jit_func)) = 0;
+#endif
     }
 }
 
-- 
cgit v1.2.1


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

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