summaryrefslogtreecommitdiff
path: root/rjit_c.c
AgeCommit message (Collapse)Author
2025-02-13[Feature #21116] Extract RJIT as a third-party gemNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12740
2025-01-10Make rb_vm_insns_count a thread local variableAaron Patterson
`rb_vm_insns_count` is a global variable used for reporting YJIT statistics. It is a counter that tallies the number of interpreter instructions that have been executed, this way we can approximate how much time we're spending in YJIT compared to the interpreter. Unfortunately keeping this statistic means that every instruction executed in the interpreter loop must increment the counter. Normally this isn't a problem, but in multi-threaded situations (when Ractors are used), incrementing this counter can become quite costly due to page caching issues. Additionally, since there is no locking when incrementing this global, the count can't really make sense in a multi-threaded environment. This commit changes `rb_vm_insns_count` to a thread local. That way each Ractor has it's own copy of the counter and incrementing the counter becomes quite cheap. Of course this means that in multi-threaded situations, the value doesn't really make sense (but it didn't make sense before because of the lack of locking). The counter is used for YJIT statistics, and since YJIT is basically disabled when Ractors are in use, I don't think we care about inaccuracies (for the time being). We can revisit this counter when we give YJIT multi-threading support, but for the time being this commit restores multi-threaded performance. To test this, I used the benchmark in [Bug #20489]. Here is the performance on Ruby 3.2: ``` $ time RUBY_MAX_CPU=12 ./miniruby -v ../test.rb 8 8 ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux] [0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8] ../test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. ________________________________________________________ Executed in 2.53 secs fish external usr time 19.86 secs 370.00 micros 19.86 secs sys time 0.02 secs 320.00 micros 0.02 secs ``` We can see the regression in performance on the master branch: ``` $ time RUBY_MAX_CPU=12 ./miniruby -v ../test.rb 8 8 ruby 3.5.0dev (2025-01-10T16:22:26Z master 4a2702dafb) +PRISM [x86_64-linux] [0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8] ../test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. ________________________________________________________ Executed in 24.87 secs fish external usr time 195.55 secs 0.00 micros 195.55 secs sys time 0.00 secs 716.00 micros 0.00 secs ``` Here are the stats after this commit: ``` $ time RUBY_MAX_CPU=12 ./miniruby -v ../test.rb 8 8 ruby 3.5.0dev (2025-01-10T20:37:06Z tl 3ef0432779) +PRISM [x86_64-linux] [0...1, 1...2, 2...3, 3...4, 4...5, 5...6, 6...7, 7...8] ../test.rb:43: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. ________________________________________________________ Executed in 2.46 secs fish external usr time 19.34 secs 381.00 micros 19.34 secs sys time 0.01 secs 321.00 micros 0.01 secs ``` [Bug #20489] Notes: Merged: https://github.com/ruby/ruby/pull/12549
2024-12-19Prefix asan_poison_object with rbPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12385
2024-11-21Annotate anonymous mmapKunshan Wang
Use PR_SET_VMA_ANON_NAME to set human-readable names for anonymous virtual memory areas mapped by `mmap()` when compiled and run on Linux 5.17 or higher. This makes it convenient for developers to debug mmap. Notes: Merged: https://github.com/ruby/ruby/pull/12119
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-05-23Introduce a specialize instruction for Array#packNobuyoshi Nakada
Instructions for this code: ```ruby # frozen_string_literal: true [a].pack("C") ``` Before this commit: ``` == disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)> 0000 putself ( 3)[Li] 0001 opt_send_without_block <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE> 0003 newarray 1 0005 putobject "C" 0007 opt_send_without_block <calldata!mid:pack, argc:1, ARGS_SIMPLE> 0009 leave ``` After this commit: ``` == disasm: #<ISeq:<main>@test.rb:1 (1,0)-(3,13)> 0000 putself ( 3)[Li] 0001 opt_send_without_block <calldata!mid:a, argc:0, FCALL|VCALL|ARGS_SIMPLE> 0003 putobject "C" 0005 opt_newarray_send 2, :pack 0008 leave ``` Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-12-19RJIT: Correct the type of rb_vm_insns_countTakashi Kokubun
2023-12-19RJIT: Declare rb_vm_insns_countTakashi Kokubun
2023-05-20`rb_bug` prints a newline after the messageNobuyoshi Nakada
2023-04-18Update RJIT to support newarray_sendAaron Patterson
This also adds max / hash support Notes: Merged: https://github.com/ruby/ruby/pull/6090
2023-04-13Fix declaration of `rb_rjit_entry_stub_hit` in rjit_c.cNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7695
2023-04-07Expose rb_sym_to_proc via RJITAaron Patterson
This is needed for getblockparamproxy Notes: Merged: https://github.com/ruby/ruby/pull/7673
2023-04-02RJIT: Support entry with different PCsTakashi Kokubun
2023-04-02RJIT: Simplify cfunc implementationTakashi Kokubun
2023-04-01Remove an unneeded function copyTakashi Kokubun
2023-04-01RJIT: Fix a leaked-globals failureTakashi Kokubun
2023-04-01RJIT: Support rest argsTakashi Kokubun
2023-03-26RJIT: Implement attr_writerTakashi Kokubun
2023-03-19RJIT: Implement ifunc invokeblockTakashi Kokubun
2023-03-19RJIT: Optimize Kernel#respond_to?Takashi Kokubun
2023-03-19RJIT: Optimize String#<<Takashi Kokubun
2023-03-18RJIT: Optimize String#bytesizeTakashi Kokubun
2023-03-18RJIT: Implement setclassvariableTakashi Kokubun
2023-03-18RJIT: Implement toregexpTakashi Kokubun
2023-03-17RJIT: Implement throw insnTakashi Kokubun
2023-03-17RJIT: Support --rjit-stats on release build as wellTakashi Kokubun
2023-03-13RJIT: Simplify how Capstone is used in testsTakashi Kokubun
2023-03-12RJIT: Fix -Wshorten-64-to-32Takashi Kokubun
2023-03-12RJIT: Implement --rjit-trace-exitsTakashi Kokubun
2023-03-11RJIT: Automate function pointer importsTakashi Kokubun
2023-03-11RJIT: Use SIZET macros instead of original PTR onesTakashi Kokubun
2023-03-10RJIT: Introduce --rjit-exec-mem-sizeTakashi Kokubun
2023-03-08RJIT: Make functions in rjit_c.c staticTakashi Kokubun
They don't need to be global.
2023-03-08RJIT: Stop allowing leaked globals rjit_*Takashi Kokubun
2023-03-08RJIT: Clean up the declaration messTakashi Kokubun
2023-03-07Allow enabling YJIT and RJIT independently (#7474)Takashi Kokubun
We used to require MJIT is supported when YJIT is supported. However, now that RJIT dropped some platforms that YJIT supports, it no longer makes sense. We should be able to enable only YJIT, and vice versa. Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2023-03-06s/mjit/rjit/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06s/MJIT/RJIT/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06Rename MJIT filenames to RJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462