ruby/internal
Jean Boussier a74c385208 Make setting and accessing class ivars lock-free
Now that class fields have been deletated to a T_IMEMO/class_fields
when we're in multi-ractor mode, we can read and write class instance
variable in an atomic way using Read-Copy-Update (RCU).

Note when in multi-ractor mode, we always use RCU. In theory
we don't need to, instead if we ensured the field is written
before the shape is updated it would be safe.

Benchmark:

```ruby
Warning[:experimental] = false

class Foo
  @foo = 1
  @bar = 2
  @baz = 3
  @egg = 4
  @spam = 5

  class << self
    attr_reader :foo, :bar, :baz, :egg, :spam
  end
end

ractors = 8.times.map do
  Ractor.new do
    1_000_000.times do
      Foo.bar + Foo.baz * Foo.egg - Foo.spam
    end
  end
end

if Ractor.method_defined?(:value)
  ractors.each(&:value)
else
  ractors.each(&:take)
end
```

This branch vs Ruby 3.4:

```bash
$ hyperfine -w 1 'ruby --disable-all ../test.rb' './miniruby ../test.rb'

Benchmark 1: ruby --disable-all ../test.rb
  Time (mean ± σ):      3.162 s ±  0.071 s    [User: 2.783 s, System: 10.809 s]
  Range (min … max):    3.093 s …  3.337 s    10 runs

Benchmark 2: ./miniruby ../test.rb
  Time (mean ± σ):     208.7 ms ±   4.6 ms    [User: 889.7 ms, System: 6.9 ms]
  Range (min … max):   202.8 ms … 222.0 ms    14 runs

Summary
  ./miniruby ../test.rb ran
   15.15 ± 0.47 times faster than ruby --disable-all ../test.rb
```
2025-06-12 14:55:13 +02:00
..
array.h Optimized instruction for Array#freeze 2024-09-05 12:46:02 +02:00
basic_operators.h Optimize instructions when creating an array just to call include? (#12123) 2024-11-26 14:31:08 -05:00
bignum.h Stop exporting symbols for MJIT 2023-03-06 21:59:23 -08:00
bits.h Add integer overflow check macros for add/sub as well as mul 2024-11-09 00:08:03 +09:00
class.h Make setting and accessing class ivars lock-free 2025-06-12 14:55:13 +02:00
cmdlineopt.h Implement Options as part of ZJITState 2025-04-18 21:52:57 +09:00
compar.h
compile.h Move the PC regardless of the leaf flag (#8232) 2023-08-16 20:28:33 -07:00
compilers.h
complex.h
cont.h Free everything at shutdown 2023-12-07 15:52:35 -05:00
dir.h
enc.h
encoding.h string.c: Directly create strings with the correct encoding 2024-11-13 13:32:32 +01:00
enum.h
enumerator.h
error.h Implement rb_bug_without_die 2024-12-12 14:07:56 -05:00
eval.h namespace on read 2025-05-11 23:32:50 +09:00
file.h Revert "reuse open(2) from rb_file_load_ok on POSIX-like system" 2023-02-27 09:24:45 -08:00
fixnum.h rb_fix_mul_fix needs internal/bits.h for MUL_OVERFLOW_FIXNUM_P 2024-10-08 23:29:49 +09:00
gc.h Move object_id in object fields. 2025-05-08 07:58:05 +02:00
hash.h Support Marshal.{dump,load} for core Set 2025-04-28 08:38:35 -07:00
imemo.h Turn rb_classext_t.fields into a T_IMEMO/class_fields 2025-06-12 07:58:16 +02:00
inits.h Merge rb_objspace_alloc and Init_heap. 2024-04-04 15:00:57 +01:00
io.h rb_io_blocking_operation_exit should not execute with pending interrupts. 2025-06-06 13:13:16 +09:00
load.h namespace on read 2025-05-11 23:32:50 +09:00
loadpath.h
math.h
missing.h Free environ when RUBY_FREE_AT_EXIT 2024-01-11 10:09:53 -05:00
namespace.h Show experimental warning when namespace is enabled 2025-05-11 23:32:50 +09:00
numeric.h Faster Integer.sqrt for large bignum 2024-03-18 13:52:27 +09:00
object.h Remove unused RBASIC_RESET_FLAGS 2025-06-02 09:52:25 -04:00
parse.h [Bug #20989] Ripper: Pass compile_error 2024-12-28 11:25:57 +09:00
proc.h Remove dead function rb_func_proc_new 2025-01-20 10:31:36 -05:00
process.h Put rb_fork back into process.c 2023-05-21 23:00:27 +09:00
ractor.h Fix shared GC with -DRUBY_DEBUG 2024-10-24 16:08:46 +01:00
random.h Free everything at shutdown 2023-12-07 15:52:35 -05:00
range.h Implement Struct on VWA 2023-06-05 15:47:16 -04:00
rational.h
re.h String#gsub! Elide MatchData allocation when we know it can't escape 2025-02-24 18:32:46 +01:00
ruby_parser.h Change return value of gets function to be rb_parser_string_t * instead of VALUE 2024-05-04 11:59:10 +09:00
sanitizers.h Make ASAN default option string built-in libruby 2025-03-16 17:33:58 +09:00
serial.h
set_table.h Optimize callcache invalidation for refinements 2025-06-09 12:33:35 +09:00
signal.h Revert "hijack SIGCHLD handler for internal use" 2024-04-04 21:48:14 +09:00
st.h Move internal ST functions to internal/st.h 2023-12-25 10:41:12 -05:00
static_assert.h
string.h Lock-free hash set for fstrings [Feature #21268] 2025-04-18 13:03:54 +09:00
struct.h Remove dead function rb_struct_const_heap_ptr 2025-01-03 17:02:50 -05:00
symbol.h Move global symbol reference updating to rb_sym_global_symbols_update_references 2025-02-10 08:47:44 -05:00
thread.h Allow IO#close to interrupt IO operations on fibers using fiber_interrupt hook. (#12839) 2025-05-23 14:55:05 +09:00
time.h [Bug #21144] Win32: Use Windows time zone ID if TZ is not set 2025-02-19 18:27:32 +09:00
transcode.h Free everything at shutdown 2023-12-07 15:52:35 -05:00
util.h
variable.h Refactor the last references to rb_shape_t 2025-06-11 16:38:38 +02:00
vm.h namespace on read 2025-05-11 23:32:50 +09:00
warnings.h