Skip to content

Commit ea8b53a

Browse files
committed
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.
1 parent 5f24741 commit ea8b53a

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

gc/default/default.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6006,9 +6006,10 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
60066006

60076007
if (RGENGC_CHECK_MODE) {
60086008
if (SPECIAL_CONST_P(a)) rb_bug("rb_gc_writebarrier: a is special const: %"PRIxVALUE, a);
6009-
if (SPECIAL_CONST_P(b)) rb_bug("rb_gc_writebarrier: b is special const: %"PRIxVALUE, b);
60106009
}
60116010

6011+
if (SPECIAL_CONST_P(b)) return;
6012+
60126013
GC_ASSERT(RB_BUILTIN_TYPE(a) != T_NONE);
60136014
GC_ASSERT(RB_BUILTIN_TYPE(a) != T_MOVED);
60146015
GC_ASSERT(RB_BUILTIN_TYPE(a) != T_ZOMBIE);

gc/mmtk/mmtk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
750750
{
751751
struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache();
752752

753+
if (SPECIAL_CONST_P(b)) return;
754+
753755
mmtk_object_reference_write_post(cache->mutator, (MMTk_ObjectReference)a);
754756
}
755757

include/ruby/internal/abi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* In released versions of Ruby, this number is not defined since teeny
2525
* versions of Ruby should guarantee ABI compatibility.
2626
*/
27-
#define RUBY_ABI_VERSION 1
27+
#define RUBY_ABI_VERSION 2
2828

2929
/* Windows does not support weak symbols so ruby_abi_version will not exist
3030
* in the shared library. */

include/ruby/internal/gc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,7 @@ rb_obj_written(
785785
RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
786786
#endif
787787

788-
if (!RB_SPECIAL_CONST_P(b)) {
789-
rb_gc_writebarrier(a, b);
790-
}
788+
rb_gc_writebarrier(a, b);
791789

792790
return a;
793791
}

0 commit comments

Comments
 (0)