aboutsummaryrefslogtreecommitdiffstats
path: root/ext/objspace
Commit message (Collapse)AuthorAgeFilesLines
* objspace_dump.c: dump call cache ids with dump_append_idJean Boussier2023-11-221-4/+5
| | | | | | Not all `ID` have an associated string. Fixes a SEGFAULT in ObjectSpace.dump_all spec.
* `ObjectSpace.count_nodes` doesn't count nodesyui-knk2023-11-211-142/+1
| | | | | | | 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.
* Don't try compacting ivars on Classes that are "too complex"Aaron Patterson2023-11-201-0/+5
| | | | | Too complex classes use a hash table to store ivs, and should always pin their IVs. We shouldn't touch those classes in compaction.
* Revert "Revert "Remove SHAPE_CAPACITY_CHANGE shapes""Peter Zhu2023-11-131-5/+0
| | | | This reverts commit 5f3fb4f4e397735783743fe52a7899b614bece20.
* Record more info from CALLCACHE in heap dumpsJohn Hawthorn2023-11-131-3/+23
| | | | | This records the called_id and klass from imemo_callcache objects in heap dumps.
* Revert "Remove SHAPE_CAPACITY_CHANGE shapes"Peter Zhu2023-11-101-0/+5
| | | | | | | This reverts commit f6910a61122931e4193bcc0fad18d839c319b720. We're seeing crashes in the test suite of Shopify's core monolith after this change.
* Remove SHAPE_CAPACITY_CHANGE shapesPeter Zhu2023-11-091-5/+0
| | | | | We don't need to create a shape to transition capacity as we can transition the capacity when the capacity of the SHAPE_IVAR changes.
* Make every initial size pool shape a root shapePeter Zhu2023-11-021-5/+0
| | | | | This commit makes every initial size pool shape a root shape and assigns it a capacity of 0.
* Switch mid dump to dump_append_string_valueJohn Hawthorn2023-10-121-3/+2
| | | | | | I don't think it's possible to create a CI with a mid which would need escaping to be in a JSON string, but I think we might as well not rely on that assumption.
* Fix ObjectSpace.dump with super() callinfoJohn Hawthorn2023-10-121-3/+7
| | | | | super() uses 0 as mid for its callinfo, so we need to check for that to avoid a segfault when using dump_all.
* Remove `NODE_VALUES`Nobuyoshi Nakada2023-10-061-1/+0
| | | | | | 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.
* Move internal NODE_DEF_TEMP to parse.yNobuyoshi Nakada2023-10-051-1/+0
|
* Dump name of method for imemo callinfoPeter Zhu2023-10-022-0/+14
| | | | | This commit dumps the `mid` of the imemo callinfo when calling `ObjectSpace.dump_all`.
* Merge NODE_DEF_TEMP and NODE_DEF_TEMP2yui-knk2023-09-291-1/+0
|
* Change RNode structure from union to structyui-knk2023-09-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | 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.
* [Feature #19719] Universal Parseryui-knk2023-06-121-5/+15
| | | | | | | | | Introduce Universal Parser mode for the parser. This commit includes these changes: * Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions are passed via `struct rb_parser_config_struct` when this macro is enabled. * Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu.
* Add deprecations for public `struct rb_io` members. (#7916)Samuel Williams2023-06-082-0/+2
| | | * Add deprecations for public struct rb_io members.
* Revert "Revert "Fix cvar caching when class is cloned""eileencodes2023-06-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 10621f7cb9a0c70e568f89cce47a02e878af6778. This was reverted because the gc integrity build started failing. We have figured out a fix so I'm reopening the PR. Original commit message: Fix cvar caching when class is cloned The class variable cache that was added in ruby#4544 changed the behavior of class variables on cloned classes. As reported when a class is cloned AND a class variable was set, and the class variable was read from the original class, reading a class variable from the cloned class would return the value from the original class. This was happening because the IC (inline cache) is stored on the ISEQ which is shared between the original and cloned class, therefore they share the cache too. To fix this we are now storing the `cref` in the cache so that we can check if it's equal to the current `cref`. If it's different we don't want to read from the cache. If it's the same we do. Cloned classes don't share the same cref with their original class. This will need to be backported to 3.1 in addition to 3.2 since the bug exists in both versions. We also added a marking function which was missing. Fixes [Bug #19379] Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Revert "Fix cvar caching when class is cloned"Aaron Patterson2023-06-011-5/+0
| | | | This reverts commit 77d1b082470790c17c24a2f406b4fec5d522636b.
* Fix cvar caching when class is clonedeileencodes2023-06-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | The class variable cache that was added in https://github.com/ruby/ruby/pull/4544 changed the behavior of class variables on cloned classes. As reported when a class is cloned AND a class variable was set, and the class variable was read from the original class, reading a class variable from the cloned class would return the value from the original class. This was happening because the IC (inline cache) is stored on the ISEQ which is shared between the original and cloned class, therefore they share the cache too. To fix this we are now storing the `cref` in the cache so that we can check if it's equal to the current `cref`. If it's different we don't want to read from the cache. If it's the same we do. Cloned classes don't share the same cref with their original class. This will need to be backported to 3.1 in addition to 3.2 since the bug exists in both versions. We also added a marking function which was missing. Fixes [Bug #19379] Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
* Revert "Hide most of the implementation of `struct rb_io`. (#6511)"NARUSE, Yui2023-06-012-2/+0
| | | | | | | | | This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2. fix [Bug #19704] https://bugs.ruby-lang.org/issues/19704 This breaks compatibility for extension libraries. Such changes need a discussion.
* Hide most of the implementation of `struct rb_io`. (#6511)Samuel Williams2023-05-302-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Add rb_io_path and rb_io_open_descriptor. * Use rb_io_open_descriptor to create PTY objects * Rename FMODE_PREP -> FMODE_EXTERNAL and expose it FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but FMODE_EXTERNAL is clearer about what the file descriptor represents and aligns with language in the IO::Buffer module. * Ensure that rb_io_open_descriptor closes the FD if it fails If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be responsible for closing your file, eventually, if you pass it to rb_io_open_descriptor, even if it raises an exception. * Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P * Expose `rb_io_closed_p`. * Add `rb_io_mode` to get IO mode. --------- Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
* Update VPATH for socket, & dependenciesMatt Valentine-House2023-04-061-0/+34
| | | | | | | | | | | | | | | | | | The socket extensions rubysocket.h pulls in the "private" include/gc.h, which now depends on vm_core.h. vm_core.h pulls in id.h when tool/update-deps generates the dependencies for the makefiles, it generates the line for id.h to be based on VPATH, which is configured in the extconf.rb for each of the extensions. By default VPATH does not include the actual source directory of the current Ruby so the dependency fails to resolve and linking fails. We need to append the topdir and top_srcdir to VPATH to have the dependancy picked up correctly (and I believe we need both of these to cope with in-tree and out-of-tree builds). I copied this from the approach taken in https://github.com/ruby/ruby/blob/master/ext/objspace/extconf.rb#L3
* Update the depend filesMatt Valentine-House2023-02-281-3/+0
|
* Remove intern/gc.h from Make depsMatt Valentine-House2023-02-271-3/+0
|
* [DOC] Improve ObjectSpace#dump_XXX method docszverok2023-02-191-21/+14
| | | | | | * remove false call-seq (output from Ruby parsing is cleaner) * explain output: argument in plain words * change parameter name in docs of #dump_shapes (typo)
* Encapsulate RCLASS_ATTACHED_OBJECTJean Boussier2023-02-151-0/+2
| | | | | | | | | Right now the attached object is stored as an instance variable and all the call sites that either get or set it have to know how it's stored. It's preferable to hide this implementation detail behind accessors so that it is easier to change how it's stored.
* Merge gc.h and internal/gc.hMatt Valentine-House2023-02-094-6/+7
| | | | [Feature #19425]
* Extract include/ruby/internal/attr/packed_struct.hNobuyoshi Nakada2023-02-081-0/+3
| | | | | | | | | Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the macros bellow: * `RBIMPL_ATTR_PACKED_STRUCT_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_END` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN` * `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END`
* Add embedded status to dumps of T_OBJECTPeter Zhu2023-01-051-0/+4
| | | | | This commit adds `"embedded":true` in ObjectSpace.dump for T_OBJECTs that are embedded.
* Fix crash in tracing object allocationsPeter Zhu2023-01-042-0/+8
| | | | | | | | | | ObjectSpace.trace_object_allocations_start could crash since it adds a TracePoint for when objects are freed. However, TracePoint could crash since it modifies st tables while inside the GC that is trying to free the object. This could cause a memory allocation to happen which would crash if it triggers another GC. See a crash log: http://ci.rvm.jp/results/trunk@ruby-sp1/4373707
* [DOC] [Bug #19290] fix formattingNobuyoshi Nakada2023-01-011-1/+1
|
* Indicate if a shape is too_complex in ObjectSpace#dumpJemma Issroff2022-12-151-4/+5
|
* Transition complex objects to "too complex" shapeJemma Issroff2022-12-152-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an object becomes "too complex" (in other words it has too many variations in the shape tree), we transition it to use a "too complex" shape and use a hash for storing instance variables. Without this patch, there were rare cases where shape tree growth could "explode" and cause performance degradation on what would otherwise have been cached fast paths. This patch puts a limit on shape tree growth, and gracefully degrades in the rare case where there could be a factorial growth in the shape tree. For example: ```ruby class NG; end HUGE_NUMBER.times do NG.new.instance_variable_set(:"@unique_ivar_#{_1}", 1) end ``` We consider objects to be "too complex" when the object's class has more than SHAPE_MAX_VARIATIONS (currently 8) leaf nodes in the shape tree and the object introduces a new variation (a new leaf node) associated with that class. For example, new variations on instances of the following class would be considered "too complex" because those instances create more than 8 leaves in the shape tree: ```ruby class Foo; end 9.times { Foo.new.instance_variable_set(":@uniq_#{_1}", 1) } ``` However, the following class is *not* too complex because it only has one leaf in the shape tree: ```ruby class Foo def initialize @a = @b = @c = @d = @e = @f = @g = @h = @i = nil end end 9.times { Foo.new } `` This case is rare, so we don't expect this change to impact performance of most applications, but it needs to be handled. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* Add variation_count on classesJemma Issroff2022-12-151-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Count how many "variations" each class creates. A "variation" is a a unique ordering of instance variables on a particular class. This can also be thought of as a branch in the shape tree. For example, the following Foo class will have 2 variations: ```ruby class Foo ; end Foo.new.instance_variable_set(:@a, 1) # case 1: creates one variation Foo.new.instance_variable_set(:@b, 1) # case 2: creates another variation foo = Foo.new foo.instance_variable_set(:@a, 1) # does not create a new variation foo.instance_variable_set(:@b, 1) # does not create a new variation (a continuation of the variation in case 1) ``` We will use this number to limit the amount of shapes that a class can create and fallback to using a hash iv lookup. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
* objspace_dump.c: don't dump class of T_IMEMOJean Boussier2022-12-141-1/+5
| | | | They don't actually have a class.
* [DOC] Fix format in ObjectSpace.dump_allPeter Zhu2022-12-121-1/+1
|
* [DOC] Fix format for ObjectSpace.dump_shapesPeter Zhu2022-12-121-1/+1
|
* [DOC] Fix call-seq for ObjectSpace methodsPeter Zhu2022-12-121-17/+13
|
* [DOC] Fix typo in docs for ObjectSpace.dump_allPeter Zhu2022-12-121-1/+1
|
* [DOC] Fix indentation for ObjectSpace.dump_allPeter Zhu2022-12-121-32/+32
|
* [DOC] Don't document private methods in objspacePeter Zhu2022-12-121-0/+3
|
* objspace_dump.c: dump the capacity field for INITIAL_CAPACITY shapesJean Boussier2022-12-091-0/+2
| | | | | We forgot about that one, it's quite useful to see which capacity we started from.
* ObjectSpace.dump_all: dump shapes as wellJean Boussier2022-12-083-13/+171
| | | | | | | | | | | | | | | | | | | | | | | | | I see several arguments in doing so. First they use a non trivial amount of memory, so for various memory profiling/mapping tools it is relevant to have visibility of the space occupied by shapes. Then, some pathological code can create a tons of shape, so it is valuable to have a way to have a way to observe shapes without having to compile Ruby with `SHAPE_DEBUG=1`. And additionally it's likely much faster to dump then this way than to use `RubyVM::Shape`. There are however a few open questions: - Shapes can't respect the `since:` argument. Not sure what to do when it is provided. Would probably make sense to not dump them. - Maybe it would make more sense to have a separate `ObjectSpace.dump_shapes`? - Maybe instead `dump_all` should take a `shapes: false` argument? Additionally, `ObjectSpace.dump_shapes` is added for the use case of debugging the evolution of the shape tree.
* Update dependenciesDaniel Colson2022-12-061-0/+1
|
* Add shape_id to heap dumpJemma Issroff2022-12-051-0/+3
|
* Remove numiv from RObjectJemma Issroff2022-11-101-1/+1
| | | | | | | Since object shapes store the capacity of an object, we no longer need the numiv field on RObjects. This gives us one extra slot which we can use to give embedded objects one more instance variable (for a total of 3 ivs). This commit removes the concept of numiv from RObject.
* Use shared flags of the typePeter Zhu2022-11-021-1/+2
| | | | | | The ELTS_SHARED flag is generic, so we should prefer to use the flags specific of the type (STR_SHARED for strings and RARRAY_SHARED_FLAG for arrays).
* Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff2022-10-111-0/+5
| | | | This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
* Move `error` from top_stmts and top_stmt to stmtyui-knk2022-10-081-0/+1
| | | | | | | | | | | | | | | | | | | 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]