summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-06-28 22:03:03 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-06-30 23:59:04 +0900
commit5204ad56e17c336af6730ee93a2a9113a11a932d (patch)
tree0ff08bf6784215fbe79f8c641e74db1232532984 /gc.c
parent7a0a218dff0f01408b33815a027aa16707ab1cdc (diff)
Compile debugging code for stress to class always
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/gc.c b/gc.c
index 6db908dbbb..976f72a1ea 100644
--- a/gc.c
+++ b/gc.c
@@ -492,7 +492,7 @@ int ruby_rgengc_debug;
#endif
#ifndef GC_DEBUG_STRESS_TO_CLASS
-#define GC_DEBUG_STRESS_TO_CLASS 0
+#define GC_DEBUG_STRESS_TO_CLASS RUBY_DEBUG
#endif
#ifndef RGENGC_OBJ_INFO
@@ -1044,8 +1044,10 @@ VALUE *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
#define ruby_gc_stress_mode objspace->gc_stress_mode
#if GC_DEBUG_STRESS_TO_CLASS
#define stress_to_class objspace->stress_to_class
+#define set_stress_to_class(c) (stress_to_class = (c))
#else
-#define stress_to_class 0
+#define stress_to_class (objspace, 0)
+#define set_stress_to_class(c) (objspace, (c))
#endif
#if 0
@@ -2845,14 +2847,12 @@ newobj_of0(VALUE klass, VALUE flags, int wb_protected, rb_ractor_t *cr, size_t a
RB_DEBUG_COUNTER_INC(obj_newobj);
(void)RB_DEBUG_COUNTER_INC_IF(obj_newobj_wb_unprotected, !wb_protected);
-#if GC_DEBUG_STRESS_TO_CLASS
if (UNLIKELY(stress_to_class)) {
long i, cnt = RARRAY_LEN(stress_to_class);
for (i = 0; i < cnt; ++i) {
if (klass == RARRAY_AREF(stress_to_class, i)) rb_memerror();
}
}
-#endif
size_t size_pool_idx = size_pool_idx_for_size(alloc_size);
@@ -13805,7 +13805,6 @@ rb_gcdebug_sentinel(VALUE obj, const char *name)
#endif /* GC_DEBUG */
-#if GC_DEBUG_STRESS_TO_CLASS
/*
* call-seq:
* GC.add_stress_to_class(class[, ...])
@@ -13819,7 +13818,7 @@ rb_gcdebug_add_stress_to_class(int argc, VALUE *argv, VALUE self)
rb_objspace_t *objspace = &rb_objspace;
if (!stress_to_class) {
- stress_to_class = rb_ary_hidden_new(argc);
+ set_stress_to_class(rb_ary_hidden_new(argc));
}
rb_ary_cat(stress_to_class, argv, argc);
return self;
@@ -13844,12 +13843,11 @@ rb_gcdebug_remove_stress_to_class(int argc, VALUE *argv, VALUE self)
rb_ary_delete_same(stress_to_class, argv[i]);
}
if (RARRAY_LEN(stress_to_class) == 0) {
- stress_to_class = 0;
+ set_stress_to_class(0);
}
}
return Qnil;
}
-#endif
/*
* Document-module: ObjectSpace
@@ -13975,10 +13973,10 @@ Init_GC(void)
rb_define_singleton_method(rb_mGC, "verify_compaction_references", rb_f_notimplement, -1);
}
-#if GC_DEBUG_STRESS_TO_CLASS
- rb_define_singleton_method(rb_mGC, "add_stress_to_class", rb_gcdebug_add_stress_to_class, -1);
- rb_define_singleton_method(rb_mGC, "remove_stress_to_class", rb_gcdebug_remove_stress_to_class, -1);
-#endif
+ if (GC_DEBUG_STRESS_TO_CLASS) {
+ rb_define_singleton_method(rb_mGC, "add_stress_to_class", rb_gcdebug_add_stress_to_class, -1);
+ rb_define_singleton_method(rb_mGC, "remove_stress_to_class", rb_gcdebug_remove_stress_to_class, -1);
+ }
{
VALUE opts;