summaryrefslogtreecommitdiff
path: root/mjit.h
AgeCommit message (Collapse)Author
2020-06-24Do not JIT inline builtin methodsTakashi Kokubun
It's probably not worth it because there's nothing we can optimize in such builtin methods. It's worth JIT only when inlined.
2020-05-27Carve out mjit_exec_slowpathTakashi Kokubun
and mark it as COLDFUN on JIT, assuming enqueue usually happens on VM.
2020-05-26Eliminate a call instruction on JIT cancel pathTakashi Kokubun
by calling combined functions specialized for each cancel type. I'm hoping to improve locality of hot code, but this patch's impact should be insignificant.
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-30Include unit id in a function name of an inlined methodTakashi Kokubun
I'm trying to make it possible to include all JIT-ed code in a single C file. This is needed to guarantee uniqueness of all function names
2020-04-13add #include guard hack卜部昌平
According to MSVC manual (*1), cl.exe can skip including a header file when that: - contains #pragma once, or - starts with #ifndef, or - starts with #if ! defined. GCC has a similar trick (*2), but it acts more stricter (e. g. there must be _no tokens_ outside of #ifndef...#endif). Sun C lacked #pragma once for a looong time. Oracle Developer Studio 12.5 finally implemented it, but we cannot assume such recent version. This changeset modifies header files so that each of them include strictly one #ifndef...#endif. I believe this is the most portable way to trigger compiler optimizations. [Bug #16770] *1: https://docs.microsoft.com/en-us/cpp/preprocessor/once *2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html Notes: Merged: https://github.com/ruby/ruby/pull/3023
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-30Optimize exivar access on JIT-ed getivarTakashi Kokubun
JIT support of dd723771c11. $ benchmark-driver -v --rbenv 'before;before --jit;after --jit' benchmark/mjit_exivar.yml --repeat-count=4 before: ruby 2.8.0dev (2020-03-30T12:32:26Z master e5db3da9d3) [x86_64-linux] before --jit: ruby 2.8.0dev (2020-03-30T12:32:26Z master e5db3da9d3) +JIT [x86_64-linux] after --jit: ruby 2.8.0dev (2020-03-31T05:57:24Z mjit-exivar 128625baec) +JIT [x86_64-linux] Calculating ------------------------------------- before before --jit after --jit mjit_exivar 57.944M 53.579M 54.471M i/s - 200.000M times in 3.451588s 3.732772s 3.671687s Comparison: mjit_exivar before: 57944345.1 i/s after --jit: 54470876.7 i/s - 1.06x slower before --jit: 53579483.4 i/s - 1.08x slower
2020-03-15Add debug counter for unload_unitsTakashi Kokubun
changing add_iseq_to_process's debug counter name as well for comparison
2020-03-12Move code to mark jit_unit's cc_entries to mjit.cTakashi Kokubun
2020-02-26Internalize rb_mjit_unit definition againTakashi Kokubun
Fixed a TODO in b9007b6c548f91e88fd3f2ffa23de740431fa969
2020-02-22Introduce disposable call-cache.Koichi Sasada
This patch contains several ideas: (1) Disposable inline method cache (IMC) for race-free inline method cache * Making call-cache (CC) as a RVALUE (GC target object) and allocate new CC on cache miss. * This technique allows race-free access from parallel processing elements like RCU. (2) Introduce per-Class method cache (pCMC) * Instead of fixed-size global method cache (GMC), pCMC allows flexible cache size. * Caching CCs reduces CC allocation and allow sharing CC's fast-path between same call-info (CI) call-sites. (3) Invalidate an inline method cache by invalidating corresponding method entries (MEs) * Instead of using class serials, we set "invalidated" flag for method entry itself to represent cache invalidation. * Compare with using class serials, the impact of method modification (add/overwrite/delete) is small. * Updating class serials invalidate all method caches of the class and sub-classes. * Proposed approach only invalidate the method cache of only one ME. See [Feature #16614] for more details. Notes: Merged: https://github.com/ruby/ruby/pull/2888
2020-02-20suppress clang warnings卜部昌平
Starting clang 11, casts between pointer and (narrower-than-pointer) int are now warned. However all such thing in our repository are guaranteed safe. Let's suppress the warnings.
2019-12-26decouple internal.h headers卜部昌平
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). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-01Constified mjit_initNobuyoshi Nakada
2019-12-01Allow specifying arbitrary MJIT flags by --jit-debugTakashi Kokubun
This is a secret feature for me. It's only for testing and any behavior with this flag override is unsupported. I needed this because I sometimes want to add debug options but do not want to disable optimizations, for using Linux perf.
2019-11-14delete unused functions卜部昌平
Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine. Notes: Merged: https://github.com/ruby/ruby/pull/2677
2019-05-15Rename mjit_gc_finish_hook to mjit_gc_exit_hookTakashi Kokubun
because @ko1 said "gc_finish" is confusing like a finish of entire GC process
2019-04-20Prefix rb_ to MJIT wait call since it's exportedk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Update MJIT referencestenderlove
ISeq can move, so we need to tell MJIT where the new location is. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-16Recompile without method inliningk0kubun
if cancel happens in an inlined method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Unify comment styles across MJIT sourcesk0kubun
I'm writing `//` comments in newer MJIT code after C99 enablement (because I write 1-line comments more often than multi-line comments and `//` requires fewer chars on 1-line) and then they are mixed with `/* */` now. For consistency and to avoid the conversion in future changes, let me finish the rewrite in MJIT-related code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-14Recompile JIT-ed code without optimizationk0kubun
based on inline cache when JIT cancel happens by that. This feature was in the original MJIT implementation by Vladimir, but on merging MJIT to Ruby it was removed for simplification. This commit adds the functionality again for the following benchmark: https://github.com/benchmark-driver/misc/blob/52f05781f65467baf895bf6ba79d172c9b0826fd/concurrent-map/bench.rb (shown float is duration seconds. shorter is better) * Before ``` $ INHERIT=0 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] -- 1.6507579649914987 $ INHERIT=0 ruby -v --jit bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] -- 1.5091587850474752 $ INHERIT=1 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] -- 1.6124781150138006 $ INHERIT=1 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] -- 1.7495657080435194 # <-- this ``` * After ``` $ INHERIT=0 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.653559010999743 $ INHERIT=0 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.4738391840364784 $ INHERIT=1 ruby -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.645227018976584 $ INHERIT=1 ruby --jit -v bench.rb ruby 2.7.0dev (2019-04-13 trunk 67523) +JIT [x86_64-linux] last_commit=Recompile JIT-ed code without optimization -- 1.523708809982054 # <-- this ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-06Add debug counter for VM <-> MJIT callsk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-29Add debug counters for MJITk0kubun
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Resurrect r67287 and r67288k0kubun
I noticed that r67287 was illegal because memory allocated by `alloca` was used after the stack is expired. So I just replaced that with `malloc` and `free` for now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Revert "Eliminate mjit_copy_job_t reference from mjit_worker"k0kubun
This reverts commit ba51ae0109ee1d1fa7ca90b43da115ea68d7214a. CI is failing again... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Eliminate mjit_copy_job_t reference from mjit_workerk0kubun
Take 2 of r67287. For some reasons, passing pointer of pointer on stack to a function and assigning an addresse to a pointer dereferenced from the pointer seems not working on mswin. So I achieved to return multiple values by returning struct instead of taking pointers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-18Revert "Request inline cache values from mjit_compile"k0kubun
This reverts commit 4161674b2fbea6bdd01783ac5d3b39d88db22972. Revert "Eliminate mjit_copy_job_t reference from mjit_worker" This reverts commit d86a1aa045959dfbf5cd472eae0d043180259727. Reverting them because of CI failures git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67291 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-17Request inline cache values from mjit_compilek0kubun
rather than preparing beforehand. By having this change, implementing inlining by calling `mjit_copy_cache_from_main_thread` for inlined methods was made possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10mjit.c: use boolean type for boolean variablesk0kubun
and functions to clarify the intention and make sure it's not used in a surprising way (like using 2, 3, ... other than 0, 1 even while it seems to be a boolean). This is a retry of r66775. It included some typos... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10Revert "mjit.c: use boolean type for boolean variables"k0kubun
This reverts commit bb1a1aeab0f2a5fe437c89b841a887ba56653453. We hit something on ci.rvm.jp, reverting until investigation is done. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10mjit.c: use boolean type for boolean variablesk0kubun
and functions to clarify the intention and make sure it's not used in a surprising way (like using 2, 3, ... other than 0, 1 even while it seems to be a boolean). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66775 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26vm_trace.c: MJIT-limited thread-safety for postponed_jobk0kubun
[Bug #15316] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Revert "process.c: try to workaroun SEGV by r65994"k0kubun
This reverts commit 0e6aba22c6b876a36adc39cac5314ce6e626954c. because it didn't help, at all. http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480207 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26process.c: try to workaroun SEGV by r65994k0kubun
http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1480173 It tries to print C backtrace but fails. And core file on the server seems to be stopping on the irrelevant place due to its own signal handler for the dump. And I failed to reproduce this SEGV on my machine. I don't know why it's broken, so let me try this change to investigate the reason of SEGV. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26process.c: finish MJIT prior to #execk0kubun
to prevent ruby from leaving MJIT-related files. test_jit.rb: add a test to prevent that git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21mjit.c: copy call cache values to MJIT workerk0kubun
same as r65275 but for call cache. === Optcarrot Benchmark === $ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems --jit;after::after --disable-gems --jit' -v --repeat-count 24 before: ruby 2.6.0dev (2018-10-21 trunk 65277) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-10-21 trunk 65277) +JIT [x86_64-linux] last_commit=mjit.c: copy call cache values to MJIT worker Calculating ------------------------------------- before after Optcarrot Lan_Master.nes 85.372 85.359 fps Comparison: Optcarrot Lan_Master.nes before: 85.4 fps after: 85.4 fps - 1.00x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21mjit.c: copy inline cache values to MJIT workerk0kubun
on VM_CHECK_INTS. Letting MJIT worker directly see inline cache which may be being updated could result in inconsistent IC index and serial. mjit_worker.c: request the copy job after dequeue, and receive the result synchronously. tool/ruby_vm/views/_mjit_compile_ivar.erb: use the copied IC mjit_compile.c: change the interface to pass is_entries mjit.h: ditto === Optcarrot Benchmark === Thankfully this didn't have major performance regression. $ benchmark-driver benchmark.yml --rbenv 'before::before --disable-gems --jit;after::after --disable-gems --jit' -v --repeat-count 24 before: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-10-21 trunk 65263) +JIT [x86_64-linux] last_commit=mjit.c: copy inline cache values to MJIT worker Calculating ------------------------------------- before after Optcarrot Lan_Master.nes 85.421 85.454 fps Comparison: Optcarrot Lan_Master.nes after: 85.5 fps before: 85.4 fps - 1.00x slower git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20add disabling MJIT features option.ko1
* configure.ac: introduce new configure option `--enable-mjit` and `--disable-mjit`. Default is "enable". `--disable-mjit` disables all of MJIT features so that `ruby --jit` can't enable MJIT. This option affect a macro `USE_MJIT`. This change remove `--enable/disable-install-mjit-header` option. * Makefile.in: introduce the `ENABLE_MJIT` variable. * common.mk: use `ENABLE_MJIT` option. * internal.h: respect `USE_MJIT`. Same as other *.c, *.h. * test/ruby/test_jit.rb: check `ENABLE_MJIT` key of rbconfg.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-07vm_core.h: fix inconsistent prototype declarationsk0kubun
like "error: static declaration of 'xxx' follows non-static declaration". r64940 is successfully built on mswin but not built on almost all other environments. internal.h: ditto include/ruby/intern.h: MJIT_STATIC is moved to this file since this file also needs to use this. mjit.h: MJIT_STATIC is moved from this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-07mjit.h: introduce MJIT_STATIC for full mswin JIT supportk0kubun
This change resolves most of major remaining MJIT bugs on mswin. Since Visual Studio doesn't support generating pre-processed code preserving macros, we can't use transform_mjit_header approach for mswin. So we need to transform MJIT header using macro like this. vm.c: use MJIT_STATIC for non-static functions that exist on MJIT header and cause conflict on link. vm_insnhelper.c: ditto test_jit.rb: remove many skips for mswin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-07mjit.h: call compiled code immediatelyk0kubun
after the first compilation on --jit-wait. Previously the assignment to `func` didn't have meaning for the behavior, and the compiled code wasn't called immediately after the synchronous compilation. It wasn't intentional. Fixing this issue without impacting performance without --jit-wait is not so obvious. Adding branch or goto to call func in mjit_exec spoiled the performance without --jit-wait. Instead of that, I called the func inside mjit_wait_call() (former mjit_get_iseq_func()) which is never inlined to mjit_exec(). Thanks to that, this commit has no impact for normal performance. mjit.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13Revert "vm_insnhelper.h: simplify EXEC_EC_CFP implementation"k0kubun
This reverts commit r64711, because EXEC_EC_CFP on JIT-ed code does not call jit_func with the patch when catch_except_p is true. It wasn't intentional. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-13vm_insnhelper.h: simplify EXEC_EC_CFP implementationk0kubun
and possibly memory access for iseq->body may be reduced. No significant impact for performance on Optcarrot. * before fps: 55.03865935187656 fps: 57.16854675983188 fps: 57.672458407661765 fps: 58.28989837869383 fps: 58.80503815099268 fps: 59.068054176528534 fps: 59.55736806358244 fps: 61.01018920533034 fps: 63.34167049232186 fps: 65.20575018321766 fps: 65.46758316561318 * after fps: 55.21860411005677 fps: 55.34840351179166 fps: 58.23666596747484 fps: 59.71987124578901 fps: 61.131485120234935 fps: 61.279905164649485 fps: 61.66060774175459 fps: 64.11215576508765 fps: 64.63699742853154 fps: 65.28260058920769 fps: 65.85447796482678 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11mjit.c: exclude mjit_valid_class_serial_pk0kubun
from mjit.c because it's executed only on MJIT worker thread. Instead of that, `valid_class_serials` is shared with mjit_ prefix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-11mjit_worker.c: carve out worker-related codek0kubun
The motivation of this change is to make sure rb_funcall or GC-related functions are not called on worker-related code. Currently such functions are used in some places and I believe it's partly because it's hard to identify which part is called on MJIT worker thread. Now, mjit.c is safe to use them but we know we need to safely deal with mjit_compile.c, mjit_worker.c and mjit_internal.h. mjit_compile.c: update the comment about it git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-09process.c: fix outdated mjit_pause declarationk0kubun
by sharing it with vm.c in internal.h. vm.c: ditto internal.h: ditto mjit.h: share more. mjit.c: make sure the third arguemnt is not used git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-07mjit.c: initial support for mswin MJITk0kubun
By this commit's changes in other files, now MJIT started to work on VC++. Unfortunately some features are still broken and they'll be fixed later. This also suppresses cl.exe's default output to stdout because there seems to be no option to do it. Tweaking some log messages as well. vm_core.h: declare `__declspec(dllimport)` to export them correctly on mswin. vm_insnhelper.h: ditto mjit.h: ditto test_jit.rb: skipped some pending tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e