Граф коммитов

246 Коммитов

Автор SHA1 Сообщение Дата
Yusuke Endoh c1228f833c vm_core.h: Avoid unaligned access to ic_serial on 32-bit machine
This caused Bus error on 32 bit Solaris
2021-10-29 10:57:46 +09:00
Alan Wu 7c08538aa3 Cleanup diff against upstream. Add comments
I did a `git diff --stat` against upstream and looked at all the files
that are outside of YJIT to come up with these minor changes.
2021-10-20 18:19:42 -04:00
Aaron Patterson 41f405c486 Remove the scraper
Now that we're using the jit function entry point, we don't need the
scraper.  Thank you for your service, scraper. ❤️
2021-10-20 18:19:38 -04:00
Aaron Patterson 30f20d7c38 Remove some MicroJIT vestiges
Just happened to run across this, so lets fix them
2021-10-20 18:19:36 -04:00
Alan Wu 5d834bcf9f YJIT: lazy polymorphic getinstancevariable
Lazily compile out a chain of checks for different known classes and
whether `self` embeds its ivars or not.

* Remove trailing whitespaces

* Get proper addresss in Capstone disassembly

* Lowercase address in Capstone disassembly

Capstone uses lowercase for jump targets in generated listings. Let's
match it.

* Use the same successor in getivar guard chains

Cuts down on duplication

* Address reviews

* Fix copypasta error

* Add a comment
2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert fe3bd57007 Remove trailing whitespaces 2021-10-20 18:19:31 -04:00
Jose Narvaez 4e2eb7695e Yet Another Ruby JIT!
Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
2021-10-20 18:19:31 -04:00
Maxime Chevalier-Boisvert 2e561ff255 Restore interpreter regs in ujit hook. Implement leave bytecode. 2021-10-20 18:19:28 -04:00
Maxime Chevalier-Boisvert e4c65ec49c Refactor uJIT code into more files for readability 2021-10-20 18:19:26 -04:00
Alan Wu b75169a440 Fix typo 2021-10-20 18:19:26 -04:00
Alan Wu 5f9beb9b1b Include disassembly in MicroJIT scraper output 2021-10-20 18:19:26 -04:00
Alan Wu 11c1daea17 Add to the MicroJIT scraper an example that passes ec 2021-10-20 18:19:25 -04:00
Alan Wu 7662653b4c Fix compilation for OPT_THREADED_CODE=2 2021-10-20 18:19:24 -04:00
Alan Wu 2790428e55 Zero sized array are not standard C 2021-10-20 18:19:24 -04:00
Alan Wu a3e58f4df8 Compile with MicroJIT disabled when scrape fails
This is just so we can build successfully on -O0 and other cases that
are not supported by the code scraper.
2021-10-20 18:19:24 -04:00
Alan Wu f3c961f273 endbr64 is fine 2021-10-20 18:19:24 -04:00
Alan Wu 453218b272 Preliminary GNU/Linux support for code scraper
Let's see if this works on CI
2021-10-20 18:19:24 -04:00
Alan Wu 3d87eadf16 Refactor ujit_examples.h generator. Remove dwarfdump dependency 2021-10-20 18:19:24 -04:00
Maxime Chevalier-Boisvert 3739588811 Remove PC argument from ujit instructions 2021-10-20 18:19:23 -04:00
Alan Wu 16c5ce863c Yeah, this actually works! 2021-10-20 18:19:22 -04:00
Alan Wu cec197696f Add example handler for ujit and scrape it from vm.o 2021-10-20 18:19:22 -04:00
Nobuyoshi Nakada b44c5187b4 Expose instruction information for debuggers [Feature #18026] 2021-10-04 09:43:09 -07:00
Jeremy Evans 48c8df9e0e
Allow tracing of optimized methods
This updates the trace instructions to directly dispatch to
opt_send_without_block.  So this should cause no slowdown in
non-trace mode.

To enable the tracing of the optimized methods, RUBY_EVENT_C_CALL
and RUBY_EVENT_C_RETURN are added as events to the specialized
instructions.

Fixes [Bug #14870]

Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2021-08-21 10:15:01 -07:00
Takashi Kokubun 2209e152c0
Decompose the captured_cc code for investigation
I'm investigating SEGVs like https://github.com/ruby/ruby/runs/2715166621?check_suite_focus=true.
Because a lot of things are going on on this line, it's hard to identify
the cause, especially because we can't get the core file of the failures.

Therefore I intentionally increased the number of lines for
investigation.
2021-05-31 21:57:57 -07:00
John Hawthorn 9d0ae387c8 Remove DEFINED_IVAR2 from enum
This version of defined? doesn't seem to be possible to emit anymore.
2021-03-10 09:38:20 -08:00
Takashi Kokubun 2a1c68c91e
Avoid re-entering opt_invokebuiltin_delegate_leave
on interruption.

The cancellation code was originally written for leave insn, but re-entering
opt_invokebuiltin_delegate_leave insn on a cancellation is not safe, because
a builtin function is executed twice.
2021-01-11 07:40:38 +00:00
Takashi Kokubun 7a3322a0fd
Fix broken JIT of getinlinecache
e7fc353f04 reverted vm_ic_hit_p's signature change made in 53babf35ef,
which broke JIT compilation of getinlinecache.

To make sure it doesn't happen again, I separated vm_inlined_ic_hit_p to
make the intention clear.
2021-01-04 13:09:08 -08:00
Takashi Kokubun 87c546b5fa
Avoid using inconsistent coding style
Other `_mjit_compile_*.erb` files don't use goto. These files'd better
be consistent for readability.
2021-01-04 10:45:01 -08:00
Koichi Sasada e7fc353f04 enable constant cache on ractors
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.
2021-01-05 02:27:58 +09:00
Takashi Kokubun 81a8d1cf09
Skip checking ROBJECT_EMBED
when we already check ROBJECT_NUMIV(self) is larger than
ROBJECT_EMBED_LEN_MAX at the beginning of the method, because the number
of instance variables for the same object doesn't decrease.

```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=4 --alternate --output=all benchmark_3000.yml
before --jit: ruby 3.0.0dev (2020-12-23T06:32:19Z master dbb4f19969) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-23T07:45:42Z master 95e866c098) +JIT [x86_64-linux]
last_commit=Skip checking ROBJECT_EMBED
Calculating -------------------------------------
                              before --jit           after --jit
Optcarrot 3000 frames   102.34091772397872    102.77738408379015 fps
                        103.37784821624231    105.46530219076179
                        104.39567016876369    106.43712452152215
                        105.31782092252713    106.54986150067481
```
2020-12-22 23:50:43 -08:00
Takashi Kokubun 692af8e8f8
Prefer stdbool in vm_exec
Make the code a bit modern and consistent with some other places.
2020-12-21 21:16:39 -08:00
Takashi Kokubun 7d0144e055
Check mjit_call_p only when interrupted
for leaf_without_check_ints insns.

$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-12-20T05:02:18Z master 02b3555874) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-20T05:36:00Z master 3f58de4eab) +JIT [x86_64-linux]
last_commit=Check mjit_call_p only when interrupted
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    84.50647332260259     85.85057800433144 fps
                            91.17796644338372     92.09930605656054
                            91.29346683444497     93.01336611323687
                            91.50322318568884     93.07234029037433
                            91.66560903214686     93.22773241529644
                            91.82315142636172     93.37032901061119
                            92.15066379608260     93.83701526141679
                            92.37897097456643     93.86032792681507
                            92.53049815524908     93.91211970920320
                            92.78414507914283     94.09109196967890
                            92.90299756525958     94.40107239595325
                            93.70279428858790     95.01326369371263
2020-12-19 21:38:14 -08:00
Takashi Kokubun 5611066e03
Prefer RB_OBJ_FROZEN_RAW
following the original implementation's change.
RB_TYPE_P(obj, T_OBJECT) is already checked in these places.

```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-12-19T08:27:44Z master 52b1716c78) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-19T08:27:44Z master 52b1716c78) +JIT [x86_64-linux]
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    88.04551460097873     84.38303800957766 fps
                            88.25194345156318     85.31098251408059
                            88.34143982084871     86.60491582339496
                            88.63486879856976     88.23675694701865
                            88.85392212902701     88.23696283371444
                            89.05739427483194     88.97185459567562
                            89.08141031147311     90.16373192658857
                            89.11359420883423     90.61655686444394
                            89.80323392966130     90.77044959019291
                            90.58912189625207     90.88534596330966
                            90.59847996970350     91.34314801302897
                            90.61180456415137     93.11599164249547
```
2020-12-19 00:34:33 -08:00
Takashi Kokubun 5d74894f2b
Lazily move PC with RUBY_VM_CHECK_INTS
```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-12-17T06:17:46Z master 3b4d698e0b) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-12-17T07:01:48Z master 843abb96f0) +JIT [x86_64-linux]
last_commit=Lazily move PC with RUBY_VM_CHECK_INTS
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    80.29343646660429     83.15779723251525 fps
                            82.26755637885149     85.50197941326810
                            83.50682959728820     88.14657804306270
                            85.01236533133049     88.78201988978667
                            87.81799334561326     88.94841008936447
                            87.88228562393064     89.37925215601926
                            88.06695585889995     89.86143277214475
                            88.84730834922165     90.00773346420887
                            90.46317871213088     90.82603371104014
                            90.96308347148916     91.29797694822179
                            90.97945938504556     91.31086331868738
                            91.57127890154500     91.49949184318844
```
2020-12-16 23:06:28 -08:00
Takashi Kokubun 3b4d698e0b
Ignore catch_except_p for PC motion
We probably don't need to move it when an insn is leaf...
2020-12-16 22:17:46 -08:00
Takashi Kokubun 53babf35ef
Inline getconstant on JIT (#3906)
* Inline getconstant on JIT

* Support USE_MJIT=0
2020-12-16 06:24:07 -08:00
Takashi Kokubun 9d85ed6cbb
Simplify positioning of '{' and '}'
and fix inconsistent indentation in mjit_compile.inc.erb
2020-12-14 21:07:41 -08:00
Koichi Sasada aa6287cd26 fix inline method cache sync bug
`cd` is passed to method call functions to method invocation
functions, but `cd` can be manipulated by other ractors simultaneously
so it contains thread-safety issue.

To solve this issue, this patch stores `ci` and found `cc` to `calling`
and stops to pass `cd`.
2020-12-15 13:29:30 +09:00
Takashi Kokubun d409837729
Cache access to reg_cfp->self on JIT
```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-11-27T06:41:15Z master 8ce1711c25) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-11-27T08:36:02Z master 2c592126b9) +JIT [x86_64-linux]
last_commit=Cache access to reg_cfp->self on JIT
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    82.40522392468650     82.66023870551237 fps
                            82.67998539899482     83.08660305312587
                            85.51280693947453     87.09311989553235
                            86.32925337181406     87.16115255191410
                            87.35617494926235     87.30699391518075
                            87.91865339426212     88.47590342996875
                            88.11573661006648     88.64778616696353
                            88.16060826662158     88.67015079203991
                            88.21639244865058     89.19630739497482
                            88.47241577897603     89.23443637947730
                            89.37087287229809     89.57052723997015
                            89.46969964699964     89.97803363889025
```
2020-11-27 00:42:42 -08:00
Takashi Kokubun 8ce1711c25
Revert "Set VM_FRAME_FLAG_FINISH at once on MJIT"
This reverts commit 4d2c8edca6.

Unfortunately this seems to cause several issues:
https://github.com/ruby/ruby/runs/1462188376?check_suite_focus=true
http://ci.rvm.jp/results/trunk-mjit-wait@phosphorus-docker/3272802
2020-11-26 22:41:15 -08:00
Takashi Kokubun 4d2c8edca6
Set VM_FRAME_FLAG_FINISH at once on MJIT
Performance is probably improved?

$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-11-27T04:37:47Z master 69e77e81dc) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-11-27T05:28:19Z master df6b05c6dd) +JIT [x86_64-linux]
last_commit=Set VM_FRAME_FLAG_FINISH at once
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    80.89292998533379     82.19497327502751 fps
                            80.93130641142331     85.13943315260148
                            81.06214830270119     87.43757879797808
                            82.29172808453910     87.89942441487113
                            84.61206450455929     87.91309779491075
                            85.44545883567997     87.98026086648694
                            86.02923132404449     88.03081060383973
                            86.07411817365879     88.14650206137341
                            86.34348799602836     88.32791633649961
                            87.90257338977324     88.57599644892220
                            88.58006509876580     88.67426384743277
                            89.26611118140011     88.81669430874207

This should have no bad impact on VM because this function is ALWAYS_INLINE.
2020-11-26 21:32:14 -08:00
Takashi Kokubun 1fea0367d2
Clarify the intention of `false &&` 2020-11-22 22:09:42 -08:00
Nobuyoshi Nakada bf951c763d
An ellipsis (...) can only be placed at the beginning 2020-10-29 18:14:27 +09:00
Nobuyoshi Nakada 396e921044
Escape '/*' within block comment too 2020-10-26 09:01:27 +09:00
Koichi Sasada f6661f5085 sync RClass::ext::iv_index_tbl
iv_index_tbl manages instance variable indexes (ID -> index).
This data structure should be synchronized with other ractors
so introduce some VM locks.

This patch also introduced atomic ivar cache used by
set/getinlinecache instructions. To make updating ivar cache (IVC),
we changed iv_index_tbl data structure to manage (ID -> entry)
and an entry points serial and index. IVC points to this entry so
that cache update becomes atomically.
2020-10-17 08:18:04 +09:00
Koichi Sasada fad97f1f96 sync generic_ivtbl
generic_ivtbl is a process global table to maintain instance variables
for non T_OBJECT/T_CLASS/... objects. So we need to protect them
for multi-Ractor exection.

Hint: we can make them Ractor local for unshareable objects, but
      now it is premature optimization.
2020-10-14 16:36:55 +09:00
Koichi Sasada 79df14c04b Introduce Ractor mechanism for parallel execution
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.
2020-09-03 21:11:06 +09:00
Alan Wu 4c3f0597de Remove the pc argument of vm_trace()
This makes the binary 272 bytes smaller on -O3 GCC 10.2.0.
2020-09-01 22:02:29 -04:00
卜部昌平 acd8ee8dbc tool/prelude.c.tmpl: use RubyVM::CEscape
Do not repeat yourself.
2020-08-11 16:51:07 +09:00
卜部昌平 b0eb5aa344 RubyVM::CEscape#rstring2cstr: do not escape '
A single quote "is representable either by itself or by the escape
sequence", according to ISO/IEC 9899 (checked all versions).  So this is
not a bug fix.  But the generated output is a bit readable without
backslashes.
2020-08-11 16:51:07 +09:00