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

1998 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 8d6e9b6658
Suppress false warning for freed pointer 2021-10-24 16:20:34 +09:00
Aaron Patterson 844588f915 Push compaction page alignment check down
It seems like `gc_verify_compaction_references` is not protected in case
alignment is wrong.  This commit pushes the alignment check down to
`gc_start_internal` so that anyone trying to compact will check page
alignment

I think this method may be getting called on PowerPC and the alignment
might be wrong.

  http://rubyci.s3.amazonaws.com/ppc64le/ruby-master/log/20211021T190006Z.fail.html.gz
2021-10-21 15:47:38 -07:00
Aaron Patterson 0d63600e4f Partial revert of ceebc7fc98
I'm looking through the places where YJIT needs notifications.  It looks
like these changes to gc.c and vm_callinfo.h have become unnecessary
since 84ab77ba59.  This commit just makes the diff against upstream
smaller, but otherwise shouldn't change any behavior.
2021-10-20 18:19:36 -04:00
Alan Wu c378c7a7cb MicroJIT: generate less code for CFUNCs
Added UJIT_CHECK_MODE. Set to 1 to double check method dispatch in
generated code.

It's surprising to me that we need to watch both cc and cme. There might
be opportunities to simplify there.
2021-10-20 18:19:26 -04:00
Aaron Patterson b0c3f18ec5 Print errno when mprotect fails
Trying to figure out the problem on s390x.
2021-10-20 15:06:40 -07:00
S.H e54d1e99e9
Move rb_ractor_p definition 2021-10-04 08:21:40 +09:00
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
Nobuyoshi Nakada ff480f2953
Cast to void pointer to suppress -Wformat-pedantic in RUBY_DEBUG_LOG 2021-10-03 13:59:48 +09:00
Nobuyoshi Nakada f7ffe9dbde
Introduce `RBIMPL_NONNULL_ARG` macro
Runtime assertion for the argument declared as non-null.
This macro does nothing if `RBIMPL_ATTR_NONNULL` is effective,
otherwise asserts that the argument is non-null.
2021-09-27 14:47:52 +09:00
Peter Zhu 9770bf23b7 Fix malloc_increase is not correctly calculated
Commit 123eeb1c1a added incremental GC
which moved resetting malloc_increase, oldmalloc_increase to before
marking. However, during_minor_gc is not set until gc_marks_start. So
the value will be from the last GC run, rather than the current one.
Before the incremental GC commit, this code was in gc_before_sweep
which ran before sweep (after marking) so the value during_minor_gc
was correct.
2021-09-20 09:01:58 -04:00
Peter Zhu db51bcada4 Fix total_freed_objects for invalidated pages
When the object is moved back into the T_MOVED, the flags of the T_MOVED
is not copied, so the FL_FROM_FREELIST flag is lost. This causes
total_freed_objects to always be incremented.
2021-09-15 09:59:37 -04:00
Peter Zhu a65ac2d6fa Don't overwrite free_slots count during sweeping
gc_compact_finish may invalidate pages, which may move objects from this
page to other pages, which updates the free_slots of this page.
2021-09-15 09:00:42 -04:00
Peter Zhu e624d0d202 Update the free_slots count of the original page
When invalidating a page during compaction, the free_slots count should
be updated for the page of the object and not the page of the forwarding
address (since the object gets moved back to the forwarding address).
2021-09-15 09:00:42 -04:00
S-H-GAMELINKS 032534dbdf Using RB_BIGNUM_TYPE_P macro 2021-09-11 09:13:24 +09:00
卜部昌平 64f271241d suppress GCC's -Wnonnull-compare
This particular NULL check must be a good thing to do both statically
and dynamically.
2021-09-10 20:00:06 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Peter Zhu 0aa82b592f Remove heap_is_swept_object function
is_swept_object just calls heap_is_swept_object so remove
heap_is_swept_object.
2021-09-01 13:42:22 -04:00
Peter Zhu ed31bdfeee Fix memory leak in Variable Width Allocation
Force recycled objects could create a freelist for the page. At the
start of sweeping we should append to the freelist to avoid
permanently losing the slots on the freelist.
2021-08-27 10:13:32 -04:00
Peter Zhu 62bc4a9420 [Feature #18045] Implement size classes for GC
This commits implements size classes in the GC for the Variable Width
Allocation feature. Unless `USE_RVARGC` compile flag is set, only a
single size class is created, maintaining current behaviour. See the
redmine ticket for more details.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-08-25 09:28:21 -04:00
Peter Zhu c08d4067be [Feature #18045] Remove T_PAYLOAD
This commit removes T_PAYLOAD since the new VWA implementation no longer
requires T_PAYLOAD types.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-08-25 09:28:21 -04:00
Peter Zhu 6648b411f7 Replace intptr_t with uintptr_t in gc.c
Pointers may be large to the point where intptr_t would be negative.
This is problematic when doing comparisons of pointers.
2021-08-23 14:57:52 -04:00
Peter Zhu eddd369e73 Revert "[Feature #18045] Implement size classes for GC"
This reverts commits 48ff7a9f3e
and b2e2cf2ded because it is causing
crashes in SPARC solaris and i386 debian.
2021-08-23 10:54:53 -04:00
Peter Zhu b2e2cf2ded [Feature #18045] Implement size classes for GC
This commits implements size classes in the GC for the Variable Width
Allocation feature. Unless `USE_RVARGC` compile flag is set, only a
single size class is created, maintaining current behaviour. See the
redmine ticket for more details.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-08-23 09:15:42 -04:00
Peter Zhu 48ff7a9f3e [Feature #18045] Remove T_PAYLOAD
This commit removes T_PAYLOAD since the new VWA implementation no longer
requires T_PAYLOAD types.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-08-23 09:15:42 -04:00
Nobuyoshi Nakada 4c93c124c2
Turned the reminder comment to a compile-time message 2021-08-20 15:18:13 +09:00
Mike Dalessio e8e3b7a0e2 Undefine the alloc function for T_DATA classes
which have not undefined or redefined it.

When a `T_DATA` object is created whose class has not undefined or
redefined the alloc function, the alloc function now gets undefined by
Data_Wrap_Struct et al. Optionally, a future release may also warn
that this being done.

This should help developers of C extensions to meet the requirements
explained in "doc/extension.rdoc". Without a check like this, there is
no easy way for an author of a C extension to see where they have made
a mistake.
2021-08-20 08:30:06 +09:00
Nobuyoshi Nakada ee7bd7d732
`SIZE_MAX` is not `size_t` on emscripten 2021-08-16 15:36:37 +09:00
Peter Zhu 79cc566ab4 Make during_compacting flag in GC one bit
Commit c32218de1b turned during_compacting
flag to 2 bits to support the case when there is no write barrier. But
commit 32b7dcfb56 changed compaction to
always enable the write barrier. This commit cleans up some of the
leftover code.
2021-08-11 09:26:19 -04:00
Nobuyoshi Nakada 587f501c7c
Make bit flags `reason` unsigned 2021-08-08 17:13:33 +09:00
Nobuyoshi Nakada f81964568f
Suppress warnings when GC_ENABLE_INCREMENTAL_MARK == 0 2021-08-08 15:13:49 +09:00
S.H 378e8cdad6
Using RBOOL macro 2021-08-02 12:06:44 +09:00
Jeremy Evans 87b327efe6 Do not check pending interrupts when running finalizers
This fixes cases where exceptions raised using Thread#raise are
swallowed by finalizers and not delivered to the running thread.

This could cause issues with finalizers that rely on pending interrupts,
but that case is expected to be rarer.

Fixes [Bug #13876]
Fixes [Bug #15507]

Co-authored-by: Koichi Sasada <ko1@atdot.net>
2021-07-29 09:44:11 -07:00
Nobuyoshi Nakada 377995035a Suppress exception message in finalizer [Feature #17798] 2021-07-23 12:01:15 +09:00
Nobuyoshi Nakada fc4dd45d01 Show exception in finalizer [Feature #17798] 2021-07-23 12:01:15 +09:00
Nobuyoshi Nakada 63e5f4df38 Access rb_execution_context_t::errinfo directly 2021-07-23 12:01:15 +09:00
Nobuyoshi Nakada b726c4ee38 Use rb_equal
It can be optimized and handles Qnil properly.
2021-07-23 10:25:37 +09:00
Nobuyoshi Nakada 4da07ac2f3 Finalizers no longer store the safe level 2021-07-23 10:25:37 +09:00
Peter Zhu 62661dd9e4 Don't recompute the heap page
We already page the page of the zombie calculated. Don't recalculate the
page.
2021-07-22 10:10:23 -04:00
Peter Zhu 018f3961ae Don't set flags in finalize_list
The call after it to `heap_page_add_freeobj` will set the flags.
2021-07-22 10:10:23 -04:00
Peter Zhu 31144fe987 Change GC verification to walk all pages
`gc_verify_internal_consistency_` does not walk pages in the tomb heap
so numbers were off. This commit changes it to walk all allocated pages.
2021-07-21 14:40:44 -04:00
Peter Zhu e5fe48646c [Bug #18014] Add assertion to verify freelist
This commit adds an assertion has been added after `gc_page_sweep` to
verify that the freelist length is equal to the number of free slots in
the page.
2021-07-15 11:48:52 -04:00
Peter Zhu 4a627dbdfd [Bug #18014] Fix memory leak in GC when using Ractors
When a Ractor is removed, the freelist in the Ractor cache is not
returned to the GC, leaving the freelist permanently lost. This commit
recycles the freelist when the Ractor is destroyed, preventing a memory
leak from occurring.
2021-07-15 11:48:52 -04:00
Peter Zhu 119697f61e [Bug #18014] Fix rb_gc_force_recycle unmark before sweep
If we force recycle an object before the page is swept, we should clear
it in the mark bitmap. If we don't clear it in the bitmap, then during
sweeping we won't account for this free slot so the `free_slots` count
of the page will be incorrect.
2021-07-15 11:48:52 -04:00
Nobuyoshi Nakada cb3eb3d7d5
Get rid of conflict in ccan/list
Undefine LIST_HEAD from BSD-origin sys/queue.h.
2021-07-10 17:39:25 +09:00
Yusuke Endoh 1293042307 gc.c: use each_stack_location for emscripten
follow up of e4e416380d
2021-07-07 17:17:52 +09:00
Peter Zhu 4a3df35239 Use stride passed into os_obj_of_i 2021-06-30 16:12:03 -04:00
Peter Zhu 03dc664493 Fix crash on RGENGC_CHECK_MODE=4
When running btest there is a crash when compiled with
RGENGC_CHECK_MODE=4. The crash happens because `during_gc` is not
turned off before `gc_marks_check` is called, causing the marking to
happen on the main mark stack instead of mark stack created in
`objspace_allrefs`.
2021-06-29 09:28:07 -04:00
eileencodes 4f77a54f07 Fix asan error when walking heap for T_PAYLOAD objects
Related to https://bugs.ruby-lang.org/issues/18001

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-06-22 14:34:08 -07: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
Peter Zhu c639b58823 Refactor heap_set_increment
heap_set_increment essentially only calls heap_allocatable_pages_set.
They only differ in behaviour when `additional_pages == 0`. However,
this is only possible because heap_extend_pages may return 0. This
commit also changes heap_extend_pages to always return at least 1.
2021-06-17 10:58:48 -04:00