aboutsummaryrefslogtreecommitdiffstats
path: root/mjit.c
Commit message (Collapse)AuthorAgeFilesLines
* Add ISEQ_BODY macroPeter Zhu2022-03-241-31/+31
| | | | | | Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using this macro will make it easier for us to change the allocation strategy of rb_iseq_constant_body when using Variable Width Allocation.
* Transfer the responsibility for MJIT options to mjit.cNobuyoshi Nakada2022-01-151-0/+58
|
* Revert "Pause an MJIT worker when JIT is cancelled"Takashi Kokubun2021-08-131-3/+0
| | | | | | This reverts commit b64f81c81729bbc248d19af01cafde88eb60fdc7. It seems to cause a problem in --jit / --jit-wait CIs. Reverting for now.
* Don't run mjit_cancel_all when MJIT is disabledTakashi Kokubun2021-08-121-0/+3
|
* Pause an MJIT worker when JIT is cancelledTakashi Kokubun2021-08-121-0/+3
|
* Print JIT cancel when all JIT-ed code is cancelledTakashi Kokubun2021-08-121-1/+11
|
* Cast jit_func for WindowsTakashi Kokubun2021-06-101-1/+1
| | | | https://ci.appveyor.com/project/ruby/ruby/builds/39542385/job/8b7aq951f9t01x4x
* Avoid enqueueing the same ISeq twiceTakashi Kokubun2021-06-101-10/+20
| | | | | | | | | | by a race condition by multiple Ractors. Atmically incrementing body->total_calls may have its own cost, so for now we intentionally leave the unreliable total_calls. So we allow an ISeq to be never pushed when you use multiple Ractors. However, if you enqueue a single ccan node twice, get_from_list loops infinitely. Thus this patch takes care of such a situation.
* Do not doubly hold an MJIT lockTakashi Kokubun2021-06-021-9/+14
| | | | | | | | | This is a follow-up of 86c262541ad07528842d76dab4b9b34bd888d5f4. CRITICAL_SECTION_START/FINISH are not needed when it's called from an MJIT worker. Also, ZALLOC needs to be calloc because ZALLOC may trigger GC, which an MJIT worker must not do.
* Fix a race condition around mjit_recompileTakashi Kokubun2021-06-021-8/+13
| | | | | | | | | This fixes SEGVs like https://github.com/ruby/ruby/runs/2715166621?check_suite_focus=true. When mjit_recompile is called when mjit_compile is compiling the exact same iseq (and after it called mjit_capture_cc_entries), iseq->body->jit_unit is re-created and its cc_entries becomes NULL. Then, when it tries to lookup cc_entries through iseq->body->jit_unit, it fails.
* Change the default --jit-max-cache to 10000Takashi Kokubun2021-05-311-1/+1
| | | | | This is useful for large applications like Rails. https://k0kubun.medium.com/ruby-3-jit-can-make-rails-faster-756310f235a
* Drop JIT_ISEQ_SIZE_THRESHOLDTakashi Kokubun2021-05-311-2/+1
| | | | | | | | | Compiling everything seems to contributed to improving the final performance in general. MJIT's compilation is slow anyway, especially when you need to wait for JIT compaction. This might make sense for short-time benchmarks like Optcarrot with default parameters, but it didn't give benefits in my local environment.
* Mark inlined ISeqs during MJIT compilation (#4539)Takashi Kokubun2021-05-301-5/+13
| | | [Bug #17584]
* enable constant cache on ractorsKoichi Sasada2021-01-051-18/+0
| | | | | | | | | | | | | | | | constant cache `IC` is accessed by non-atomic manner and there are thread-safety issues, so Ruby 3.0 disables to use const cache on non-main ractors. This patch enables it by introducing `imemo_constcache` and allocates it by every re-fill of const cache like `imemo_callcache`. [Bug #17510] Now `IC` only has one entry `IC::entry` and it points to `iseq_inline_constant_cache_entry`, managed by T_IMEMO object. `IC` is atomic data structure so `rb_mjit_before_vm_ic_update()` and `rb_mjit_after_vm_ic_update()` is not needed.
* Skip mjit_wait if iseq is not a targetTakashi Kokubun2021-01-041-0/+14
|
* Avoid hanging on --jit-wait after MJIT.pauseTakashi Kokubun2021-01-031-0/+3
| | | | When a worker is stopped, nobody will JIT a method for you.
* Stop managing valid class serialsTakashi Kokubun2020-12-291-48/+1
| | | | `mjit_valid_class_serial_p` has no longer been used since b9007b6c548.
* Mark an ISeq being JIT-edTakashi Kokubun2020-12-201-2/+10
| | | | | This is to avoid SEGV on a CC reference in a normal compilation https://github.com/ruby/ruby/runs/1586578023
* Mark active_unitsTakashi Kokubun2020-12-201-4/+37
| | | | | | | | | | | | | | | | | | to avoid SEGV on mjit_recompile and compact_all_jit_code. For some reason, ISeqs on stack are sometimes GC-ed (why?) and therefore it may run mjit_recompile on a GC-ed ISeq, which I expected d07183ec85d to fix but apparently it may refer to random things if already GC-ed. Marking active_units would workaround the situation. http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3292740 Also, while compact_all_jit_code was executed, we saw some SEGVs where CCs seemed to be already GC-ed, meaning their owner ISeq was not marked properly. Even if units are still in active_units, it's not guaranteed that their ISeqs are in use. So in this case we need to mark active_units for a legitimate reason. http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3293277 http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3293090
* Stop marking unit_queueTakashi Kokubun2020-12-201-27/+0
| | | | | | | | | | The original motivation of this marking was https://github.com/k0kubun/yarv-mjit/issues/20. As wanabe said, there are multiple options to mitigate the issue, and Eric Wong introduced another fix at 143776f6fe by checking unit->iseq inside the lock. Therefore this particular condition has been covered in two ways, and the script given by wanabe no longer crashes without mjit_mark().
* Do not access jit_unit if NULLTakashi Kokubun2020-12-161-1/+4
|
* Inline getconstant on JIT (#3906)Takashi Kokubun2020-12-161-0/+26
| | | | | * Inline getconstant on JIT * Support USE_MJIT=0
* Lazily move units from active_units to stale_unitsTakashi Kokubun2020-12-161-3/+4
| | | | | | to avoid SEGV like http://ci.rvm.jp/results/trunk-mjit@phosphorus-docker/3289588 by a race condition between mjit_recompile and compation around active_units
* Assert unit->iseq null out happens under the JIT/GC guardTakashi Kokubun2020-12-031-0/+2
|
* Throttle unload_unitsTakashi Kokubun2020-11-271-1/+1
| | | | | | | | | | Because d80226e7bd often reduces the number of unloaded units, it increases the number of unload_units calls, which are heavy. To mitigate that, this throttles unload_units per `max_cache_size / 10`. Also hoping to fix https://ci.appveyor.com/project/ruby/ruby/builds/36552382/job/kjmjgw9cjyf2ksd7
* Run unload_units in the JIT worker threadTakashi Kokubun2020-11-271-101/+1
| | | | | | | | to avoid "Too many JIT code, but skipped unloading units for JIT compaction". Now we can forget the `in_compact` locking. Moving some functions from mjit.c to mjit_worker.c because mjit_worker.c should have functions executed in the JIT worker.
* Handle calloc failureTakashi Kokubun2020-11-241-0/+2
| | | | for cfd8c7e6ca9f923cee3a062b548d0824fc67e9a5.
* Prefer calloc/free over ZALLOC/xfreeTakashi Kokubun2020-11-231-2/+5
| | | | | To avoid SEGV like http://ci.rvm.jp/logfiles/brlog.trunk-mjit.20201124-061530
* ruby/internal/config.h needs to be included firstTakashi Kokubun2020-11-221-1/+2
| | | | to define USE_MJIT.
* Make --disable-jit-support compileTakashi Kokubun2020-11-221-2/+1
| | | | | | vm_core.h needs to be included to know rb_execution_context_t, etc. I also added a trivial refactoring in mjit.c and missing dependency for process.c.
* Remove obsoleted internal/mjit.h inclusionTakashi Kokubun2020-11-221-1/+0
| | | | :bow:
* Stop leaving .c files for JIT compaction in /tmp (#3802)Takashi Kokubun2020-11-221-4/+0
| | | | | | | | | * Re-generate C files for JIT compaction every time * Refactor in_jit return logic * Just write code in a single file * Add a TODO comment [ci skip]
* Make sure all threads are scanned on unload_unitsTakashi Kokubun2020-11-211-10/+10
| | | | | | | | | | | This has been a TODO since 79df14c04b. While adcf0316d1 covered the root_fiber of the initial thread, it didn't cover root_fibers of other threads. Now it's hooked properly in rb_threadptr_root_fiber_setup. With regards to "XXX: Is this mjit_cont `mjit_cont_free`d?", when rb_threadptr_root_fiber_release is called, although I'm not sure when th->root_fiber is truthy, fiber_free seems to call cont_free and mjit_cont_free. So mjit_conts of root_fibers seem to be freed properly.
* Fix wrong #ifdef usages with #ifTakashi Kokubun2020-11-201-1/+1
| | | | Apparently #ifdef is always true
* Unify some confusing macro usagesTakashi Kokubun2020-11-201-2/+2
| | | | | | | | | | | | | | _MSC_VER used to be the macro to switch JIT compaction. However, since d4381d2ceb, the correct macro to switch it was changed from _MSC_VER to _WIN32. As I didn't properly replace all relevant _MSC_VER usages to _WIN32, these macros have been used inconsistently. nobu replaced _WIN32 with USE_HEADER_TRANSFORMATION in 5eb446d12f3. Therefore we had USE_HEADER_TRANSFORMATION and _MSC_VER. This commit makes sure such inconsistent _MSC_VER usages will be unified to the new header, also renaming it to USE_JIT_COMPACTION to be more precise about the requirements. The header transformation itself is not quite relevant to places changed in this commit.
* Eliminate IVC sync between JIT and Ruby threads (#3799)Takashi Kokubun2020-11-201-46/+1
| | | | Thanks to Ractor (https://github.com/ruby/ruby/pull/2888 and https://github.com/ruby/ruby/pull/3662), inline caches support parallel access now.
* Assert in_gc >= 0 instead of guarding it (#3687)Takashi Kokubun2020-10-221-3/+1
|
* Use a lock level for a less granular lock.Aaron Patterson2020-10-221-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We are seeing an error where code that is generated with MJIT contains references to objects that have been moved. I believe this is due to a race condition in the compaction function. `gc_compact` has two steps: 1. Run a full GC to pin objects 2. Compact / update references Step one is executed with `garbage_collect`. `garbage_collect` calls `gc_enter` / `gc_exit`, these functions acquire a JIT lock and release a JIT lock. So a lock is held for the duration of step 1. Step two is executed by `gc_compact_after_gc`. It also holds a JIT lock. I believe the problem is that the JIT is free to execute between step 1 and step 2. It copies call cache values, but doesn't pin them when it copies them. So the compactor thinks it's OK to move the call cache even though it is not safe. We need to hold a lock for the duration of `garbage_collect` *and* `gc_compact_after_gc`. This patch introduces a lock level which increments and decrements. The compaction function can increment and decrement the lock level and prevent MJIT from executing during both steps.
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-5/+6
| | | | | | | | | | | | | | | | 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.
* mjit_mark_cc_entries: should consider VM_CALLCACHE_UNMARKABLE卜部昌平2020-06-091-1/+1
| | | | | Now that vm_empty_cc is VM_CALLCACHE_UNMARKABLE, it has to be properly ruled out from being GCed.
* Eliminate a call instruction on JIT cancel pathTakashi Kokubun2020-05-261-2/+34
| | | | | | | 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.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Deduplicate functions in compacted JIT codeTakashi Kokubun2020-05-011-2/+2
| | | | | | | | | | | | | | to improve code locality. Using benchmark-driver/sinatra with 100 methods JIT-ed, [Before] 12149.97 rps 1.3M /tmp/_ruby_mjit_p31171u145.so [After] 12818.83 rps 260K /tmp/_ruby_mjit_p32155u145.so (VM is 13714.89 rps)
* Do not stop the world during JIT compactionTakashi Kokubun2020-04-301-7/+11
| | | | | | | | | | Running C compiler for JIT compaction inside a critical section may lock main thread for a long time when it triggers GC. As I'm planning to increase this duration a bit, I'd like to make sure this doesn't stop the world. For now, I chose to give up unloading units when it's during JIT compaction, assuming other calls may unload them later.
* Add MJIT_COUNTER macro to dump total_callsTakashi Kokubun2020-04-121-0/+20
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-1/+1
| | | Split ruby.h
* Add debug counter for unload_unitsTakashi Kokubun2020-03-151-0/+2
| | | | changing add_iseq_to_process's debug counter name as well for comparison
* Mark all cc_entries associated to compiled_iseqTakashi Kokubun2020-03-121-1/+2
|
* Move code to mark jit_unit's cc_entries to mjit.cTakashi Kokubun2020-03-121-3/+15
|