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

1563 Коммитов

Автор SHA1 Сообщение Дата
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
Jose Narvaez 4e2eb7695e Yet Another Ruby JIT!
Renaming uJIT to YJIT. AKA s/ujit/yjit/g.
2021-10-20 18:19:31 -04:00
Alan Wu 57977ba30d uJIT: Implement opt_getinlinecache
* ujit: implement opt_getinlinecache

Aggressively bet that writes to constants don't happen and invalidate
all opt_getinlinecache blocks on any and all constant writes.

Use alignment padding on block_t to track this assumption. No change to
sizeof(block_t).

* Fix compile warnings when not RUBY_DEBUG
* Fix reversed condition
* Switch to st_table to keep track of assumptions

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2021-10-20 18:19:30 -04:00
Alan Wu faabe2b0ad Ujit bug fixes
* uJIT: don't compile tailcalls

* Don't compile calls to protected methods

We need to generate extra code to check whether the call goes through if
we want to support these.

* Fix copy pasta

* Update blockids in branches

* Update dependencies
2021-10-20 18:19:29 -04:00
Alan Wu c02517bacb Tie lifetime of uJIT blocks to iseqs
* Tie lifetime of uJIT blocks to iseqs

   Blocks weren't being freed when iseqs are collected.

* Add rb_dary. Use it for method dependency table

* Keep track of blocks per iseq

  Remove global version_tbl

* Block version bookkeeping fix

* dary -> darray

* free ujit_blocks

* comment about size of ujit_blocks
2021-10-20 18:19:29 -04:00
Alan Wu 25234f8a1c Update dependencies 2021-10-20 18:19:27 -04:00
Aaron Patterson e427fdff0a Directly link libcapstone for easier development
This lets us use libcapstone directly from miniruby so we don't need a
Ruby Gem to to dev work.

Example usage:

```ruby
def foo(x)
  if x < 1
    "wow"
  else
    "neat"
  end
end

iseq = RubyVM::InstructionSequence.of(method(:foo))
puts UJIT.disasm(iseq)
100.times { foo 1 }
puts UJIT.disasm(iseq)
```

Then in the terminal

```
$ ./miniruby test.rb

== disasm: #<ISeq:foo@test.rb:1 (1,0)-(7,3)> (catch: FALSE)
local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] x@0<Arg>
0000 getlocal_WC_0                          x@0                       (   2)[LiCa]
0002 putobject_INT2FIX_1_
0003 opt_lt                                 <calldata!mid:<, argc:1, ARGS_SIMPLE>
0005 branchunless                           10
0007 putstring                              "wow"                     (   3)[Li]
0009 leave                                                            (   7)[Re]
0010 putstring                              "neat"                    (   5)[Li]
0012 leave                                                            (   7)[Re]

== ISEQ RANGE: 10 -> 10 ========================================================
        0x0:    movabs  rax, 0x7fe816e2d1a0
        0xa:    mov     qword ptr [rdi], rax
        0xd:    mov     r8, rax
        0x10:   mov     r9, rax
        0x13:   mov     r11, r12
        0x16:   jmp     qword ptr [rax]
== ISEQ RANGE: 0 -> 7 ==========================================================
        0x0:    mov     rax, qword ptr [rdi + 0x20]
        0x4:    mov     rax, qword ptr [rax - 0x18]
        0x8:    mov     qword ptr [rdx], rax
        0xb:    mov     qword ptr [rdx + 8], 3
        0x13:   movabs  rax, 0x7fe817808200
        0x1d:   test    byte ptr [rax + 0x3e6], 1
        0x24:   jne     0x3ffff7b
        0x2a:   test    byte ptr [rdx], 1
        0x2d:   je      0x3ffff7b
        0x33:   test    byte ptr [rdx + 8], 1
        0x37:   je      0x3ffff7b
        0x3d:   mov     rax, qword ptr [rdx]
        0x40:   cmp     rax, qword ptr [rdx + 8]
        0x44:   movabs  rax, 0
        0x4e:   movabs  rcx, 0x14
        0x58:   cmovl   rax, rcx
        0x5c:   mov     qword ptr [rdx], rax
        0x5f:   test    qword ptr [rdx], -9
        0x66:   jne     0x3ffffd5
```

Make sure to `brew install pkg-config capstone`
2021-10-20 18:19:27 -04:00
Alan Wu 331f662ddb Update dependencies 2021-10-20 18:19:27 -04:00
Maxime Chevalier-Boisvert e4c65ec49c Refactor uJIT code into more files for readability 2021-10-20 18:19:26 -04:00
Alan Wu d9ab1e9563 Update dependencies 2021-10-20 18:19:25 -04:00
Alan Wu f500c1e321 Update dependency 2021-10-20 18:19:24 -04:00
Alan Wu 5f4e30be66 Run ruby tool/update-deps --fix 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
Alan Wu 25acbaf4f6 Don't assume srcdir is cwd 2021-10-20 18:19:23 -04:00
Maxime Chevalier-Boisvert b8a3f2ed61 Add function to print strings from generated code 2021-10-20 18:19:23 -04:00
Alan Wu 1665bbacc1 Fix typo 2021-10-20 18:19:23 -04:00
Alan Wu 4d959a25e4 Fix dependency for ujit_examples.h
Once this works on GNU/Linux this could be done semi automatically.
2021-10-20 18:19:23 -04:00
Maxime Chevalier-Boisvert 1c8fb90f6b Add new files, ujit_compile.c, ujit_compile.h 2021-10-20 18:19:23 -04:00
Maxime Chevalier-Boisvert 8f40a62647 Progress on x86 assembler. Encode a few simple instructions. 2021-10-20 18:19:22 -04:00
Maxime Chevalier-Boisvert 0a5dcc056e Progress on porting x86 assembler for MicroJIT 2021-10-20 18:19:22 -04:00
Alan Wu 16c5ce863c Yeah, this actually works! 2021-10-20 18:19:22 -04:00
Kazuhiro NISHIYAMA f310c19544
Suppress some messages on building mjit header 2021-10-12 18:07:55 +09:00
Jean Boussier afcbb501ac marshal.c Marshal.load accepts a freeze: true option.
Fixes [Feature #18148]

When set, all the loaded objects are returned as frozen.

If a proc is provided, it is called with the objects already frozen.
2021-10-05 18:34:56 +02:00
卜部昌平 5c167a9778 ruby tool/update-deps --fix 2021-10-05 14:18:23 +09:00
Koichi Sasada bc96a45f12 introduce debug.gem
For the `test-bundled-gems`, make `debug.so` with extconf.rb and
`make` command directly because `rake-compiler` assume ruby is
installed (but `test-bundled-gems` can run without installation).
2021-10-05 02:07:33 +09:00
Nobuyoshi Nakada d087214658 Restore Hash#compare_by_identity mode [Bug #18171] 2021-10-02 11:43:35 +09:00
Nobuyoshi Nakada 545e01645f
lldb: Show encoding of String [ci skip] 2021-09-28 20:03:54 +09:00
Nobuyoshi Nakada 18f0b7c2f7
Fix dependency of verconf.h
template/verconf.h.tmpl reads rbconfig.rb.
2021-09-26 09:48:53 +09:00
Nobuyoshi Nakada 6e1507f8a2
Explicit the target of do-install-all as the same as dont-install-all 2021-09-21 23:58:00 +09:00
Nobuyoshi Nakada 98c5907c65
Ripper source on mswin
* Get rid of command substitution for cmd.exe.
* Separate RM1 command to remove single file sans directory.
2021-09-21 13:05:27 +09:00
Samuel Williams b61064b821 Add gvl and fiber assertions to scheduler interface to catch invalid usage. 2021-09-20 23:16:45 +12:00
Nobuyoshi Nakada bf5711f498
Check ruby-related includes only [ci skip] 2021-09-11 15:01:22 +09:00
Hiroshi SHIBATA 934feb1dee Removed minitest dir from make task 2021-09-11 08:48:03 +09:00
卜部昌平 a310f896db common.mk: update dependencies 2021-09-10 20:00:06 +09:00
Nobuyoshi Nakada 3562c7ba33
Update the list of replacing objects under missing 2021-08-27 12:43:45 +09:00
Nobuyoshi Nakada 04be8e84db
Use C99-defined macros to classify a floating-point number 2021-08-27 12:41:30 +09:00
Yusuke Endoh b44741f5dc tool/test-bundled-gems.rb: Use the bundled RBS code to test TypeProf
Formerly, TypeProf was tested with the latest RBS code during
`make test-bundled-gems`. However, when a new version of rbs is
released, and if it is incompatible with TypeProf,
`make test-bundled-gems` starts failing, which was annoying.

By this change, TypeProf is tested with the bundled version of RBS.
2021-08-25 11:13:17 +09:00
Yusuke Endoh 4a6b5f4622 Revert "tool/test-bundled-gems.rb: Use the bundled RBS code to test TypeProf"
This reverts commit 22deda43cb.

It was incomplete. Sorry!
2021-08-24 18:08:16 +09:00
Yusuke Endoh 22deda43cb tool/test-bundled-gems.rb: Use the bundled RBS code to test TypeProf
Formerly, TypeProf was tested with the latest RBS code during
`make test-bundled-gems`. However, when a new version of rbs is
released, and if it is incompatible with TypeProf,
`make test-bundled-gems` starts failing, which was annoying.

By this change, TypeProf is tested with the bundled version of RBS.
2021-08-24 17:43:11 +09:00
Nobuyoshi Nakada c38c2d8ee2 Moved exported symbols in internal/util.h to ruby/util.h
[Feature #18051]
2021-08-24 10:37:41 +09:00
Benoit Daloze e57a1cc20c ruby/spec no longer needs webrick to run 2021-08-13 18:15:02 +02:00
Nobuyoshi Nakada 6e60fc2945
Group commands on GitHub Actions 2021-08-07 18:32:24 +09:00
Martin Dürst 01e98d8785 Change Unicode Emoji Version from 13.0 to 13.1 2021-07-27 17:10:49 +09:00
Nobuyoshi Nakada fa239e0479
Remove unneeded quotes [ci skip] 2021-07-19 17:18:51 +09:00
Samuel Williams 6073a8bdc0 Add debug assertion in `rb_funcall*` that the current thread has the gvl. 2021-07-16 17:32:02 +12:00
Martin Dürst b6113a3fd8 Update common.mk to deal with Unicode version 13.0.0
- Change Unicode version to 13.0.0
- Change Emoji version to 13.0
- Adjust to moved locations of emoji-data.txt and emoji-variation-sequences.txt
  by splitting these files from $(UNICODE_EMOJI_FILES) and putting them into
  a new group $(UNICODE_UCD_EMOJI_FILES)
2021-07-08 14:45:03 +09:00
Nobuyoshi Nakada cca2f7ab14
programs will be made from exts
`programs` after `exts` overwrites programs built with extension
libraries when static-linked-ext.
2021-07-05 11:17:42 +09:00
Nobuyoshi Nakada ac6924e10e
goruby.c: include golf_prelude.c to get rid of overwriting EXTOBJS 2021-07-03 22:39:14 +09:00
Nobuyoshi Nakada 0feec79846
"nodoc" needs to exclude "doc" [ci skip] 2021-06-30 19:56:37 +09:00
eileencodes b91b3bc771 Add a cache for class variables
Redo of 34a2acdac788602c14bf05fb616215187badd504 and
931138b00696419945dc03e10f033b1f53cd50f3 which were reverted.

GitHub PR #4340.

This change implements a cache for class variables. Previously there was
no cache for cvars. Cvar access is slow due to needing to travel all the
way up th ancestor tree before returning the cvar value. The deeper the
ancestor tree the slower cvar access will be.

The benefits of the cache are more visible with a higher number of
included modules due to the way Ruby looks up class variables. The
benchmark here includes 26 modules and shows with the cache, this branch
is 6.5x faster when accessing class variables.

```
compare-ruby: ruby 3.1.0dev (2021-03-15T06:22:34Z master 9e5105c) [x86_64-darwin19]
built-ruby: ruby 3.1.0dev (2021-03-15T12:12:44Z add-cache-for-clas.. c6be009) [x86_64-darwin19]

|         |compare-ruby|built-ruby|
|:--------|-----------:|---------:|
|vm_cvar  |      5.681M|   36.980M|
|         |           -|     6.51x|
```

Benchmark.ips calling `ActiveRecord::Base.logger` from within a Rails
application. ActiveRecord::Base.logger has 71 ancestors. The more
ancestors a tree has, the more clear the speed increase. IE if Base had
only one ancestor we'd see no improvement. This benchmark is run on a
vanilla Rails application.

Benchmark code:

```ruby
require "benchmark/ips"
require_relative "config/environment"

Benchmark.ips do |x|
  x.report "logger" do
    ActiveRecord::Base.logger
  end
end
```

Ruby 3.0 master / Rails 6.1:

```
Warming up --------------------------------------
              logger   155.251k i/100ms
Calculating -------------------------------------
```

Ruby 3.0 with cvar cache /  Rails 6.1:

```
Warming up --------------------------------------
              logger     1.546M i/100ms
Calculating -------------------------------------
              logger     14.857M (± 4.8%) i/s -     74.198M in   5.006202s
```

Lastly we ran a benchmark to demonstate the difference between master
and our cache when the number of modules increases. This benchmark
measures 1 ancestor, 30 ancestors, and 100 ancestors.

Ruby 3.0 master:

```
Warming up --------------------------------------
            1 module     1.231M i/100ms
          30 modules   432.020k i/100ms
         100 modules   145.399k i/100ms
Calculating -------------------------------------
            1 module     12.210M (± 2.1%) i/s -     61.553M in   5.043400s
          30 modules      4.354M (± 2.7%) i/s -     22.033M in   5.063839s
         100 modules      1.434M (± 2.9%) i/s -      7.270M in   5.072531s

Comparison:
            1 module: 12209958.3 i/s
          30 modules:  4354217.8 i/s - 2.80x  (± 0.00) slower
         100 modules:  1434447.3 i/s - 8.51x  (± 0.00) slower
```

Ruby 3.0 with cvar cache:

```
Warming up --------------------------------------
            1 module     1.641M i/100ms
          30 modules     1.655M i/100ms
         100 modules     1.620M i/100ms
Calculating -------------------------------------
            1 module     16.279M (± 3.8%) i/s -     82.038M in   5.046923s
          30 modules     15.891M (± 3.9%) i/s -     79.459M in   5.007958s
         100 modules     16.087M (± 3.6%) i/s -     81.005M in   5.041931s

Comparison:
            1 module: 16279458.0 i/s
         100 modules: 16087484.6 i/s - same-ish: difference falls within error
          30 modules: 15891406.2 i/s - same-ish: difference falls within error
```

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-06-18 10:02:44 -07:00