summaryrefslogtreecommitdiff
path: root/include/ruby/internal/core
AgeCommit message (Collapse)Author
3 days[nit] refactor rename inline functions卜部昌平
Pretty sure commit 0f64da9672d88921439f6fdb306d16fece9b9c90 didn't intend to welcome extension libraries to use these functions.
11 days[Bug #18433] Remove unneeded declarationNobuyoshi Nakada
This `rb_cObject` declaration was only for `rb_cData()` that was removed at 7c738ce5e649b82bdc1305d5c347e81886ee759a.
12 daysAdd field handle_weak_references to TypedDataPeter Zhu
This commit adds a field handle_weak_references to rb_data_type_struct for the callback when handling weak references. This avoids TypedData objects from needing to expose their rb_data_type_struct and weak references function.
2026-01-01Extract `RBIMPL_TYPEDDATA_PRECONDITION`Nobuyoshi Nakada
2025-12-31[DOC] Move typed-data related macrosNobuyoshi Nakada
The flags for `rb_data_type_t::flags` are public constants for defining `rb_data_type_t`. The embedded data flag and mask are internal implementation detail.
2025-12-31Make `RTYPEDDATA_EMBEDDABLE_P` internal-use onlyNobuyoshi Nakada
It should not be exposed because it is so implementation specific that it is only used in gc.c even within the entire Ruby source tree.
2025-12-29Return `NULL` in a `void *` functionNobuyoshi Nakada
2025-12-29Make `rb_check_typeddata` and `rbimpl_check_typeddata` identicalNobuyoshi Nakada
2025-12-29Declare `rb_data_typed_t` parameters and return values as nonullNobuyoshi Nakada
2025-12-29rtypeddata.h: Add missing `RBIMPL_CAST`Nobuyoshi Nakada
In public headers, casts should be enclosed in `RBIMPL_CAST` for compilation in C++.
2025-12-26Remove an useless macro definition `RSTRUCT_PTR`Nobuyoshi Nakada
The underlying definition, `rb_struct_ptr`, was removed four years ago.
2025-12-26Remove old APIs to allocate a data object deprecated for 5 yearsNobuyoshi Nakada
2025-12-18thread_sync.c: declare queue_data_type as parent of szqueue_data_type.Jean Boussier
Allows to remove some duplicated code like szqueue_length, etc.
2025-12-09Don't declare `rbimpl_check_typeddata` as pureJean Boussier
[Bug #21771] It may raise so it's incorrect and can lead to the compiler optimizing the call out.
2025-12-05fix typo s/sharable/shareable/Koichi Sasada
2025-12-05(experimental) RUBY_TYPED_FROZEN_SHAREABLE_NO_RECKoichi Sasada
`T_DATA` has a flag `RUBY_TYPED_FROZEN_SHAREABLE` which means if the `T_DATA` object is frozen, it can be sharable. On the `Ractor.make_sharable(obj)`, rechable objects from the `T_DATA` object will be apply `Ractor.make_shareable` recursively. `RUBY_TYPED_FROZEN_SHAREABLE_NO_REC` is similar to the `RUBY_TYPED_FROZEN_SHAREABLE`, but doesn't apply `Ractor.make_sharable` recursively for children. If it refers to unshareable objects, it will simply raise an error. I'm not sure this pattern is common or not, so it is not in public. If we find more cases, we can discuss publication.
2025-12-03Speedup TypedData_Get_StructJean Boussier
While profiling `Monitor#synchronize` and `Mutex#synchronize` I noticed a fairly significant amount of time spent in `rb_check_typeddata`. By implementing a fast path that assumes the object is valid and that can be inlined, it does make a significant difference: Before: ``` Mutex 13.548M (± 3.6%) i/s (73.81 ns/i) - 68.566M in 5.067444 Monitor 10.497M (± 6.5%) i/s (95.27 ns/i) - 52.529M in 5.032698s ``` After: ``` Mutex 20.887M (± 0.3%) i/s (47.88 ns/i) - 106.021M in 5.075989s Monitor 16.245M (±13.3%) i/s (61.56 ns/i) - 80.705M in 5.099680s ``` ```ruby require 'bundler/inline' gemfile do gem "benchmark-ips" end mutex = Mutex.new require "monitor" monitor = Monitor.new Benchmark.ips do |x| x.report("Mutex") { mutex.synchronize { } } x.report("Monitor") { monitor.synchronize { } } end ```
2025-11-11simplify RSRING_GETMEM() definition.nagachika
2025-11-11include/ruby/internal/core/rstring.h: Remove rbimpl_rstring_getmem() definition.nagachika
2025-11-11Remove rbimpl_rstring_getmem() usage as workaround for GCC 15.2.1 ↵nagachika
optimization bug. [Bug #21655]
2025-10-25Use pointer to the memberNobuyoshi Nakada
Instead of the offset calculation.
2025-10-25[DOC] Follow up GH-14470Nobuyoshi Nakada
`IS_TYPED_DATA` is no longer a flag in `type`, and the "embedded" flag has been shifted accordingly. ruby/ruby#14470
2025-10-08[Bug #21629] Initialize `struct RString`Nobuyoshi Nakada
2025-09-15[DOC] Fix typos in commentsÉtienne Barrié
2025-09-08Move `IS_TYPED_DATA` in RBasic.flagsJean Boussier
Ref: https://github.com/ruby/ruby/pull/14134#issuecomment-3207733725 We can't safely use low-bit pointer tagging anymore because `RTypedData.type` lines up with `RData.dfree` and there is no aligment guarantee on function pointers, as evidenced by `memcached` and `gpgme` gems. We also can't use FL_USER* for this, because extensions may use these for other purposes. Using a general flag for this is a bit unfortunate, as general flags are hard to come by, however I recently freed several of them, and we still have two or three free ones left.
2025-08-27Replace ROBJECT_EMBED by ROBJECT_HEAPJean Boussier
The embed layout is way more common than the heap one, especially since WVA. I think it makes for more readable code to inverse the flag.
2025-08-26Ensure T_OBJECT and T_IMEMO/fields have identical layoutJean Boussier
2025-08-14Fix a static assertion incompatible with C++98 (#14229)Takashi Kokubun
2025-08-14Fix documentation about struct RData's data fieldÉtienne Barrié
Also adds a static assertion to ensure the documented behavior stays true, namely that the data field is at the same position in the RData and RTypedData structs.
2025-08-12RTypedData: keep direct reference to IMEMO/fieldsJean Boussier
Similar to f3206cc79bec2fd852e81ec56de59f0a67ab32b7 but for TypedData. It's quite common for TypedData objects to have a mix of reference in their struct and some ivars. Since we do happen to have 8B free in the RtypedData struct, we could use it to keep a direct reference to the IMEMO/fields saving having to synchronize the VM and lookup the `gen_fields_tbl` on every ivar access. For old school Data classes however, we don't have free space, but this API is soft-deprecated and no longer very common.
2025-06-02shape.c: Implement a lock-free version of get_next_shape_internalJean Boussier
Whenever we run into an inline cache miss when we try to set an ivar, we may need to take the global lock, just to be able to lookup inside `shape->edges`. To solve that, when we're in multi-ractor mode, we can treat the `shape->edges` as immutable. When we need to add a new edge, we first copy the table, and then replace it with CAS. This increases memory allocations, however we expect that creating new transitions becomes increasingly rare over time. ```ruby class A def initialize(bool) @a = 1 if bool @b = 2 else @c = 3 end end def test @d = 4 end end def bench(iterations) i = iterations while i > 0 A.new(true).test A.new(false).test i -= 1 end end if ARGV.first == "ractor" ractors = 8.times.map do Ractor.new do bench(20_000_000 / 8) end end ractors.each(&:take) else bench(20_000_000) end ``` The above benchmark takes 27 seconds in Ractor mode on Ruby 3.4, and only 1.7s with this branch. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/13441
2025-05-28Use flag for RCLASS_IS_INITIALIZEDJohn Hawthorn
Previously we used a flag to set whether a module was uninitialized. When checked whether a class was initialized, we first had to check that it had a non-zero superclass, as well as that it wasn't BasicObject. With the advent of namespaces, RCLASS_SUPER is now an expensive operation, and though we could just check for the prime superclass, we might as well take this opportunity to use a flag so that we can perform the initialized check with as few instructions as possible. It's possible in the future that we could prevent uninitialized classes from being available to the user, but currently there are a few ways to do that. Notes: Merged: https://github.com/ruby/ruby/pull/13443
2025-05-26Add shape_id to RBasic under 32 bitJohn Hawthorn
This makes `RBobject` `4B` larger on 32 bit systems but simplifies the implementation a lot. [Feature #21353] Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/13341
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-05Save one VALUE per embedded RTypedDataJeremy Evans
This halves the amount of memory used for embedded RTypedData if they are one VALUE (8 bytes on 64-bit platforms) over the slot size limit. For Set, on 64-bit it uses an embedded 56-byte struct. With the previous implementation, the embedded structs starts at offset 32, resulting in a total size of 88. Since that is over the 80 byte limit, it goes to the next highest bucket, 160 bytes, wasting 72 bytes. This allows it to fit in a 80 byte bucket, which reduces the total size for small sets of from 224 bytes (160 bytes embedded, 64 bytes malloc, 72 bytes wasted in embedding) to 144 bytes (80 bytes embedded, 64 bytes malloc, 0 bytes wasted in embedding). Any other embedded RTypedData will see similar advantages if they are currently one VALUE over the limit. To implement this, remove the typed_flag from struct RTypedData. Embed the typed_flag information in the type member, which is now a tagged pointer using VALUE type, using the bottom low 2 bits as flags (1 bit for typed flag, the other for the embedded flag). To get the actual pointer, RTYPEDDATA_TYPE masks out the low 2 bits and then casts. That moves the RTypedData data pointer from offset 32 to offset 24 (on 64-bit). Vast amount of code in the internals (and probably external C extensions) expects the following code to work for both RData and non-embedded RTypedData: ```c DATA_PTR(obj) = some_pointer; ``` Allow this to work by moving the data pointer in RData between the dmark and dfree pointers, so it is at the same offset (24 on 64-bit). Other than these changes to the include files, the only changes needed were to gc.c, to account for the new struct layouts, handle setting the low bits in the type member, and to use RTYPEDDATA_TYPE(obj) instead of RTYPEDDATA(obj)->type. Notes: Merged: https://github.com/ruby/ruby/pull/13190
2025-02-12Remove dead iv_index_tbl field in RObjectPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12739
2024-11-13Mark strings returned by Symbol#to_s as chilled (#12065)Jean byroot Boussier
* Use FL_USER0 for ELTS_SHARED This makes space in RString for two bits for chilled strings. * Mark strings returned by `Symbol#to_s` as chilled [Feature #20350] `STR_CHILLED` now spans on two user flags. If one bit is set it marks a chilled string literal, if it's the other it marks a `Symbol#to_s` chilled string. Since it's not possible, and doesn't make much sense to include debug info when `--debug-frozen-string-literal` is set, we can't include allocation source, but we can safely include the symbol name in the warning message, making it much easier to find the source of the issue. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com> --------- Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com> Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-06-06Mark old Data API as deprecatedJean Boussier
[Feature #19998]
2024-03-23[DOC] Small edits in rbasic.hXavier Noria
2023-11-08TypedData_Make_Struct0: cast RTYPEDDATA_GET_DATA return pointerJean Boussier
Fixes: ``` /usr/local/ruby/include/ruby-3.3.0+0/ruby/internal/core/rtypeddata.h:467:33: error: invalid conversion from ‘void*’ to ‘parser_t*’ [-fpermissive] 467 | (sval) = RTYPEDDATA_GET_DATA(result); \ | ~~~~~~~~~~~~~~~~~~~^~~~~~~~ | | | void* ```
2023-11-07Implement embedded TypedData objectsPeter Zhu
This commit adds a new flag RUBY_TYPED_EMBEDDABLE that allows the data of a TypedData object to be embedded after the object itself. This will improve cache locality and allow us to save the 8 byte data pointer. Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
2023-08-02YJIT: Move ROBJECT_OFFSET_* to yjit.c (#8157)Takashi Kokubun
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2023-07-24RString NULL ptr check only when RUBY_DEBUGNobuyoshi Nakada
Since edf01d4e82d8e44ee30ec41fbcb7f802bc8b8c5d, fake string treats NULL as an empty string.
2023-07-20Embed struct rmatch into GC slot (#8097)Kunshan Wang
2023-07-13Remove RARRAY_CONST_PTR_TRANSIENTPeter Zhu
RARRAY_CONST_PTR now does the same things as RARRAY_CONST_PTR_TRANSIENT. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13Remove RARRAY_PTR_USE_TRANSIENTPeter Zhu
RARRAY_PTR_USE now does the same things as RARRAY_PTR_USE_TRANSIENT. Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13Remove rb_array_ptr_use_{start,end}Peter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/8071
2023-07-13[Feature #19730] Remove transient heapPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7942
2023-07-13Store object age in a bitmapMatt Valentine-House
Closes [Feature #19729] Previously 2 bits of the flags on each RVALUE are reserved to store the number of GC cycles that each object has survived. This commit introduces a new bit array on the heap page, called age_bits, to store that information instead. This patch still reserves one of the age bits in the flags (the old FL_PROMOTED0 bit, now renamed FL_PROMOTED). This is set to 0 for young objects and 1 for old objects, and is used as a performance optimisation for the write barrier. Fetching the age_bits from the heap page and doing the required math to calculate if the object was old or not would slow down the write barrier. So we keep this bit synced in the flags for fast access. Notes: Merged: https://github.com/ruby/ruby/pull/7938
2023-06-06Unify length field for embedded and heap strings (#7908)Peter Zhu
* Unify length field for embedded and heap strings The length field is of the same type and position in RString for both embedded and heap allocated strings, so we can unify it. * Remove RSTRING_EMBED_LEN Notes: Merged-By: maximecb <maximecb@ruby-lang.org>