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

36 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 187c164d71
Suppress unused-variable warning
`key` is not used outside this assertion.
2020-08-10 17:49:08 +09:00
卜部昌平 32623150cd reroute redefinition of NDEBUG
NDEBUG can be defined via a command-line argument.  Should take care of
such situations.
2020-04-21 13:07:19 +09:00
Koichi Sasada b9007b6c54 Introduce disposable call-cache.
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.
2020-02-22 09:58:59 +09:00
卜部昌平 eb92159d72 Revert https://github.com/ruby/ruby/pull/2486
This reverts commits: 10d6a3aca7 8ba48c1b85 fba8627dc1 dd883de5ba
6c6a25feca 167e6b48f1 7cb96d41a5 3207979278 595b3c4fdd 1521f7cf89
c11c5e69ac cf33608203 3632a812c0 f56506be0d 86427a3219 .

The reason for the revert is that we observe ABA problem around
inline method cache.  When a cache misshits, we search for a
method entry.  And if the entry is identical to what was cached
before, we reuse the cache.  But the commits we are reverting here
introduced situations where a method entry is freed, then the
identical memory region is used for another method entry.  An
inline method cache cannot detect that ABA.

Here is a code that reproduce such situation:

```ruby
require 'prime'

class << Integer
  alias org_sqrt sqrt
  def sqrt(n)
    raise
  end

  GC.stress = true
  Prime.each(7*37){} rescue nil # <- Here we populate CC
  class << Object.new; end

  # These adjacent remove-then-alias maneuver
  # frees a method entry, then immediately
  # reuses it for another.
  remove_method :sqrt
  alias sqrt org_sqrt
end

Prime.each(7*37).to_a # <- SEGV
```
2019-10-03 12:45:24 +09:00
卜部昌平 3632a812c0 refactor add rb_id_table_foreach_with_replace_with_key
This is a pure refactoring to reduce copy & paste.  Also the new
function is made visible from other parts of the interpreter, to
be used later.
2019-09-30 10:26:38 +09:00
tenderlove 91793b8967 Add `GC.compact` again.
🙏

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 01:19:47 +00:00
tenderlove 744e5df715 Reverting compaction for now
For some reason symbols (or classes) are being overridden in trunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 09:41:41 +00:00
tenderlove 3c55b643ae Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 03:17:25 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
nobu b8e3a4bd2c id_table.c: use NULL as ID* instead of Qundef
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 06:44:43 +00:00
nobu 5ae753dfa3 Adjusted styles
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 06:44:41 +00:00
tenderlove 3ef4db15e9 Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 20:32:04 +00:00
nobu 6924066a65 adjust styles [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-10 00:39:26 +00:00
ko1 4c2d014e92 swithc id_table data structure.
* id_table.c: swtich to "simple open addressing with quadratic probing"
  by Yura Sokolov.  For more detail measurements, see [Feature #12180]
* id_table.c: remove other algorithms to simplify the source code.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-25 03:03:52 +00:00
nobu 00ed779cb0 id_table.c: fix typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-19 05:24:34 +00:00
nobu dfe1d4fda6 id_table.c: extend, don't shrink
* id_table.c (hash_table_extend): should not shrink the table than
  the previous capacity.  [ruby-core:76534] [Bug #12614]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-14 13:35:42 +00:00
nobu a62dcd947c id_table.h: dummy sentinel
* id_table.h (rb_id_table_iterator_result): add dummy sentinel
  member because C standard prohibits a trailing comma.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-06 00:35:33 +00:00
ngoto 02cafdf491 capa should be even number on 64-bit SPARC for 8-byte word alignment
* id_table.c (list_id_table_init): When unaligned word access is
  prohibited and sizeof(VALUE) is 8 (64-bit machines),
  capa should always be even number for 8-byte word alignment
  of the values of a table. This code assumes that sizeof(ID) is 4,
  sizeof(VALUE) is 8, and xmalloc() returns 8-byte aligned memory.
  This fixes bus error on 64-bit SPARC Solaris 10.
  [Bug #12406][ruby-dev:49631]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 14:55:23 +00:00
nobu 439224a590 RUBY_ASSERT
* error.c (rb_assert_failure): assertion with stack dump.
* ruby_assert.h (RUBY_ASSERT): new header for the assertion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-22 08:33:55 +00:00
normal b147b5a3b8 id_table: const correctness for _size and _memsize
This allows us to swap in rb_id_table_memsize for st_memsize
(which takes a "const st_table *") more easily.

It also makes sense to do the same for rb_id_table_size,
too; as the table cannot be altered when accessing size.

* id_table.h (rb_id_table_size): const arg
  (rb_id_table_memsize): ditto
* id_table.c (st_id_table_size): ditto
  (st_id_table_memsize): ditto
  (list_id_table_size): ditto
  (list_id_table_memsize): ditto
  (hash_id_table_size): ditto
  (hash_id_table_memsize): ditto
  (mix_id_table_size): ditto
  (mix_id_table_memsize): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-02 22:18:32 +00:00
ko1 840e6b6307 * id_table.c (mix_id_table_insert): do not touch list during
list->hash transition because GC can run during transition.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-01 08:17:25 +00:00
nobu 7f13f878cf id_table.c: fix prototype names
* id_table.c: fix prototype names, missing underscore prefixes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-27 00:23:18 +00:00
nobu 33ed298379 id_table.c: fix prototype names
* id_table.c: fix prototype names, missing underscore prefixes.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-27 00:17:53 +00:00
nobu 6b64ffd225 id_table.c: suppress warnings
* id_table.c (UNUSED): mark implementation functions maybe-unused
  to suppress warnings by old gcc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-27 00:10:47 +00:00
hsbt 1bbe442f80 * id_table.c: fix typo. [ci skip][fix GH-1031] Patch @davydovanton
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-25 00:47:17 +00:00
nobu 80e386e92c id_table.c: fix types
* id_table.c (insert_into_chain, insert_into_main): fix argument
  types in prototype declarations.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-17 01:01:39 +00:00
nobu a3b9b9870e id_table.c: aliases
* id_table.c (IMPL_TYPE, IMPL_VOID): make aliases if supported on
  the platform.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-26 01:20:31 +00:00
nobu 38cfb957dd id_table.h: callback function types
* id_table.h (rb_id_table_foreach_func_t): define callback
  function type for rb_id_table_foreach().

* id_table.h (rb_id_table_foreach_values_func_t): ditto for
  rb_id_table_foreach_values().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-26 00:47:10 +00:00
nobu 86fd28d11e id_table.c: adjust indent
* id_table.c (list_table_extend, fix_empty): adjust indent.
  (hash_id_table_foreach_values): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-26 00:46:58 +00:00
nobu f92ed1943c id_table.c: constify
* id_table.c (find_empty): constify static data.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-26 00:46:34 +00:00
nobu 341c84ed22 id_table.c: fix for C89 compilers
* id_table.c (list_table_extend, hash_table_extend): remove C99
  features.  [ruby-dev:49239] [Bug #11487]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-26 00:26:02 +00:00
nobu 235e7738d6 id_table.c: TOKEN_PASTE
* id_table.c (IMPL1): use TOKEN_PASTE, and prevent `op' from
  expansion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-13 04:41:54 +00:00
nobu 2c3b813bd3 id_table.c: prefix first
* id_table.c (IMPL): prepend id_table to the argument before its
  expansion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 13:20:21 +00:00
ko1 1761312577 * id_table.c: IMPL() macro accept op as _opname instead of opname
because jemalloc seems to replace the word `free' to `je_free'.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 12:59:29 +00:00
ko1 e514914919 * id_table.c (mix_id_table_insert): fix memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 12:51:56 +00:00
ko1 c35ff11ae5 * id_table.h: introduce ID key table.
[Feature #11420]
  This table only manage ID->VALUE table to reduce overhead of st.
  Some functions prefixed rb_id_table_* are provided.
* id_table.c: implement rb_id_table_*.
  There are several algorithms to implement it.
  Now, there are roughly 4 types:
    * st
    * array
    * hash (implemented by  Yura Sokolov)
    * mix of array and hash
  The macro ID_TABLE_IMPL can choose implementation.
  You can see detailes about them at the head of id_table.c.
  At the default, I choose 34 (mix of list and hash).
  This is not final decision.
  Please report your suitable parameters or
  your data structure.
  * symbol.c: introduce rb_id_serial_t and rb_id_to_serial()
    to represent ID by serial number.
  * internal.h: use id_table for method tables.
  * class.c, gc.c, marshal.c, vm.c, vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 08:43:55 +00:00