summaryrefslogtreecommitdiff
path: root/marshal.c
AgeCommit message (Collapse)Author
2024-06-02Eliminate internal uses of `Data_Wrap_Struct`Jean Boussier
Ref: https://github.com/ruby/ruby/pull/10872 These should be the last internal uses of the old `Data` API inside Ruby itself. Some use remain in a couple default gems.
2024-05-12[Bug #20481] Check for unmarshaling ivarNobuyoshi Nakada
Prohibit setting instance variables of existing classes and modules via link.
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-27Use RB_SPECIAL_CONST_P instead of rb_special_const_pPeter Zhu
rb_special_const_p returns a VALUE (Qtrue or Qfalse), so we shouldn't assume that Qfalse is 0. We should instead use RB_SPECIAL_CONST_P.
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-01-19Remove null checks for xfreePeter Zhu
xfree can handle null values, so we don't need to check it.
2023-12-07Free everything at shutdownAdam Hess
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown. Co-authored-by: Nobuyoshi Nakada <[email protected]> Co-authored-by: Peter Zhu <[email protected]>
2023-12-07Use free with ruby_dtoaJohn Hawthorn
In ae0ceafb0c0d05cc80623b525070255e3abb34ef ruby_dtoa was switched to use malloc instead of xmalloc, which means that consumers should be using free instead of xfree. Otherwise we will artificially shrink oldmalloc_increase_bytes.
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-20marshal.c: embed load and dump argument objectsJean Boussier
This avoid a bit of needless malloc churn.
2023-08-20Align the type of `num_entries` to `st_table`Nobuyoshi Nakada
2023-06-20Copy instance variables to regexp from marshaled dataNobuyoshi Nakada
`rb_ivar_foreach` disallows `ST_DELETE`. Notes: Merged: https://github.com/ruby/ruby/pull/7962
2023-04-26marshal.c: shallow freeze user objectsJean Boussier
When `freeze: true` argument is passed. [Bug #19427] Notes: Merged: https://github.com/ruby/ruby/pull/7764
2023-02-21Marshal.load: restore instance variables on RegexpJean Boussier
[Bug #19439] The instance variables were restore on the Regexp source, not the regexp itself. Unfortunately we have a bit of a chicken and egg problem. The source holds the encoding, and the encoding need to be set on the source to be able to instantiate the Regexp. So the instance variables have to be read on the `source`. To correct this we transfert the instance variables after instantiating the Regexp. The only way to avoid this would be to read the instance variable twice and rewind. Notes: Merged: https://github.com/ruby/ruby/pull/7323
2023-02-16Move `attached_object` into `rb_classext_struct`Jean Boussier
Given that signleton classes don't have an allocator, we can re-use these bytes to store the attached object in `rb_classext_struct` without making it larger. Notes: Merged: https://github.com/ruby/ruby/pull/7309
2023-02-13Marshal.load: also freeze extended objectsJean Boussier
[Bug #19427] The `proc` wouldn't be called either, that fixes both. Notes: Merged: https://github.com/ruby/ruby/pull/7284
2022-12-07Stop transitioning to UNDEF when undefining an instance variableAaron Patterson
Cases like this: ```ruby obj = Object.new loop do obj.instance_variable_set(:@foo, 1) obj.remove_instance_variable(:@foo) end ``` can cause us to use many more shapes than we want (and even run out). This commit changes the code such that when an instance variable is removed, we'll walk up the shape tree, find the shape, then rebuild any child nodes that happened to be below the "targetted for removal" IV. This also requires moving any instance variables so that indexes derived from the shape tree will work correctly. Co-Authored-By: Jemma Issroff <[email protected]> Co-authored-by: John Hawthorn <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/6866
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-10-31Implement object shapes for T_CLASS and T_MODULE (#6637)John Hawthorn
* Avoid RCLASS_IV_TBL in marshal.c * Avoid RCLASS_IV_TBL for class names * Avoid RCLASS_IV_TBL for autoload * Avoid RCLASS_IV_TBL for class variables * Avoid copying RCLASS_IV_TBL onto ICLASSes * Use object shapes for Class and Module IVs Notes: Merged-By: jhawthorn <[email protected]>
2022-10-11Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff
This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
2022-09-30Revert "This commit implements the Object Shapes technique in CRuby."Aaron Patterson
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-28This commit implements the Object Shapes technique in CRuby.Jemma Issroff
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 <[email protected]> Co-Authored-By: Eileen M. Uchitelle <[email protected]> Co-Authored-By: John Hawthorn <[email protected]>
2022-09-26Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson
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-26This commit implements the Object Shapes technique in CRuby.Jemma Issroff
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 <[email protected]> Co-Authored-By: Eileen M. Uchitelle <[email protected]> Co-Authored-By: John Hawthorn <[email protected]> Notes: Merged: https://github.com/ruby/ruby/pull/6386
2022-09-10Using is_broken_string functionS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6346
2022-09-02`w_bigfixnum` is used only for large FIXNUMNobuyoshi Nakada
2022-09-02Adjust styles [ci skip]Nobuyoshi Nakada
2022-08-15Optimize Marshal dump/load for large (> 31-bit) FIXNUM (#6229)John Hawthorn
* Optimize Marshal dump of large fixnum Marshal's FIXNUM type only supports 31-bit fixnums, so on 64-bit platforms the 63-bit fixnums need to be represented in Marshal's BIGNUM. Previously this was done by converting to a bugnum and serializing the bignum object. This commit avoids allocating the intermediate bignum object, instead outputting the T_FIXNUM directly to a Marshal bignum. This maintains the same representation as the previous implementation, including not using LINKs for these large fixnums (an artifact of the previous implementation always allocating a new BIGNUM). This commit also avoids unnecessary st_lookups on immediate values, which we know will not be in that table. * Fastpath for loading FIXNUM from Marshal bignum * Run update-deps Notes: Merged-By: jhawthorn <[email protected]>
2022-08-06Adjust styles [ci skip]Nobuyoshi Nakada
2022-07-26Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu
rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-06-17Using is_ascii_string to check encodingS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/5867
2021-12-25Fix typos [ci skip]Kazuhiro NISHIYAMA
2021-10-05marshal.c Marshal.load accepts a freeze: true option.Jean Boussier
Fixes [Feature #18148] When set, all the loaded objects are returned as frozen. If a proc is provided, it is called with the objects already frozen.
2021-10-03Using NIL_P macro instead of `== Qnil`S.H
Notes: Merged: https://github.com/ruby/ruby/pull/4925 Merged-By: nobu <[email protected]>
2021-10-02Restore Hash#compare_by_identity mode [Bug #18171]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4893
2021-09-30marshal.c: don't call the proc with partially initialized objects. (#4866)Jean byroot Boussier
For cyclic objects, it requires to keep a st_table of the partially initialized objects. Notes: Merged-By: byroot <[email protected]>
2021-09-23Add symname_equal_lit for comparison with a string literalNobuyoshi Nakada
2021-09-23Prohibit invalid encoding symbols [Bug #18184]Nobuyoshi Nakada
2021-09-23Check instance variable count overflowNobuyoshi Nakada
2021-09-23Extract ruby2_keywords predicate and setterNobuyoshi Nakada
2021-09-23Turned to_be_skipped_id to an inline functionNobuyoshi Nakada
2021-09-23Check the encoding of `ruby2_keywords_flag` [Bug #18184]Nobuyoshi Nakada
2021-09-22Check the entire name as `ruby2_keywords_flag` [Bug #18184]Nobuyoshi Nakada
2021-09-15Marshal.load: do not call the proc until strings have their encodingJean Boussier
Ref: https://bugs.ruby-lang.org/issues/18141 Notes: Merged: https://github.com/ruby/ruby/pull/4797
2021-03-20Remove unneeded declarationsS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4295 Merged-By: nobu <[email protected]>
2020-10-21Don't redefine #rb_intern over and over againStefan Stüben
Notes: Merged: https://github.com/ruby/ruby/pull/3589
2020-09-05Removed useless castsNobuyoshi Nakada
2020-08-15RARRAY_AREF: convert into an inline function卜部昌平
RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function. Notes: Merged: https://github.com/ruby/ruby/pull/3419