Skip to content

Commit 094418a

Browse files
byrooteregon
authored andcommitted
gc.h: Reintroduce immediate guard in rb_obj_written
This guard was removed in ruby#13497 on the justification that some GC may need to be notified even for immediate. But the two currently available GCs don't, and there are plenty of assumtions GCs don't everywhere, notably in YJIT and ZJIT. This optimization is also not so micro (but not huge either). I routinely see 1-2% wasted there on micro-benchmarks. So perhaps if in the future we actually need this, it might make sense to introduce a way for GCs to declare that as an option, but in the meantime it's extra overhead with little gain.
1 parent eaa952b commit 094418a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

gc/default/default.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6090,11 +6090,13 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
60906090
{
60916091
rb_objspace_t *objspace = objspace_ptr;
60926092

6093-
if (RGENGC_CHECK_MODE) {
6094-
if (SPECIAL_CONST_P(a)) rb_bug("rb_gc_writebarrier: a is special const: %"PRIxVALUE, a);
6095-
}
6096-
6097-
if (SPECIAL_CONST_P(b)) return;
6093+
#if RGENGC_CHECK_MODE
6094+
if (SPECIAL_CONST_P(a)) rb_bug("rb_gc_writebarrier: a is special const: %"PRIxVALUE, a);
6095+
if (SPECIAL_CONST_P(b)) rb_bug("rb_gc_writebarrier: b is special const: %"PRIxVALUE, b);
6096+
#else
6097+
ASSUME(!SPECIAL_CONST_P(a));
6098+
ASSUME(!SPECIAL_CONST_P(b));
6099+
#endif
60986100

60996101
GC_ASSERT(!during_gc);
61006102
GC_ASSERT(RB_BUILTIN_TYPE(a) != T_NONE);

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 0
27+
#define RUBY_ABI_VERSION 1
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,9 @@ rb_obj_written(
785785
RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
786786
#endif
787787

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

790792
return a;
791793
}

0 commit comments

Comments
 (0)