summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-10-21 15:07:32 -0400
committerGitHub <noreply@github.com>2021-10-21 15:07:32 -0400
commitbdfc23cba9c7ade8f4528f38b19b0ea11c0d56c4 (patch)
treea0f2a8ac31ab070ddae0f13815ca71e7fb175868 /bootstraptest
parentd0cad8ad83a72455c35afc5300f090c7742af007 (diff)
YJIT: don't compile attr_accessor methods when tracing (#4998)
2d98593bf54a37397c6e4886ccc7e3654c2eaf85 made it so that attr_accessor methods fire C method tracing events. Previously, we weren't checking for whether we are tracing before compiling, leading to missed events. Since global invalidation invalidates all code, and that attr_accessor methods can never enable tracing while running, events are only dropped when YJIT tries to compile when tracing is already enabled. Factor out the code for checking tracing and check it before generating code for attr_accessor methods. This change fixes TestSetTraceFunc#test_tracepoint_attr when it's ran in isolation.
Notes
Notes: Merged-By: maximecb
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index a58ff2d18f..53cdcc69ac 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -2214,3 +2214,53 @@ assert_equal 'ok', %q{
:ok
}
+
+# regression test for tracing attr_accessor methods.
+assert_equal "true", %q{
+ c = Class.new do
+ attr_accessor :x
+ alias y x
+ alias y= x=
+ end
+ obj = c.new
+
+ ar_meth = obj.method(:x)
+ aw_meth = obj.method(:x=)
+ aar_meth = obj.method(:y)
+ aaw_meth = obj.method(:y=)
+ events = []
+ trace = TracePoint.new(:c_call, :c_return){|tp|
+ next if tp.path != __FILE__
+ next if tp.method_id == :call
+ case tp.event
+ when :c_call
+ events << [tp.event, tp.method_id, tp.callee_id]
+ when :c_return
+ events << [tp.event, tp.method_id, tp.callee_id, tp.return_value]
+ end
+ }
+ test_proc = proc do
+ obj.x = 1
+ obj.x
+ obj.y = 2
+ obj.y
+ aw_meth.call(1)
+ ar_meth.call
+ aaw_meth.call(2)
+ aar_meth.call
+ end
+ test_proc.call # populate call caches
+ trace.enable(&test_proc)
+ expected = [
+ [:c_call, :x=, :x=],
+ [:c_return, :x=, :x=, 1],
+ [:c_call, :x, :x],
+ [:c_return, :x, :x, 1],
+ [:c_call, :x=, :y=],
+ [:c_return, :x=, :y=, 2],
+ [:c_call, :x, :y],
+ [:c_return, :x, :y, 2],
+ ] * 2
+
+ expected == events
+}