summaryrefslogtreecommitdiff
path: root/shape.c
AgeCommit message (Collapse)Author
2025-05-09Stop exposing rb_shape_frozen_shape_pJean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Get rid of `rb_shape_get_parent`.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_get_shape_id` -> `RB_OBJ_SHAPE_ID`Jean Boussier
And `rb_shape_get_shape` -> `RB_OBJ_SHAPE`. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Remove unused `rb_shape_object_id_index`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_get_next` to return an IDJean Boussier
Also rename it, and change parameters to be consistent with other transition functions. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_transition_shape_remove_ivar` to not take a shape pointerJean Boussier
It's more consistent with other transition functions. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_obj_too_complex` -> `rb_shape_obj_too_complex_p`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_transition_too_complex` to return an ID.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_transition_frozen` to return a `shape_id`.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Rename `rb_shape_get_shape_by_id` -> `RSHAPE`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_get_next_iv_shape` to take and return ids.Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_depth` to take an ID rather than a pointer.Jean Boussier
As well as `rb_shape_edges_count` and `rb_shape_memsize`. Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Refactor `rb_shape_traverse_from_new_root` to not expose `rb_shape_t`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-09Extract `rb_shape_free_all`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13283
2025-05-08Fix `remove_instance_variable` on complex objectsJean Boussier
Introduced in: https://github.com/ruby/ruby/pull/13159 Now that there is no longer a unique TOO_COMPLEX shape with no children, checking `shape->type == TOO_COMPLEX` is incorrect. Notes: Merged: https://github.com/ruby/ruby/pull/13280
2025-05-08Move `object_id` in object fields.Jean Boussier
And get rid of the `obj_to_id_tbl` It's no longer needed, the `object_id` is now stored inline in the object alongside instance variables. We still need the inverse table in case `_id2ref` is invoked, but we lazily build it by walking the heap if that happens. The `object_id` concern is also no longer a GC implementation concern, but a generic implementation. Co-Authored-By: Matt Valentine-House <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08shape.c: refactor frozen shape to no longer be finalJean Boussier
This opens the door to store more informations in shapes, such as the `object_id` or object address in case it has been observed and the object has to be moved. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08Refactor OBJ_TOO_COMPLEX_SHAPE_ID to not be referenced outside shape.hJean Boussier
Also refactor checks for `->type == SHAPE_OBJ_TOO_COMPLEX`. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08Rename `ivptr` -> `fields`, `next_iv_index` -> `next_field_index`Jean Boussier
Ivars will longer be the only thing stored inline via shapes, so keeping the `iv_index` and `ivptr` names would be confusing. Instance variables won't be the only thing stored inline via shapes, so keeping the `ivptr` name would be confusing. `field` encompass anything that can be stored in a VALUE array. Similarly, `gen_ivtbl` becomes `gen_fields_tbl`. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-05Improve style consistency of `rb_shape_t *`Jean Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/13257
2025-04-30get_next_shape_internal: Skip VM lock for single child caseJean Boussier
If the shape has only one child, we check it lock-free without compromising thread safety. I haven't computed hard data as to how often that it the case, but we can assume that it's not too rare for shapes to have a single child that is often requested, typically when freezing and object. Notes: Merged: https://github.com/ruby/ruby/pull/13191
2025-04-30Improve syntax style consistency in shape.c and shape.hJean Boussier
Most of this code use the `type * name` style, while the overwhemling majority of the rest of ruby use the `type *name` style. This is a cosmetic change, but helps with readability.
2024-12-24[DOC] Hide `RubyVM::Shape` that is for debug from RDoc totallyNobuyoshi Nakada
2024-11-21Annotate anonymous mmapKunshan Wang
Use PR_SET_VMA_ANON_NAME to set human-readable names for anonymous virtual memory areas mapped by `mmap()` when compiled and run on Linux 5.17 or higher. This makes it convenient for developers to debug mmap. Notes: Merged: https://github.com/ruby/ruby/pull/12119
2024-10-03Rename size_pool -> heapMatt Valentine-House
Now that we've inlined the eden_heap into the size_pool, we should rename the size_pool to heap. So that Ruby contains multiple heaps, with different sized objects. The term heap as a collection of memory pages is more in memory management nomenclature, whereas size_pool was a name chosen out of necessity during the development of the Variable Width Allocation features of Ruby. The concept of size pools was introduced in order to facilitate different sized objects (other than the default 40 bytes). They wrapped the eden heap and the tomb heap, and some related state, and provided a reasonably simple way of duplicating all related concerns, to provide multiple pools that all shared the same structure but held different objects. Since then various changes have happend in Ruby's memory layout: * The concept of tomb heaps has been replaced by a global free pages list, with each page having it's slot size reconfigured at the point when it is resurrected * the eden heap has been inlined into the size pool itself, so that now the size pool directly controls the free_pages list, the sweeping page, the compaction cursor and the other state that was previously being managed by the eden heap. Now that there is no need for a heap wrapper, we should refer to the collection of pages containing Ruby objects as a heap again rather than a size pool Notes: Merged: https://github.com/ruby/ruby/pull/11771
2024-08-16Parenthesize macro argumentsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11389
2024-08-16Simplify and clarify bitmask calculationNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11389
2024-08-16Fix some warningsRaed Rizqie
* Fix unused functions when no `mmap`. ``` shape.c:285:1: warning: unused function 'redblack_insert' [-Wunused-function] 285 | redblack_insert(redblack_node_t * tree, ID key, rb_shape_t * value) | ^~~~~~~~~~~~~~~ ``` * Fix unknown warning group '-Wmaybe-uninitialized' with clang. ``` thread_win32.c:596:1: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option] 596 | COMPILER_WARNING_IGNORED(-Wmaybe-uninitialized) | ^ ``` Co-authored-by: Nobuyoshi Nakada <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/11376 Merged-By: nobu <[email protected]>
2024-06-04Do not emit shape transition warnings when YJIT is compilingJean Boussier
[Bug #20522] If `Warning.warn` is redefined in Ruby, emitting a warning would invoke Ruby code, which can't safely be done when YJIT is compiling.
2024-05-09`redblack_cache_ancestors` is enabled only when `mmap` is availableNobuyoshi Nakada
2024-04-25Use xcalloc for allocating shape treePeter Zhu
The GC is initialized by this point, so we can use xcalloc instead of ruby_mimcalloc.
2024-04-24Add ruby_mimcallocPeter Zhu
Many places call ruby_mimmalloc then MEMZERO. This can be reduced by using ruby_mimcalloc instead.
2024-03-30If we have a shape cache we should use itAaron Patterson
If there is a shape cache, then we should believe the results instead of doing a linear search for non-existent items This fixes a case where checking the index of an undefined ivar would result in an O(n) search. Now we get O(log n). Benchmark is as follows: ```ruby N = ARGV[0].to_i class ManyIVs class_eval "def initialize;" + N.times.map { "@a#{_1} = #{_1}" }.join("\n") + "end" def check defined?(@not) end end class Subclass < ManyIVs def initialize super @foo = 123 end end def t s = Process.clock_gettime Process::CLOCK_MONOTONIC yield Process.clock_gettime(Process::CLOCK_MONOTONIC) - s end def test a = ManyIVs.new b = Subclass.new t { 200000.times { a.check; b.check } } end puts "#{N},#{test}" ``` On the master branch: ``` $ for i in (seq 1 3 32); ./miniruby test.rb $i; end 1,0.015619999991031364 4,0.013061000005109236 7,0.013365999999223277 10,0.015474999992875382 13,0.017674999980954453 16,0.020055999979376793 19,0.02260500000556931 22,0.0254080000158865 25,0.02806599999894388 28,0.031244999991031364 31,0.034568000002764165 ``` On this branch: ``` $ for i in (seq 1 3 32); ./miniruby test.rb $i; end 1,0.015848999988520518 4,0.013225000002421439 7,0.013049000001046807 10,0.010697999998228624 13,0.010902000009082258 16,0.011448000004747882 19,0.01151199999731034 22,0.011539999977685511 25,0.01173300002119504 28,0.011900000012246892 31,0.012278999987756833 ```
2024-03-13Remove unused size_pool_edge_namesPeter Zhu
2024-03-13Don't allow SHAPE_T_OBJECT in rb_shape_alloc_new_childPeter Zhu
2024-03-13Make special const and too complex shapes before T_OBJECT shapesPeter Zhu
2024-03-13Don't create per size pool shapes for non-T_OBJECTPeter Zhu
2024-03-13Don't directly read the SIZE_POOL_COUNT in shapesPeter Zhu
This removes the assumption about SIZE_POOL_COUNT for shapes.
2024-02-23Remove unneeded RUBY_FUNC_EXPORTEDPeter Zhu
2024-01-12Handle mmap failures for redblack tree cacheAaron Patterson
The redblack tree cache is totally optional, so if we can't allocate room for the cache, then just pretend as if the cache is full if mmap fails
2023-12-20Fix a grammar issue in the shape performance warning messageJean Boussier
2023-12-18Use #initialize instead of `initialize` in shape perf warningJean Boussier
This is more consistent with other messages.
2023-12-18[DOC] No document for internal or debug methodsNobuyoshi Nakada
2023-12-18Make the SHAPE_TOO_COMPLEX performance warning more actionableJean Boussier
As suggested by Mame, we should try to help users fix the issues without having to lookup the meaning of the warning.
2023-12-06Re-embed when removing Object instance variablesPeter Zhu
Objects with the same shape must always have the same "embeddedness" (either embedded or heap allocated) because YJIT assumes so. However, using remove_instance_variable, it's possible that some objects are embedded and some are heap allocated because it does not re-embed heap allocated objects. This commit changes remove_instance_variable to re-embed Object instance variables when it becomes small enough.
2023-12-06Deduplicate assertions in redblack_balancePeter Zhu
The bug in i686 was fixed in commit 71babe5536bdb2238509752d8706194ee57ff485.
2023-12-05Fix alphabetical order of include in shape.cPeter Zhu
2023-12-01Add assertions for shape cache grandchild nodesPeter Zhu
2023-11-30Add assertions in redblack_balancePeter Zhu
These assertions check that binary search tree invariants are held for the new tree.
2023-11-30Rename variables redblack_balancePeter Zhu
It's too difficult for me to keep track that y is the new node, x is the new left node, z is the new right node, a is the new left left node, b is the new left right node, c is the new right left node, and d is the new right right node. This commit refactors the variable names to be more descriptive.