diff options
author | Peter Zhu <[email protected]> | 2025-06-02 16:31:28 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2025-06-03 12:04:24 -0400 |
commit | ea8b53a53954c2f34b1093ae2547951ae0e1fe8c (patch) | |
tree | 93bdeae1cb7622eeed5fd59c9fb2e850db99fc0a | |
parent | 5f247416b6b46b6f99c9f5229fab36ba721fd975 (diff) |
Allow pass special constants to the write barrier
Some GC implementations want to always know when an object is written to,
even if the written value is a special constant. Checking special constants
in rb_obj_written was a micro-optimization that made assumptions about
the GC implementation.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13497
-rw-r--r-- | gc/default/default.c | 3 | ||||
-rw-r--r-- | gc/mmtk/mmtk.c | 2 | ||||
-rw-r--r-- | include/ruby/internal/abi.h | 2 | ||||
-rw-r--r-- | include/ruby/internal/gc.h | 4 |
4 files changed, 6 insertions, 5 deletions
diff --git a/gc/default/default.c b/gc/default/default.c index 1b45d4b724..5664b3dd90 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -6006,9 +6006,10 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b) if (RGENGC_CHECK_MODE) { if (SPECIAL_CONST_P(a)) rb_bug("rb_gc_writebarrier: a is special const: %"PRIxVALUE, a); - if (SPECIAL_CONST_P(b)) rb_bug("rb_gc_writebarrier: b is special const: %"PRIxVALUE, b); } + if (SPECIAL_CONST_P(b)) return; + GC_ASSERT(RB_BUILTIN_TYPE(a) != T_NONE); GC_ASSERT(RB_BUILTIN_TYPE(a) != T_MOVED); GC_ASSERT(RB_BUILTIN_TYPE(a) != T_ZOMBIE); diff --git a/gc/mmtk/mmtk.c b/gc/mmtk/mmtk.c index 41e7f13972..9e4ee9f3de 100644 --- a/gc/mmtk/mmtk.c +++ b/gc/mmtk/mmtk.c @@ -750,6 +750,8 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b) { struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache(); + if (SPECIAL_CONST_P(b)) return; + mmtk_object_reference_write_post(cache->mutator, (MMTk_ObjectReference)a); } diff --git a/include/ruby/internal/abi.h b/include/ruby/internal/abi.h index e6d1fa7e8f..0c99d93bf9 100644 --- a/include/ruby/internal/abi.h +++ b/include/ruby/internal/abi.h @@ -24,7 +24,7 @@ * In released versions of Ruby, this number is not defined since teeny * versions of Ruby should guarantee ABI compatibility. */ -#define RUBY_ABI_VERSION 1 +#define RUBY_ABI_VERSION 2 /* Windows does not support weak symbols so ruby_abi_version will not exist * in the shared library. */ diff --git a/include/ruby/internal/gc.h b/include/ruby/internal/gc.h index 5ab3bb266e..19783f3023 100644 --- a/include/ruby/internal/gc.h +++ b/include/ruby/internal/gc.h @@ -785,9 +785,7 @@ rb_obj_written( RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line); #endif - if (!RB_SPECIAL_CONST_P(b)) { - rb_gc_writebarrier(a, b); - } + rb_gc_writebarrier(a, b); return a; } |