summaryrefslogtreecommitdiff
path: root/vm_trace.c
AgeCommit message (Collapse)Author
2025-12-16Make tracepoints with set_trace_func or TracePoint.new ractor local (#15468)Luke Gruber
Before this change, GC'ing any Ractor object caused you to lose all enabled tracepoints across all ractors (even main). Now tracepoints are ractor-local and this doesn't happen. Internal events are still global. Fixes [Bug #19112]
2025-12-08Register internal tracepoints globallyJohn Hawthorn
Internal tracepoints only make sense to run globally, and they already took completely different paths.
2025-12-08Only globally clear the flag being clearedJohn Hawthorn
This solution is not quite correct because it doesn't solve multiple Ractors subscribing to the same event, but this will avoid unrelated events clobbering the flags for other events. This however will work corretly for subscribing to global ObjectSpace GC events.
2025-10-30specific traces can be unshareableKoichi Sasada
2025-09-02ZJIT: Clear jit entry from iseqs after TracePoint activation (#14407)Stan Lo
ZJIT: Remove JITed code after TracePoint is enabled
2025-08-27Rename rb_hook_list_mark_and_update to rb_hook_list_mark_and_movePeter Zhu
2025-04-27Fix jump buffer leak in WASI builds刘皓
Notes: Merged: https://github.com/ruby/ruby/pull/13142
2025-02-13[Feature #21116] Extract RJIT as a third-party gemNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12740
2024-11-29[Bug #20915] Fix SEGV with `TracePoint#parameters` and aliased C methodviralpraxis
The following snippet results with a SEGV: ```ruby C = Class.new do alias_method :new_to_s, :to_s end TracePoint.new(:c_call, &:parameters).enable { C.new.new_to_s } ``` at MRI 3.3.6 and ruby 3.4.0dev The root cause of the issue lies in the `rb_tracearg_parameters` function within the `RUBY_EVENT_C_RETURN` branch. Specifically, when the invoked method is an alias for a C function, `rb_method_entry_without_refinements(..., trace_arg->called_id, ...)` may return NULL. In that case we can fallback to `trace_arg->id`. Notes: Merged: https://github.com/ruby/ruby/pull/12186
2024-10-08Cast via `uintptr_t` function pointer between object pointerNobuyoshi Nakada
- ISO C forbids conversion of function pointer to object pointer type - ISO C forbids conversion of object pointer to function pointer type
2024-08-16Fix assertion error when TracePoint has incompatible eventsPeter Zhu
TracePoints with incompatible events (i.e. events not in ISEQ_TRACE_EVENTS) with a method target will fail an assertion error because it does not filter for the supported events. For example, the following lines will cause an assertion error: def foo; end # No arguments passed into TracePoint.new enables all ISEQ_TRACE_EVENTS TracePoint.new {}.enable(target: method(:foo)) # Raise is not supported with a target TracePoint.new(:raise, :return) {}.enable(target: method(:foo)) foo Crashes with: Assertion Failed: vm_insnhelper.c:7026:vm_trace:(iseq_local_events & ~(0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010| 0x0020| 0x0040 | 0x0100 | 0x0200 | 0x4000 | 0x010000| 0x020000)) == 0 Notes: Merged: https://github.com/ruby/ruby/pull/11390
2024-03-17Prefer `enum ruby_tag_type` over `int`Nobuyoshi Nakada
2024-03-06Move FL_SINGLETON to FL_USER1Jean Boussier
This frees FL_USER0 on both T_MODULE and T_CLASS. Note: prior to this, FL_SINGLETON was never set on T_MODULE, so checking for `FL_SINGLETON` without first checking that `FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-01-23Memory leak with TracePoint on bmethodPeter Zhu
[Bug #20194] When disabling the TracePoint on bmethod, the hooks list is not freed. For example: obj = Object.new obj.define_singleton_method(:foo) {} bmethod = obj.method(:foo) tp = TracePoint.new(:return) {} 10.times do 100_000.times do tp.enable(target: bmethod) {} end puts `ps -o rss= -p #{$$}` end Before: 18208 22832 26528 29728 34000 37776 40864 44400 47680 51504 After: 16688 17168 17168 17248 17696 17760 17824 17824 17856 17920
2024-01-16Rename BUILTIN_ATTR_SINGLE_NOARG_INLINETakashi Kokubun
to BUILTIN_ATTR_SINGLE_NOARG_LEAF The attribute was created when the other attribute was called BUILTIN_ATTR_INLINE. Now that the original attribute is renamed to BUILTIN_ATTR_LEAF, it's only confusing that we call it "_INLINE".
2024-01-08Adjust styles and indents [ci skip]Nobuyoshi Nakada
2023-12-22Remove EC argument from clean_hooks_checkJohn Hawthorn
This argument doesn't seem used anymore. Since we want to free these objects during VM destruction when RUBY_FREE_AT_EXIT is set they must work without an EC. This avoids a use-after-free running `RUBY_FREE_AT_EXIT=1 ./miniruby -e ''`
2023-12-13Refactor local variable names in postponed_job methodsKJ Tsanaktsidis
Just removes the unneeded `prereg_` prefix from a few local var names.
2023-12-12[Bug #19114] Fix for multiple calls of TracePoint#enableKouhei Yanagita
2023-12-10add `flags` to `rb_postponed_job_preregister`Koichi Sasada
for future extensions.
2023-12-10Change the semantics of rb_postponed_job_registerKJ Tsanaktsidis
Our current implementation of rb_postponed_job_register suffers from some safety issues that can lead to interpreter crashes (see bug #1991). Essentially, the issue is that jobs can be called with the wrong arguments. We made two attempts to fix this whilst keeping the promised semantics, but: * The first one involved masking/unmasking when flushing jobs, which was believed to be too expensive * The second one involved a lock-free, multi-producer, single-consumer ringbuffer, which was too complex The critical insight behind this third solution is that essentially the only user of these APIs are a) internal, or b) profiling gems. For a), none of the usages actually require variable data; they will work just fine with the preregistration interface. For b), generally profiling gems only call a single callback with a single piece of data (which is actually usually just zero) for the life of the program. The ringbuffer is complex because it needs to support multi-word inserts of job & data (which can't be atomic); but nobody actually even needs that functionality, really. So, this comit: * Introduces a pre-registration API for jobs, with a GVL-requiring rb_postponed_job_prereigster, which returns a handle which can be used with an async-signal-safe rb_postponed_job_trigger. * Deprecates rb_postponed_job_register (and re-implements it on top of the preregister function for compatability) * Moves all the internal usages of postponed job register pre-registration
2023-11-22Implement TracePoint on VWAPeter Zhu
2023-11-22Implement Write Barriers on TracePointPeter Zhu
2023-09-04[Bug #18487] [DOC] Remove stale note in `set_trace_func` documentNobuyoshi Nakada
`c-call` and `c-return events no longer pass the nearest Ruby method binding. Notes: Merged: https://github.com/ruby/ruby/pull/8364
2023-09-04[DOC] Update `set_trace_func` documentNobuyoshi Nakada
- Clarify the class of event parameters - Represent event names as strings - Update the example to show the above Notes: Merged: https://github.com/ruby/ruby/pull/8364
2023-09-04[DOC] Fix indent of `set_trace_func` documentNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8364
2023-08-01support `rescue` event for TracePointKoichi Sasada
fix [Feature #19572] Notes: Merged: https://github.com/ruby/ruby/pull/8150
2023-05-20`rb_bug` prints a newline after the messageNobuyoshi Nakada
2023-03-23`vm_call_single_noarg_inline_builtin`Koichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/7486
2023-03-06s/mjit/rjit/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-15Encapsulate RCLASS_ATTACHED_OBJECTJean Boussier
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. Notes: Merged: https://github.com/ruby/ruby/pull/7308
2023-01-20Make all of the references of iseq movablePeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7156
2023-01-04Fix crash in TracePoint c_call for removed methodPeter Zhu
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] Notes: Merged: https://github.com/ruby/ruby/pull/7064
2022-12-24MJIT: Cancel all on disastrous situations (#7019)Takashi Kokubun
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. Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2022-12-21Make sure TracePoint#binding returns nil for c_call/c_return eventsJeremy Evans
This makes sure the method returns nil for these events, as described in NEWS, even if the TracePoint could create a binding. Notes: Merged: https://github.com/ruby/ruby/pull/6984 Merged-By: jeremyevans <code@jeremyevans.net>
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-11-13Refactor update_global_event_hookTakashi Kokubun
It seems more readable to put JIT invalidation code together.
2022-11-13YJIT: Fix invalidation for c_call and c_return (#6719)Alan Wu
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. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-11-10YJIT: Invalidate JIT code only for ISEQ_TRACE_EVENTS (#6695)Takashi Kokubun
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-06-22Fix infinite loop when b_return TracePoint throwsAlan Wu
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] Notes: Merged: https://github.com/ruby/ruby/pull/4638
2022-06-10Fix nested bmethod TracePoint and memory leakAlan Wu
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] Notes: Merged: https://github.com/ruby/ruby/pull/4651
2022-04-06Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans
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> Notes: Merged: https://github.com/ruby/ruby/pull/5767 Merged-By: jeremyevans <code@jeremyevans.net>
2022-04-01Revert "Raise RuntimeError if Kernel#binding is called from a non-Ruby frame"Jeremy Evans
This reverts commit 343ea9967e4a6b279eed6bd8e81ad0bdc747f254. This causes an assertion failure with -DRUBY_DEBUG=1 -DRGENGC_CHECK_MODE=2
2022-03-30Prefix ccan headers (#4568)Nobuyoshi Nakada
* 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> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-03-29Avoid trace events in implementation of TracePoint#enableJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/5359
2022-03-24Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans
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> Notes: Merged: https://github.com/ruby/ruby/pull/5567
2022-01-22Fix error: old-style function definitionKazuhiro NISHIYAMA
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() | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```