From 71c398f298265244d7bc9d282668c389d9f2538f Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 30 Jul 2022 22:31:57 +0900 Subject: [PATCH] Perform Full-GC from `mrb_realloc_simple()` by `MRB_GC_STRESS + MRB_DEBUG` It also fills the GC'ed object area with `0xff` for debugging purposes. --- doc/guides/mrbconf.md | 2 ++ src/gc.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/doc/guides/mrbconf.md b/doc/guides/mrbconf.md index e71346ae6..05b7b5cc9 100644 --- a/doc/guides/mrbconf.md +++ b/doc/guides/mrbconf.md @@ -82,6 +82,8 @@ You can use mrbconfs with following ways: * When defined full GC is emitted per each `RBasic` allocation. * Mainly used in memory manager debugging. +* If defined at the same time as `MRB_DEBUG`, full GC is emitted also per each heap allocation (`mrb_malloc()` or etc.). + This configuration slows down mruby execution by a factor of 2 to 3 or even more. `MRB_GC_TURN_OFF_GENERATIONAL` diff --git a/src/gc.c b/src/gc.c index a3d496162..d5afc80a2 100644 --- a/src/gc.c +++ b/src/gc.c @@ -224,6 +224,9 @@ mrb_realloc_simple(mrb_state *mrb, void *p, size_t len) { void *p2; +#if defined(MRB_GC_STRESS) && defined(MRB_DEBUG) + mrb_full_gc(mrb); +#endif p2 = (mrb->allocf)(mrb, p, len, mrb->allocf_ud); if (!p2 && len > 0 && mrb->gc.heaps) { mrb_full_gc(mrb); @@ -921,6 +924,10 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end) default: break; } +#if defined(MRB_GC_STRESS) && defined(MRB_DEBUG) + memset(obj, -1, sizeof(RVALUE)); + paint_white(obj); +#endif obj->tt = MRB_TT_FREE; }