Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ruby part of TracePoint impl #4806

Closed

Conversation

olleolleolle
Copy link
Member

@olleolleolle olleolleolle commented Oct 5, 2017

This PR adds a Ruby implementation of the class method .trace to TracePoint.

The file is named after C impl file in MRI.

Fixes #4800

Questions for reviewer:

  • Do we want to have a full implementation of each of TracePoint methods?
  • Are there tests that I can re-enable, now?

  - file named after C impl file in MRI
@headius
Copy link
Member

headius commented Oct 5, 2017

Another question: does MRI trace the exit from the trace function? Since I suggested you do this in Ruby, that might be hard to avoid if not. Didn't even think of it until now.

@olleolleolle
Copy link
Member Author

olleolleolle commented Oct 5, 2017

@headius To answer your question with a "it seems so":

--- ruby/jruby ‹feature/4800-tracepoint-trace* ?› » JRUBY_OPTS=--debug irb -r ./vm_trace.rb
Ignoring byebug-9.0.6 because its extensions are not built.  Try: gem pristine byebug --version 9.0.6
irb(main):001:0> TracePoint.trace(:call) { |tp| puts tp.inspect }
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
=> #<TracePoint:enabled>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
#<TracePoint:call>
irb(main):002:0>
#<TracePoint:call>
#<TracePoint:call>

The last lines show me pressing Ctrl-D to leave the irb.

@olleolleolle
Copy link
Member Author

@headius Should we jettison this idea of using Ruby for a TracePoint patched implementation?

@headius
Copy link
Member

headius commented Oct 6, 2017

So here's the thing. It appears that MRI does trace the return from TracePoint.trace but it does so as a :c_return rather than a :return.

[] ~/projects/jruby $ ruby -e 'def bar; end; TracePoint.trace(:return) {|x| puts x.method_id }; puts :foo; bar'
foo
bar

[] ~/projects/jruby $ ruby -e 'def bar; end; TracePoint.trace(:c_return) {|x| puts x.method_id }; puts :foo; bar'
trace
to_s
foowrite

write
puts
puts

In JRuby, it's reversed, since we would implement it in Ruby instead of "C".

I'm not sure how important this is in practice. If there's logic that's attempting to hook only C methods, it will not see the return from trace. If there's logic that's attempting to hook only Ruby methods, it will see an unexpected return from trace.

Big deal? No big deal?

@headius
Copy link
Member

headius commented Oct 6, 2017

@olleolleolle I think we should just go with it and see what happens. Worst case we do a minor bit of porting and put it in Java.

As for tests, there might be something in spec/ruby but more likely there's a test excluded under test/mri/ruby/test_tracepoint.rb. The excludes are in test/mri/excludes with file path matching test class.

@headius
Copy link
Member

headius commented Oct 6, 2017

It might also be worth digging up any issue where this was added (in MRI) or opening a new one and clarifying with them how "spec" the :c_return vs :return is for cases like this.

@headius
Copy link
Member

headius commented Oct 9, 2017

Meh, I'm just going to use the Ruby version you provided to implement a Java version. I'm glad you got a chance to see how this fits together in JRuby, but we've already spent too long debating whether this minor difference is worth using Ruby for :-)

@headius headius closed this Oct 9, 2017
@enebo
Copy link
Member

enebo commented Oct 9, 2017

I said this on irc last week but I think semantically this should return :return if it is implemented in Ruby. Think of Rubinius/RubyTruffle or even MRI of the future where they start writing stuff in Ruby implwise (for inlining/JIT stuff). All this stuff will just change what they are implemented in. Any tests which return this as an error seems like an impl-specific test to me.

@headius
Copy link
Member

headius commented Oct 9, 2017

@enebo Yeah I never intended to tweak it so the Ruby version would do :c_return instead of :return. It's a minor difference, but it's also a five-minute patch to just write this in Java and moot the point.

@olleolleolle olleolleolle deleted the feature/4800-tracepoint-trace branch October 10, 2017 07:16
@kares kares added this to the Invalid or Duplicate milestone Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants