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

227 Коммитов

Автор SHA1 Сообщение Дата
Yusuke Endoh f691c15792 ext/objspace/lib/objspace/trace.rb: Remove the original Kernel#p
... to disable a "method redefined" warning.

http://rubyci.s3.amazonaws.com/solaris11-gcc/ruby-master/log/20210514T050008Z.fail.html.gz
```
  1) Failure:
TestObjSpace#test_objspace_trace [/export/home/chkbuild/chkbuild-gcc/tmp/build/20210514T050008Z/ruby/test/objspace/test_objspace.rb:621]:
<["objspace/trace is enabled"]> expected but was
<["/export/home/chkbuild/chkbuild-gcc/tmp/build/20210514T050008Z/ruby/.ext/common/objspace/trace.rb:29: warning: method redefined; discarding old p",
 "objspace/trace is enabled"]>.
```
2021-05-14 15:39:57 +09:00
Yusuke Endoh cf1e1879f1 ext/objspace/lib/objspace/trace.rb: Added
This file, when require'ed, starts tracing the object allocations, and
redefines `Kernel#p` to show the allocation site.

This commit is experimental; the library name and APIs may change.

[Feature #17762]
2021-05-14 13:40:32 +09:00
Matt Valentine-House 8bbd319806 Allow newobj_of0 and newobj_slowpath to allocate into multiple heap slots 2021-05-06 09:18:17 -04:00
Peter Zhu 4f88acc833 Fix compiler warnings in objspace_dump.c when assertions are turned on
Example:

```
In file included from ../../../include/ruby/defines.h:72,
                 from ../../../include/ruby/ruby.h:23,
                 from ../../../gc.h:3,
                 from ../../../ext/objspace/objspace_dump.c:15:
../../../ext/objspace/objspace_dump.c: In function ‘dump_append_ld’:
../../../ext/objspace/objspace_dump.c:95:26: warning: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘int’ [-Wsign-compare]
   95 |     RUBY_ASSERT(required <= width);
      |                          ^~
```
2021-04-26 19:26:50 -04:00
卜部昌平 6413dc27dc dependency updates 2021-04-13 14:30:21 +09:00
Jean Boussier 3a888398a6 objspace_dump.c: tag singleton classes and reference the superclass 2021-02-04 09:53:31 -08:00
Jean Boussier 6ca3d1af33 objspace_dump.c: Handle allocation path and line missing 2021-01-20 10:48:13 -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
Nobuyoshi Nakada 6ed6b85ece Expose atomic operation macros with RUBY prefix
Now we need atomic operations, which are lighter than mutex, more
widely for extension libraries because of Ractor.
2020-12-24 11:43:21 +09:00
Aaron Patterson cdc4084b0a Prevent objects from moving while iterating the heap
This iterator uses an st_table, but if objects move the references in
the st table won't be updated.  This patch just changes the st table to
an identity hash.
2020-10-06 16:22:01 -07:00
Kazuhiro NISHIYAMA d0a7189f26 Fix ObjectSpace.dump(obj, output: :stdout)
RDoc says `ObjectSpace.dump(obj, output: :stdout)   # => nil`,
but it returns STDOUT since fbba6bd4e3.

I think it is unintentional change.
2020-10-03 00:00:01 +09:00
Nobuyoshi Nakada b971f141b2
Fix up dependencies on internal/sanitizers.h 2020-09-29 13:14:54 +09:00
Aaron Patterson 0b0e2d88ce Refactor common heap iteration code
We have code common to all heap iteration paths in this file.  Refactor
such that we keep ASAN checks and flags checks in one place
2020-09-28 08:20:23 -07:00
Aaron Patterson b9488accf9 Fix ASAN support when invalidating CCs
Again, this code is walking the heap.  Empty slots can be poisoned, so
we need to unpoison before checking the type
2020-09-28 08:20:23 -07:00
Aaron Patterson 18b3f0f54c Make ext/objspace ASAN friendly
ext/objspace iterates over the heap, but some slots in the heap are
poisoned, so we need to take care of that when running with ASAN
2020-09-28 08:20:23 -07:00
Alan Wu 24820d508b Return nil when argument to ObjectSpace.internal_class_of is T_IMEMO
The added test case crashes the interpreter because it makes
ObjectSpace.internal_class_of return the second VALUE slot of an AST
imemo object. The second VALUE slot of `struct rb_ast_struct` is
not a VALUE and not a pointer to a Ruby object.
2020-09-25 09:27:49 -07:00
Jean Boussier fbba6bd4e3 Parse ObjectSpace.dump_all / dump arguments in Ruby to avoid allocation noise
[Feature #17045] ObjectSpace.dump_all should allocate as little as possible in the GC heap

Up until this commit ObjectSpace.dump_all allocates two Hash because of `rb_scan_args`.

It also can allocate a `File` because of `rb_io_get_write_io`.

These allocations are problematic because `dump_all` dumps the Ruby
heap, so it should try modify as little as possible what it is
observing.
2020-09-15 09:18:13 -07:00
Kazuhiro NISHIYAMA 406559a268
Add missing break
pointed out by Coverity Scan
2020-09-11 11:02:24 +09:00
Jean Boussier 5001cc4716 Optimize ObjectSpace.dump_all
The two main optimization are:
  - buffer writes for improved performance
  - avoid formatting functions when possible

```

|                   |compare-ruby|built-ruby|
|:------------------|-----------:|---------:|
|dump_all_string    |       1.038|   195.925|
|                   |           -|   188.77x|
|dump_all_file      |      33.453|   139.645|
|                   |           -|     4.17x|
|dump_all_dev_null  |      44.030|   278.552|
|                   |           -|     6.33x|
```
2020-09-09 11:11:36 -07:00
Jean Boussier b49a870414 Add a :since option to dump_all
This is useful to see what a block of code allocated, e.g.

```
GC.start
GC.disable
ObjectSpace.trace_object_allocations do
  # run some code
end
gc_gen = GC.count
allocations = ObjectSpace.dump_all(output: :file, since: gc_gen)
GC.enable
GC.start
retentions = ObjectSpace.dump_all(output: :file, since: gc_gen)
```
2020-09-09 08:05:14 -07:00
卜部昌平 490010084e sed -i '/rmodule.h/d' 2020-08-27 16:42:06 +09:00
卜部昌平 756403d775 sed -i '/r_cast.h/d' 2020-08-27 15:03:36 +09:00
卜部昌平 0da2a3f1fc sed -i '\,2/extern.h,d' 2020-08-27 14:07:49 +09:00
Jean Boussier a74df67244 Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized 2020-08-19 08:13:09 -07:00
卜部昌平 99093e1600 RHASH_TBL: is now ext-only
It seems almost no internal codes use RHASH_TBL any longer.  Why not
just eliminate it entirely, so that the macro can be purely ext-only.
2020-08-19 15:10:53 +09:00
Aaron Patterson 7a58ee9b96 Update references when tracing allocations
The allocation tracing code keeps essentially a weak reference to
objects that have been allocated (storing the allocation information
along with the weak ref).  Compacting the heap would break references in
this weak map, so the wrong values could be returned.

This commit just updates the values in the weak ref in order to fix the
allocation tracing book keeping
2020-08-18 19:10:51 -07:00
John Hawthorn 971857c332 Fix method name escaping in ObjectSpace.dump
It's possible to define methods with any name, even if the parser
doesn't support it and it can only be used with ex. send.

This fixes an issue where invalid JSON was output from ObjectSpace.dump
when a method name needed escaping.
2020-08-17 09:47:53 -07:00
Nobuyoshi Nakada 27f7b047e0
Also escape DEL code 2020-08-17 22:36:48 +09:00
Nobuyoshi Nakada 7b4b5e0840
Fixed the radix for control chars 2020-08-17 22:30:26 +09:00
Simon Perepelitsa 09e9f7cf7a [DOC] Clarify ObjectSpace return values are in bytes [ci skip] 2020-07-28 12:13:40 +09:00
Jean Boussier 6a0cb1d649 Avoid allocating a string when dumping an anonymous module or class 2020-07-23 10:52:30 +09:00
Alan Wu cbf52087a2 Fix missing imemo cases in objspace_dump by refactoring
imemo_callcache and imemo_callinfo were not handled by the `objspace`
module and were showing up as "unknown" in the dump. Extract the code for
naming imemos and use that in both the GC and the `objspace` module.
2020-07-10 22:42:35 -04:00
Kazuki Tsujimoto ddded1157a
Introduce find pattern [Feature #16828] 2020-06-14 09:24:36 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Kazuki Tsujimoto 6ed7bc83ec
Fix indentation 2020-05-04 13:27:25 +09:00
Nobuyoshi Nakada e474c189da
Suppress -Wswitch warnings 2020-04-08 15:13:37 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Koichi Sasada b3983c68dd should not expose hidden object.
Hidden object (T_CLASS) can be exposed (BUG).
Also rename rb_mInternalObjectWrapper to rb_cInternalObjectWrapper
because it is a class.
2020-02-29 04:22:17 +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
Koichi Sasada f2286925f0 VALUE size packed callinfo (ci).
Now, rb_call_info contains how to call the method with tuple of
(mid, orig_argc, flags, kwarg). Most of cases, kwarg == NULL and
mid+argc+flags only requires 64bits. So this patch packed
rb_call_info to VALUE (1 word) on such cases. If we can not
represent it in VALUE, then use imemo_callinfo which contains
conventional callinfo (rb_callinfo, renamed from rb_call_info).

iseq->body->ci_kw_size is removed because all of callinfo is VALUE
size (packed ci or a pointer to imemo_callinfo).

To access ci information, we need to use these functions:
vm_ci_mid(ci), _flag(ci), _argc(ci), _kwarg(ci).

struct rb_call_info_kw_arg is renamed to rb_callinfo_kwarg.

rb_funcallv_with_cc() and rb_method_basic_definition_p_with_cc()
is temporary removed because cd->ci should be marked.
2020-02-22 09:58:59 +09:00
Nobuyoshi Nakada 179e402d8a
Updated dependencies on internal/warnings.h
Needed for `UNALIGNED_MEMBER_ACCESS` using `COMPILER_WARNING_`*
macros.
2019-12-31 11:14:19 +09:00
卜部昌平 0c2d731ef2 update dependencies 2019-12-26 20:45:12 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada e1b2341488
Update dependencies 2019-11-18 23:16:22 +09:00
Nobuyoshi Nakada fb6a489af2
Revert "Method reference operator"
This reverts commit 67c5747369.
[Feature #16275]
2019-11-12 17:24:48 +09:00
Yusuke Endoh 99c9431ea1 Rename NODE_ARRAY to NODE_LIST to reflect its actual use cases
and NODE_ZARRAY to NODE_ZLIST.

NODE_ARRAY is used not only by an Array literal, but also the contents
of Hash literals, method call arguments, dynamic string literals, etc.
In addition, the structure of NODE_ARRAY is a linked list, not an array.

This is very confusing, so I believe `NODE_LIST` is a better name.
2019-09-07 13:56:29 +09:00
卜部昌平 6dd60cf114 st_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
st_foreach.  I strongly believe that this commit should have had come
with b0af0592fd, which added extra
parameter to st_foreach callbacks.
2019-08-27 15:52:26 +09:00
git e315f3a134 * expand tabs. 2019-07-31 10:22:47 +09:00
Koichi Sasada 72825c35b0 Use 1 byte hint for ar_table [Feature #15602]
On ar_table, Do not keep a full-length hash value (FLHV, 8 bytes)
but keep a 1 byte hint from a FLHV (lowest byte of FLHV).
An ar_table only contains at least 8 entries, so hints consumes
8 bytes at most. We can store hints in RHash::ar_hint.

On 32bit CPU, we use 4 entries ar_table.

The advantages:
* We don't need to keep FLHV so ar_table only consumes
  16 bytes (VALUEs of key and value) * 8 entries = 128 bytes.
* We don't need to scan ar_table, but only need to check hints
  in many cases. Especially we don't need to access ar_table
  if there is no match entries (in many cases).
  It will increase memory cache locality.

The disadvantages:
* This technique can increase `#eql?` time because hints can
  conflicts (in theory, it conflicts once in 256 times).
  It can introduce incompatibility if there is a object x where
  x.eql? returns true even if hash values are different.
  I believe we don't need to care such irregular case.
* We need to re-calculate FLHV if we need to switch from ar_table
  to st_table (e.g. exceeds 8 entries).
  It also can introduce incompatibility, on mutating key objects.
  I believe we don't need to care such irregular case too.

Add new debug counters to measure the performance:
* artable_hint_hit - hint is matched and eql?#=>true
* artable_hint_miss - hint is not matched but eql?#=>false
* artable_hint_notfound - lookup counts
2019-07-31 09:52:03 +09:00