summaryrefslogtreecommitdiff
path: root/object.c
AgeCommit message (Collapse)Author
2024-09-07Preserve encoding in exception message of `Float`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11564
2024-09-07[Bug #20719] `Float` argument must be ASCII compatibleNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11564
2024-07-23[DOC] Doc for BasicObject (#11139)Burdette Lamar
Notes: Merged-By: peterzhu2118 <[email protected]>
2024-04-22YJIT: Fix String#setbyte crashing for converted argumentsAlan Wu
Previously, passing objects that respond to #to_int to `String#setbyte` resulted in a crash when compiled by YJIT. This was due to the lazily pushed frame from rb_yjit_lazy_push_frame() lingering and not being popped by an exception as expected. The fix is to ensure that `ec->cfp` is restored to before the lazy frame push in case the method call for conversion succeeds. Right now, this is only for conversion to integers. Found running `ruby/spec`. * clarify comment We just need to make sure `ec->cfp` is always preserved and this can convert without rising when `raise` is true.
2024-04-12[DOC] Fix the wrong commentSatoshi Tagomori
This function checks the CL's superclasses containing the class C at the end of it. That means C is a superclass of CL, not a subclass.
2024-03-26Refactor init_copy gc attributeseileencodes
This PR moves `rb_copy_wb_protected_attribute` and `rb_gc_copy_finalizer` into a single function called `rb_gc_copy_attributes` to be called by `init_copy`. This reduces the surface area of the GC API. Co-authored-by: Peter Zhu <[email protected]>
2024-03-19[DOC] Unify Doxygen formats (#10285)Takashi Kokubun
2024-03-19[Bug #20279] [DOC] Update for `BasicObject`Earlopain
The current implementation raises on the call to super
2024-03-19Implement chilled stringsÉtienne Barrié
[Feature #20205] As a path toward enabling frozen string literals by default in the future, this commit introduce "chilled strings". From a user perspective chilled strings pretend to be frozen, but on the first attempt to mutate them, they lose their frozen status and emit a warning rather than to raise a `FrozenError`. Implementation wise, `rb_compile_option_struct.frozen_string_literal` is no longer a boolean but a tri-state of `enabled/disabled/unset`. When code is compiled with frozen string literals neither explictly enabled or disabled, string literals are compiled with a new `putchilledstring` instruction. This instruction is identical to `putstring` except it marks the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags. Chilled strings have the `FL_FREEZE` flag as to minimize the need to check for chilled strings across the codebase, and to improve compatibility with C extensions. Notes: - `String#freeze`: clears the chilled flag. - `String#-@`: acts as if the string was mutable. - `String#+@`: acts as if the string was mutable. - `String#clone`: copies the chilled flag. Co-authored-by: Jean Boussier <[email protected]>
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-03-06Refactor VM root modulesJean Boussier
This `st_table` is used to both mark and pin classes defined from the C API. But `vm->mark_object_ary` already does both much more efficiently. Currently a Ruby process starts with 252 rooted classes, which uses `7224B` in an `st_table` or `2016B` in an `RArray`. So a baseline of 5kB saved, but since `mark_object_ary` is preallocated with `1024` slots but only use `405` of them, it's a net `7kB` save. `vm->mark_object_ary` is also being refactored. Prior to this changes, `mark_object_ary` was a regular `RArray`, but since this allows for references to be moved, it was marked a second time from `rb_vm_mark()` to pin these objects. This has the detrimental effect of marking these references on every minors even though it's a mostly append only list. But using a custom TypedData we can save from having to mark all the references on minor GC runs. Addtionally, immediate values are now ignored and not appended to `vm->mark_object_ary` as it's just wasted space.
2024-03-06Move FL_SINGLETON to FL_USER1Jean Boussier
This frees FL_USER0 on both T_MODULE and T_CLASS. Note: prior to this, FL_SINGLETON was never set on T_MODULE, so checking for `FL_SINGLETON` without first checking that `FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-02-23YJIT: Lazily push a frame for specialized C funcs (#10080)Takashi Kokubun
* YJIT: Lazily push a frame for specialized C funcs Co-authored-by: Maxime Chevalier-Boisvert <[email protected]> * Fix a comment on pc_to_cfunc * Rename rb_yjit_check_pc to rb_yjit_lazy_push_frame * Rename it to jit_prepare_lazy_frame_call * Fix a typo * Optimize String#getbyte as well * Optimize String#byteslice as well --------- Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
2024-02-17Use `defined?(yield)` and `SIZED_ENUMERATOR`Nobuyoshi Nakada
Prefer built-in features over method calls that may be overridden.
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-14Move rb_class_allocate_instance from gc.c to object.cPeter Zhu
2024-02-12proc.c: get rid of `CLONESETUP`Jean Boussier
[Bug #20253] All the way down to Ruby 1.9, `Proc`, `Method`, `UnboundMethod` and `Binding` always had their own specific clone and dup routine. This caused various discrepancies with how other objects behave on `dup` and `clone. [Bug #20250], [Bug #20253]. This commit get rid of `CLONESETUP` and use the the same codepath as all other types, so ensure consistency. NB: It's still not accepting the `freeze` keyword argument on `clone`. Co-Authored-By: Étienne Barrié <[email protected]>
2024-02-09rb_obj_setup: do not copy RUBY_FL_SEEN_OBJ_IDJean Boussier
[Bug #20250] We're seting up a new instance, so it never had an associated object_id.
2024-01-10Fix memory leak when duplicating too complex objectPeter Zhu
[Bug #20162] Creating a ST table then calling st_replace leaks memory because the st_replace overwrites the ST table without freeing any of the existing memory. This commit changes it to use st_copy instead. For example: RubyVM::Shape.exhaust_shapes o = Object.new o.instance_variable_set(:@a, 0) 10.times do 100_000.times { o.dup } puts `ps -o rss= -p #{$$}` end Before: 23264 33600 42672 52160 61600 71728 81056 90528 100560 109840 After: 14752 14816 15584 15584 15664 15664 15664 15664 15664 15664
2023-12-25Move internal ST functions to internal/st.hPeter Zhu
st_replace and st_init_existing_table_with_size are functions used internally in Ruby and should not be publicly visible.
2023-12-24Don't copy RUBY_FL_PROMOTED flag in rb_obj_setupPeter Zhu
RUBY_FL_PROMOTED is used by the garbage collector to track when an object becomes promoted to the old generation. rb_obj_setup must not copy that flag over because then it may become out-of-sync with the age of the object. This fixes a bug in Method#clone where the cloned Method object may get RUBY_FL_PROMOTED incorrectly set.
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-05Fix parameter types for rb_ivar_foreach() callbacksAlan Wu
For this public API, the callback is declared to take `(ID, VALUE, st_data_t)`, but it so happens that using `(st_data_t, st_data_t, st_data_t)` also type checks, because the underlying type is identical. Use it as declared and get rid of some casts.
2023-11-17Refactor rb_obj_evacuate_ivs_to_hash_tableJean Boussier
That function is a bit too low level to called from multiple places. It's always used in tandem with `rb_shape_set_too_complex` and both have to know how the object is laid out to update the `iv_ptr`. So instead we can provide two higher level function: - `rb_obj_copy_ivs_to_hash_table` to prepare a `st_table` from an arbitrary oject. - `rb_obj_convert_to_too_complex` to assign the new `st_table` to the old object, and safely free the old `iv_ptr`. Unfortunately both can't be combined into one, because `rb_obj_copy_ivar` need `rb_obj_copy_ivs_to_hash_table` to copy from one object to another.
2023-11-16rb_evict_ivars_to_hash: get rid of the sahpe paramaterJean Boussier
It's only used to allocate the table with the right size, but in some case we were passing `rb_shape_get_shape_by_id(SHAPE_OBJ_TOO_COMPLEX)` which `next_iv_index` is a bit undefined. So overall we're better to just allocate a table the size of the existing object, it should be close enough in the vast majority of cases, and that's already a de-optimizaton path anyway.
2023-10-31Handle running out of shapes in `Object#dup`Jean Boussier
There is a handful of call sites where we may transition to OBJ_TOO_COMPLEX_SHAPE if we just ran out of shapes, but that weren't handling it properly.
2023-10-24`get_next_shape_internal` should always return a shapeAaron Patterson
If it runs out of shapes, or new variations aren't allowed, it will return "too complex"
2023-10-24geniv objects can become too complexAaron Patterson
2023-08-31[Bug #19349] Respect `#to_int` of `base` argumentNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7144
2023-08-15[DOC] Improve doc guide compliance (#8221)Burdette Lamar
2023-08-08[Bug #19833] Fix index underflow at superclasses of `BasicObject`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8185
2023-06-21Allow setting the name of a class or module. (#7483)Samuel Williams
Introduce `Module#set_temporary_name` for setting identifiers for otherwise anonymous modules/classes. Notes: Merged-By: ioquatix <[email protected]>
2023-04-11[DOC] Documentation for flags of RObjectPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7684
2023-03-20Use an st table for "too complex" objectsAaron Patterson
st tables will maintain insertion order so we can marshal dump / load objects with instance variables in the same order they were set on that particular instance [ruby-core:112926] [Bug #19535] Co-Authored-By: Jemma Issroff <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/7560
2023-03-16[DOC] Enhanced RDoc for TrueClass (#7521)Burdette Lamar
Notes: Merged-By: peterzhu2118 <[email protected]>
2023-03-13[DOC] Enhanced RDoc for NilClass (#7500)Burdette Lamar
Notes: Merged-By: peterzhu2118 <[email protected]>
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-02-27Fix spelling (#7389)John Bampton
Notes: Merged-By: k0kubun <[email protected]>
2023-02-19Remove (newly unneeded) remarks about aliasesBurdetteLamar
2023-02-15Encapsulate RCLASS_ATTACHED_OBJECTJean Boussier
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. Notes: Merged: https://github.com/ruby/ruby/pull/7308
2023-01-31YJIT: Implement codegen for Kernel#block_given? (#7202)Takashi Kokubun
Notes: Merged-By: maximecb <[email protected]>
2023-01-22Adjust braces [ci skip]Nobuyoshi Nakada
2023-01-04[DOC] Move the internal document for `Init_class_hierarchy`Nobuyoshi Nakada
It has hidden the document for `Object` class. Notes: Merged: https://github.com/ruby/ruby/pull/7057
2022-12-15Transition complex objects to "too complex" shapeJemma Issroff
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 <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/6931
2022-12-09Use rb_inspect instead of +PRIsVALUE for Object.inspectMatt Valentine-House
In order to preserve the values when TrueClass, FalseClass or NilClass are stored in ivars Notes: Merged: https://github.com/ruby/ruby/pull/6872
2022-11-22Remove dead code in rb_obj_copy_ivarPeter Zhu
The removed code is a duplicate of the code above. Notes: Merged: https://github.com/ruby/ruby/pull/6727
2022-11-21Refactor obj_ivar_set and vm_setivarPeter Zhu
obj_ivar_set and vm_setivar_slowpath is essentially doing the same thing, but the code is duplicated and not quite implemented in the same way, which could cause bugs. This commit refactors vm_setivar_slowpath to use obj_ivar_set. Notes: Merged: https://github.com/ruby/ruby/pull/6732
2022-11-18Update assertionAaron Patterson
New T_OBJECT objects will have a T_OBJECT shape