161 Commits

Author SHA1 Message Date
Nobuyoshi Nakada
b68ef95a51 [Feature #22215] Extract internal objspace API
Provide narrow accessors so `ext/objspace` does not depend on call
cache and call info layouts.
2026-08-07 09:59:15 +09:00
Peter Zhu
a6e302509b [DOC] Improve docs for ObjectSpace::InternalObjectWrapper#internal_object_id 2026-06-14 14:19:50 +09:00
Peter Zhu
28da8f9104 [DOC] Improve docs for ObjectSpace::InternalObjectWrapper#type 2026-06-11 14:31:46 +09:00
Peter Zhu
8c434d03bd [DOC] Improve class docs for ObjectSpace::InternalObjectWrapper 2026-06-10 10:08:32 +09:00
Peter Zhu
82329a5053 [DOC] Improve docs for ObjectSpace.internal_super_of 2026-06-09 09:17:13 +09:00
Peter Zhu
623fa94e9e [DOC] Improve docs for ObjectSpace.memsize_of 2026-06-04 07:55:45 +09:00
Peter Zhu
2ff671c93d [DOC] Improve docs for ObjectSpace.internal_class_of 2026-06-03 14:33:09 +09:00
Peter Zhu
1d3e2bd2b8 [DOC] Improve docs for ObjectSpace.reachable_objects_from_root 2026-06-03 09:31:49 +09:00
Jean Boussier
99dc513d15 Use IMEMO to store cdhash
RHash isn't a good fit for storing `cdhash` as this force to allow
arbitrary hash types into RHash, which doesn't work with AR tables.

It also cause the cdhash to be larger than needed.
2026-05-18 08:58:32 +03:00
John Hawthorn
f71840a230 Replace subclasses linked list with weakref array 2026-05-13 18:36:51 -07:00
Peter Zhu
b1a26097ad [DOC] Improve docs for ObjectSpace.reachable_objects_from 2026-05-13 20:01:54 -04:00
Peter Zhu
834a828f9b [DOC] Improve docs for ObjectSpace.count_objects_size 2026-05-07 20:27:45 -04:00
Peter Zhu
4f28236d51 [DOC] Fix hash style in ObjectSpace.count_objects_size 2026-05-06 21:27:56 -04:00
Jean Boussier
47e061277a class.c: Make cvc_tbl a managed object
[Bug #21952]

Solves the double-free or use after-free concern with boxes.
Now entries can safely be used for copy-on-write.

Also is likely necessary to make it save to read cvar from
secondary ractors, as allowed since: ab32c0e690b805cdaaf264ad4c3421696c588204
2026-04-21 16:30:14 +09:00
Augustin Gottlieb
6ef0eb29c6
Add early type validation for ObjectSpace.memsize_of_all klass argument 2026-01-23 11:00:37 +09:00
Peter Zhu
00a3b71eaf [DOC] Improve docs for ObjectSpace.memsize_of_all 2026-01-17 09:40:03 -05:00
Peter Zhu
61c372a1b7 [DOC] Improve docs for ObjectSpace.count_symbols 2026-01-11 10:46:56 -05:00
Peter Zhu
1267a3ab56 [DOC] Improve docs for ObjectSpace.count_imemo_objects 2026-01-11 10:46:56 -05:00
Peter Zhu
cf5c5abe1e [DOC] Improve docs for ObjectSpace.count_tdata_objects 2026-01-11 10:46:56 -05:00
Peter Zhu
e8c61f5139 Remove ObjectSpace.count_nodes
ObjectSpace.count_nodes has been a no-op and returning an empty hash since
Ruby 2.5 because parser nodes are not GC managed.
2026-01-09 18:05:43 -05:00
Jean Boussier
7ee127d2d1 Get rid of imemo_ast
It has been marked as obsolete for a while and I see no reason
to keep it.
2025-07-29 13:05:12 +02:00
Peter Zhu
f186f2cb70 Remove unused imemo_parser_strterm 2025-07-24 09:49:13 -04:00
Stan Lo
78820e86c7 Update doc for ObjectSpace.memsize_of 2025-07-23 15:49:04 -04:00
Jean Boussier
fb68721f63 Rename imemo_class_fields -> imemo_fields 2025-06-17 15:28:05 +02:00
Jean Boussier
3abdd4241f Turn rb_classext_t.fields into a T_IMEMO/class_fields
This behave almost exactly as a T_OBJECT, the layout is entirely
compatible.

This aims to solve two problems.

First, it solves the problem of namspaced classes having
a single `shape_id`. Now each namespaced classext
has an object that can hold the namespace specific
shape.

Second, it open the door to later make class instance variable
writes atomics, hence be able to read class variables
without locking the VM.
In the future, in multi-ractor mode, we can do the write
on a copy of the `fields_obj` and then atomically swap it.

Considerations:

  - Right now the `RClass` shape_id is always synchronized,
    but with namespace we should likely mark classes that have
    multiple namespace with a specific shape flag.
2025-06-12 07:58:16 +02:00
Satoshi Tagomori
382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Peter Zhu
a58675386c Prefix asan_poison_object with rb 2024-12-19 09:14:34 -05:00
Peter Zhu
51bd816517 [Feature #20470] Split GC into gc_impl.c
This commit splits gc.c into two files:

- gc.c now only contains code not specific to Ruby GC. This includes
  code to mark objects (which the GC implementation may choose not to
  use) and wrappers for internal APIs that the implementation may need
  to use (e.g. locking the VM).

- gc_impl.c now contains the implementation of Ruby's GC. This includes
  marking, sweeping, compaction, and statistics. Most importantly,
  gc_impl.c only uses public APIs in Ruby and a limited set of functions
  exposed in gc.c. This allows us to build gc_impl.c independently of
  Ruby and plug Ruby's GC into itself.
2024-07-03 09:03:40 -04:00
Lazarus Lazaridis
61ea202f8b
[DOC] Fix invalid documentation for reachable_objects_from (#10172)
Previous documentation is stating the opposite (that the method won't
work for CRuby).
2024-03-05 01:35:51 +09:00
Peter Zhu
386a006630 Use rb_hash_foreach in objspace.c
Using RHASH_TBL_RAW is a private API, so we should use rb_hash_foreach
rather than RHASH_TBL_RAW with st_foreach.
2024-02-23 10:24:21 -05:00
yui-knk
c3ab946e86 ObjectSpace.count_nodes doesn't count nodes
Node has not been managed by GC from Ruby 2.5.
Therefore these codes are not needed. If ObjectSpace depends on Node,
it needs to update the file when node type is updated. Delete node
related codes to avoid such update.
2023-11-21 14:39:06 +09:00
Nobuyoshi Nakada
a5cc6341c0
Remove NODE_VALUES
This node type was added for the multi-value experiment back in 2004.
The feature itself was removed after a few years, but this is its
remnant.
2023-10-06 03:39:58 +09:00
Nobuyoshi Nakada
70e1635950 Move internal NODE_DEF_TEMP to parse.y 2023-10-05 14:23:42 +09:00
yui-knk
68ae87546e Merge NODE_DEF_TEMP and NODE_DEF_TEMP2 2023-09-29 19:36:34 +09:00
yui-knk
74c6781153 Change RNode structure from union to struct
All kind of AST nodes use same struct RNode, which has u1, u2, u3 union members
for holding different kind of data.
This has two problems.

1. Low flexibility of data structure

Some nodes, for example NODE_TRUE, don’t use u1, u2, u3. On the other hand,
NODE_OP_ASGN2 needs more than three union members. However they use same
structure definition, need to allocate three union members for NODE_TRUE and
need to separate NODE_OP_ASGN2 into another node.
This change removes the restriction so make it possible to
change data structure by each node type.

2. No compile time check for union member access

It’s developer’s responsibility for using correct member for each node type when it’s union.
This change clarifies which node has which type of fields and enables compile time check.

This commit also changes node_buffer_elem_struct buf management to handle
different size data with alignment.
2023-09-28 11:58:10 +09:00
Matt Valentine-House
72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00
Nobuyoshi Nakada
f527a0911d
[DOC] [Bug #19290] fix formatting 2023-01-01 14:50:39 +09:00
yui-knk
4bfdf6d06d Move error from top_stmts and top_stmt to stmt
By this change, syntax error is recovered smaller units.
In the case below, "DEFN :bar" is same level with "CLASS :Foo"
now.

```
module Z
  class Foo
    foo.
  end

  def bar
  end
end
```

[Feature #19013]
2022-10-08 17:59:11 +09:00
Aaron Patterson
06abfa5be6
Revert this until we can figure out WB issues or remove shapes from GC
Revert "* expand tabs. [ci skip]"

This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275.

Revert "This commit implements the Object Shapes technique in CRuby."

This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
2022-09-26 16:10:11 -07:00
Jemma Issroff
9ddfd2ca00 This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26 09:21:30 -07:00
Nobuyoshi Nakada
92c7417d73
Adjust indents [ci skip] 2022-07-22 21:59:27 +09:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Nobuyoshi Nakada
be52c72889
Get rid of doubly caching 2022-04-17 18:57:26 +09:00
Nobuyoshi Nakada
2c6876f811
Get rid of magic numbers 2022-04-17 18:53:29 +09:00
John Hawthorn
764e4fa850 Never call kind_of with klass=0 2022-02-23 19:57:42 -08:00
John Hawthorn
05b1944c53 objspace: Hide identhash containing internal objs
Inside ObjectSpace.reachable_objects_from we keep an internal identhash
in order to de-duplicate reachable objects when wrapping them as
InternalObject. Previously this hash was not hidden, making it possible
to leak references to those internal objects to Ruby if using
ObjectSpace.each_object.

This commit solves this by hiding the hash. To simplify collection of
values, we instead now just use the hash as a set of visited objects,
and collect an Array (not hidden) of values to be returned.
2022-02-09 17:32:43 -08:00
Nobuyoshi Nakada
54f0e63a8c Remove NODE_DASGN_CURR [Feature #18406]
This `NODE` type was used in pre-YARV implementation, to improve
the performance of assignment to dynamic local variable defined at
the innermost scope.  It has no longer any actual difference with
`NODE_DASGN`, except for the node dump.
2021-12-13 12:53:03 +09: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
eddd369e73 Revert "[Feature #18045] Implement size classes for GC"
This reverts commits 48ff7a9f3e47bffb3e4d067a12ba9b936261caa0
and b2e2cf2dedd104acad8610721db5e4d341f135ef because it is causing
crashes in SPARC solaris and i386 debian.
2021-08-23 10:54:53 -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