summaryrefslogtreecommitdiff
path: root/vm_trace.c
Commit message (Collapse)AuthorAgeFilesLines
* `vm_call_single_noarg_inline_builtin`Koichi Sasada2023-03-231-0/+10
| | | | | | | | If the iseq only contains `opt_invokebuiltin_delegate_leave` insn and the builtin-function (bf) is inline-able, the caller doesn't need to build a method frame. `vm_call_single_noarg_inline_builtin` is fast path for such cases.
* s/mjit/rjit/Takashi Kokubun2023-03-061-3/+3
|
* Stop exporting symbols for MJITTakashi Kokubun2023-03-061-1/+1
|
* Encapsulate RCLASS_ATTACHED_OBJECTJean Boussier2023-02-151-1/+2
| | | | | | | | | Right now the attached object is stored as an instance variable and all the call sites that either get or set it have to know how it's stored. It's preferable to hide this implementation detail behind accessors so that it is easier to change how it's stored.
* Make all of the references of iseq movablePeter Zhu2023-01-201-0/+11
|
* Fix crash in TracePoint c_call for removed methodPeter Zhu2023-01-041-1/+1
| | | | | | | | trace_arg->id is the ID of the original method of an aliased method. If the original method is removed, then the lookup will fail. We should use trace_arg->called_id instead, which is the ID of the aliased method. Fixes [Bug #19305]
* MJIT: Cancel all on disastrous situations (#7019)Takashi Kokubun2022-12-241-6/+2
| | | | | | | | | | I noticed this while running test_yjit with --mjit-call-threshold=1, which redefines `Integer#<`. When Ruby is monkey-patched, MJIT itself could be broken. Similarly, Ruby scripts could break MJIT in many different ways. I prepared the same set of hooks as YJIT so that we could possibly override it and disable it on those moments. Every constant under RubyVM::MJIT is private and thus it's an unsupported behavior though.
* Make sure TracePoint#binding returns nil for c_call/c_return eventsJeremy Evans2022-12-211-0/+5
| | | | This makes sure the method returns nil for these events, as described in NEWS, even if the TracePoint could create a binding.
* Using UNDEF_P macroS-H-GAMELINKS2022-11-161-7/+7
|
* Refactor update_global_event_hookTakashi Kokubun2022-11-131-12/+11
| | | | It seems more readable to put JIT invalidation code together.
* YJIT: Fix invalidation for c_call and c_return (#6719)Alan Wu2022-11-131-6/+9
| | | | | | | | | | | Follow-up for 2b8191bdad7545b71f270d2b25a34cd2b3afa02f. Since that commit, we stopped doing code invalidation the second time the call and return events are enabled. We need to do it every time these events are enabled because we might have generated code while these events are disabled. Also rename locals and edit comments to make it more clear that the iseq rewrite code path only happens the first time a particular iseq trace event is enabled.
* YJIT: Invalidate JIT code only for ISEQ_TRACE_EVENTS (#6695)Takashi Kokubun2022-11-101-4/+6
|
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-209/+209
| | | | [Misc #18891]
* Fix infinite loop when b_return TracePoint throwsAlan Wu2022-06-221-0/+1
| | | | | | | | | Previously, we didn't pop the frame that runs the TracePoint hook for b_return events for blocks running as methods (bmethods). In case the hook raises, that formed an infinite loop during stack unwinding in hook_before_rewind(). [Bug #18060]
* Fix nested bmethod TracePoint and memory leakAlan Wu2022-06-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | df317151a5b4e0c5a30fcc321a9dc6abad63f7ed removed the code to free rb_hook_list_t, so repeated targeting of the same bmethod started to leak the hook list. You can observe how the maximum memory use scales with input size in the following script with `/usr/bin/time -v`. ```ruby o = Object.new o.define_singleton_method(:foo) {} trace = TracePoint.new(:return) {} bmethod = o.method(:foo) ARGV.first.to_i.times { trace.enable(target:bmethod){} } 4.times {GC.start} ``` After this change the maximum doesn't grow as quickly. To plug the leak, check whether the hook list is already allocated when enabling the targeting TracePoint for the bmethod. This fix also allows multiple TracePoints to target the same bmethod, similar to other valid TracePoint targets. Finally, free the rb_hook_list_t struct when freeing the method definition it lives on. Freeing in the GC is a good way to avoid lifetime problems similar to the one fixed in df31715. [Bug #18031]
* Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans2022-04-061-2/+8
| | | | | | | | | Check whether the current or previous frame is a Ruby frame in call_trace_func and rb_tracearg_binding before attempting to create a binding for the frame. Fixes [Bug #18487] Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
* Revert "Raise RuntimeError if Kernel#binding is called from a non-Ruby frame"Jeremy Evans2022-04-011-8/+1
| | | | | | This reverts commit 343ea9967e4a6b279eed6bd8e81ad0bdc747f254. This causes an assertion failure with -DRUBY_DEBUG=1 -DRGENGC_CHECK_MODE=2
* Prefix ccan headers (#4568)Nobuyoshi Nakada2022-03-301-10/+10
| | | | | | | | | | | | | * Prefixed ccan headers * Remove unprefixed names in ccan/build_assert * Remove unprefixed names in ccan/check_type * Remove unprefixed names in ccan/container_of * Remove unprefixed names in ccan/list Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
* Avoid trace events in implementation of TracePoint#enableJeremy Evans2022-03-291-0/+13
| | | | | | | | | This is more backwards compatible, and should fix issues with power_assert. Unfortunately, it requires using a sentinel value as the default value of target_thread, instead of the more natural expression used in the original approach.
* Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans2022-03-241-1/+8
| | | | | | | | | Check whether the current or previous frame is a Ruby frame in call_trace_func before attempting to create a binding for the frame. Fixes [Bug #18487] Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
* Fix error: old-style function definitionKazuhiro NISHIYAMA2022-01-221-1/+1
| | | | | | | | | | | https://rubyci.s3.amazonaws.com/debian-riscv64/ruby-master/log/20220122T050018Z.log.html.gz#miniruby ``` compiling vm_trace.c vm_trace.c: In function 'rb_vm_memsize_postponed_job_buffer': vm_trace.c:1599:1: error: old-style function definition [-Werror=old-style-definition] 1599 | rb_vm_memsize_postponed_job_buffer() | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
* Accurately report VM memsizeKevin Newton2022-01-211-0/+23
| | | | | | Currently the calculation only counts the size of the struct. This commit adds the size of the associated st tables, id tables, and linked lists. Still missing is the size of the ractors and (potentially) the size of the object space.
* fix local TP memory leakKoichi Sasada2021-12-151-14/+23
| | | | | | | It free `rb_hook_list_t` itself if needed. To recognize the need, this patch introduced `rb_hook_list_t::is_local` flag. This patch is succession of https://github.com/ruby/ruby/pull/4652
* reduce `rb_clear_attr_ccs()` callKoichi Sasada2021-12-141-10/+15
| | | | | `rb_clear_attr_ccs()` should be called only when c_call or c_return is activated.
* `TracePoint.allow_reentry`Koichi Sasada2021-12-101-0/+19
| | | | | | | | | | | | | In general, while TracePoint callback is running, other registerred callbacks are not called to avoid confusion by reentrace. This method allow the reentrace. This method should be used carefully, otherwize the callback can be easily called infinitely. [Feature #15912] Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
* Rework tracing for blocks running as methodsAlan Wu2021-12-011-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The main impetus for this change is to fix [Bug #13392]. Previously, we fired the "return" TracePoint event after popping the stack frame for the block running as method (BMETHOD). This gave undesirable source location outputs as the return event normally fires right before the frame going away. The iseq for each block can run both as a block and as a method. To accommodate that, this commit makes vm_trace() fire call/return events for instructions that have b_call/b_return events attached when the iseq is running as a BMETHOD. The logic for rewriting to "trace_*" instruction is tweaked so that when the user listens to call/return events, instructions with b_call/b_return become trace variants. To continue to provide the return value for non-local returns done using the "return" or "break" keyword inside BMETHODs, the stack unwinding code is tweaked. b_return events now provide the same return value as return events for these non-local cases. A pre-existing test deemed not providing a return value for these b_return events as a limitation. This commit removes the checks for call/return TracePoint events that happen when calling into BMETHODs when no TracePoints are active. Technically, migrating just the return event is enough to fix the bug, but migrating both call and return removes our reliance on `VM_FRAME_FLAG_FINISH` and re-entering the interpreter when the caller is already in the interpreter.
* Avoid assert failure when NULL EC is expectedAlan Wu2021-11-221-1/+1
| | | | | | | | | | | | | | | | | | | After 5680c38c75aeb5cbd219aafa8eb48c315f287d97, postponed job APIs now expect to be called on native threads not managed by Ruby and handles getting a NULL execution context. However, in debug builds the change runs into an assertion failure with GET_EC() which asserts that EC is non-NULL. Avoid the assertion failure by passing `false` for `expect_ec` instead as the intention is to handle when there is no EC. Add a test from John Crepezzi and John Hawthorn to exercise this situation. See GH-4108 See GH-5094 [Bug #17573] Co-authored-by: John Hawthorn <john@hawthorn.email> Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
* Use valid `ec` for postponed job.Koichi Sasada2021-11-091-4/+12
| | | | | | | | Postponed job can be registered from non-Ruby thread, which means `ec` in TLS can be NULL. In this case, use main thread's `ec` instead. See https://github.com/ruby/ruby/pull/4108 and https://github.com/ruby/ruby/pull/4336
* [Bug #18264] Fix memory leak in TracePointPeter Zhu2021-10-261-1/+1
| | | | | TracePoint leaks memory because it allocates a `rb_tp_t` struct without ever freeing it (it is created with `RUBY_TYPED_NEVER_FREE`).
* Put YJIT into a single compilation unitAlan Wu2021-10-201-2/+2
| | | | | | | | | | | | | | | | | | | | | For upstreaming, we want functions we export either prefixed with "rb_" or made static. Historically we haven't been following this rule, so we were "leaking" a lot of symbols as `make leak-globals` would tell us. This change unifies everything YJIT into a single compilation unit, yjit.o, and makes everything unprefixed static to pass `make leak-globals`. This manual "unified build" setup is similar to that of vm.o. Having everything in one compilation unit allows static functions to be visible across YJIT files and removes the need for declarations in headers in some cases. Unnecessary declarations were removed. Other changes of note: - switched to MJIT_SYMBOL_EXPORT_BEGIN which indicates stuff as being off limits for native extensions - the first include of each YJIT file is change to be "internal.h" - undefined MAP_STACK before explicitly redefining it since it collide's with a definition in system headers. Consider renaming?
* filter out internal events. add comments. reorderAlan Wu2021-10-201-2/+7
|
* TracePoint supportAlan Wu2021-10-201-0/+5
| | | | | | | | | | | | | | | | | | | | | | This change fixes some cases where YJIT fails to fire tracing events. Most of the situations YJIT did not handle correctly involves enabling tracing while running inside generated code. A new operation to invalidate all generated code is added, which uses patching to make generated code exit at the next VM instruction boundary. A new routine called `jit_prepare_routine_call()` is introduced to facilitate this and should be used when generating code that could allocate, or could otherwise use `RB_VM_LOCK_ENTER()`. The `c_return` event is fired in the middle of an instruction as opposed to at an instruction boundary, so it requires special handling. C method call return points are patched to go to a fucntion which does everything the interpreter does, including firing the `c_return` event. The generated code for C method calls normally does not fire the event. Invalided code should not change after patching so the exits are not clobbered. A new variable is introduced to track the region of code that should not change.
* Refactor rb_add_event_hook functionS-H-GAMELINKS2021-09-291-2/+1
|
* include/ruby/debug.h: add doxygen卜部昌平2021-09-101-30/+0
| | | | Must not be a bad idea to improve documents. [ci skip]
* Support tracing of attr_reader and attr_writerJeremy Evans2021-08-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | In vm_call_method_each_type, check for c_call and c_return events before dispatching to vm_call_ivar and vm_call_attrset. With this approach, the call cache will still dispatch directly to those functions, so this change will only decrease performance for the first (uncached) call, and even then, the performance decrease is very minimal. This approach requires that we clear the call caches when tracing is enabled or disabled. The approach currently switches all vm_call_ivar and vm_call_attrset call caches to vm_call_general any time tracing is enabled or disabled. So it could theoretically result in a slowdown for code that constantly enables or disables tracing. This approach does not handle targeted tracepoints, but from my testing, c_call and c_return events are not supported for targeted tracepoints, so that shouldn't matter. This includes a benchmark showing the performance decrease is minimal if detectable at all. Fixes [Bug #16383] Fixes [Bug #10470] Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
* Don't cancel JIT-ed code on TracePoint :classTakashi Kokubun2021-08-121-2/+6
| | | | events get enabled
* Print JIT cancel when all JIT-ed code is cancelledTakashi Kokubun2021-08-121-4/+2
|
* Using RBOOL macroS.H2021-08-021-3/+3
|
* Adjust styles [ci skip]Nobuyoshi Nakada2021-06-171-1/+1
| | | | | | | | | * --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
* Document binding behavior for C call/return events for TracePoint/set_trace_funcJeremy Evans2021-04-261-0/+4
| | | | | | | C methods do not have bindings, so binding returns the binding of the nearest C method. Fixes [Bug #9009]
* Replace "iff" with "if and only if"Gannon McGibbon2021-01-191-1/+1
| | | | | | | iff means if and only if, but readers without that knowledge might assume this to be a spelling mistake. To me, this seems like exclusionary language that is unnecessary. Simply using "if and only if" instead should suffice.
* separate rb_ractor_pub from rb_ractor_tKoichi Sasada2020-12-221-0/+1
| | | | | | | | | separate some fields from rb_ractor_t to rb_ractor_pub and put it at the beggining of rb_ractor_t and declare it in vm_core.h so vm_core.h can access rb_ractor_pub fields. Now rb_ec_ractor_hooks() is a complete inline function and no MJIT related issue.
* TracePoint.new(&block) should be ractor-localKoichi Sasada2020-12-221-7/+11
| | | | | TracePoint should be ractor-local because the Proc can violate the Ractor-safe.
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-1/+2
| | | | | | | | | | | | | | | | This commit introduces Ractor mechanism to run Ruby program in parallel. See doc/ractor.md for more details about Ractor. See ticket [Feature #17100] to see the implementation details and discussions. [Feature #17100] This commit does not complete the implementation. You can find many bugs on using Ractor. Also the specification will be changed so that this feature is experimental. You will see a warning when you make the first Ractor with `Ractor.new`. I hope this feature can help programmers from thread-safety issues.
* [Feature #16513] TracePoint#inspect returns "... file:line" (#3391)Nguyễn Quang Minh2020-08-061-3/+3
| | | | | | | | | * Fix debug documents to match Thread#to_s change (Feature #16412 ticket) * TracePoint#inspect returns "... file:line" (Feature #16513) * Guard older version of Ruby in Tracepoint inspection tests * Focus on current thread only when running TracePoint inspection test
* tracepoint_inspect: do not goto into a branch卜部昌平2020-06-291-6/+6
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* Clear all trace events during teardownAlan Wu2020-03-291-0/+6
| | | | | | | | | | | Since 0c2d81dada, not all trace events are cleared during VM teardown. This causes a crash when there is a tracepoint for `RUBY_INTERNAL_EVENT_GC_EXIT` active during teardown. The commit looks like a refactoring commit so I think this change was unintentional. [Bug #16682]
* rb_vm_t::postponed_job_index shall be rb_atomic_t卜部昌平2020-02-061-3/+3
| | | | | Pointer to this field is passed to ATOMIC_CAS. We have to use rb_atomic_t for that purpose.
* Separate builtin initialization callsNobuyoshi Nakada2019-12-291-2/+0
|
* decouple internal.h headers卜部昌平2019-12-261-4/+6
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).