From 608915353bf53f991f01f1c4d818fed5134ed293 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Thu, 13 Jun 2024 12:11:32 +0900 Subject: [PATCH] avoid recursive calls on `check_rvalue_consistency` `check_rvalue_consistency` uses bitmap and `RVALUE_WB_UNPROTECTED` etc calls `check_rvalue_consistency` again. --- gc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/gc.c b/gc.c index aa5b720a5c6023..94df028a76b05b 100644 --- a/gc.c +++ b/gc.c @@ -1538,18 +1538,22 @@ tick(void) static inline VALUE check_rvalue_consistency(const VALUE obj); +#define RVALUE_MARKED_BITMAP(obj) MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(obj), (obj)) +#define RVALUE_WB_UNPROTECTED_BITMAP(obj) MARKED_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), (obj)) +#define RVALUE_MARKING_BITMAP(obj) MARKED_IN_BITMAP(GET_HEAP_MARKING_BITS(obj), (obj)) +#define RVALUE_UNCOLLECTIBLE_BITMAP(obj) MARKED_IN_BITMAP(GET_HEAP_UNCOLLECTIBLE_BITS(obj), (obj)) + static inline int RVALUE_MARKED(VALUE obj) { check_rvalue_consistency(obj); - return MARKED_IN_BITMAP(GET_HEAP_MARK_BITS(obj), (obj)) != 0; + return RVALUE_MARKED_BITMAP(obj) != 0; } static inline int RVALUE_PINNED(VALUE obj) { check_rvalue_consistency(obj); - return MARKED_IN_BITMAP(GET_HEAP_PINNED_BITS(obj), (obj)) != 0; } @@ -1557,14 +1561,14 @@ static inline int RVALUE_WB_UNPROTECTED(VALUE obj) { check_rvalue_consistency(obj); - return MARKED_IN_BITMAP(GET_HEAP_WB_UNPROTECTED_BITS(obj), (obj)) != 0; + return RVALUE_WB_UNPROTECTED_BITMAP(obj) != 0; } static inline int RVALUE_MARKING(VALUE obj) { check_rvalue_consistency(obj); - return MARKED_IN_BITMAP(GET_HEAP_MARKING_BITS(obj), (obj)) != 0; + return RVALUE_MARKING_BITMAP(obj) != 0; } static inline int @@ -1578,10 +1582,10 @@ static inline int RVALUE_UNCOLLECTIBLE(VALUE obj) { check_rvalue_consistency(obj); - return MARKED_IN_BITMAP(GET_HEAP_UNCOLLECTIBLE_BITS(obj), (obj)) != 0; + return RVALUE_UNCOLLECTIBLE_BITMAP(obj) != 0; } -#define RVALUE_PAGE_MARKED(page, obj) MARKED_IN_BITMAP((page)->mark_bits, (obj)) +#define RVALUE_PAGE_MARKED(page, obj) MARKED_IN_BITMAP((page)->mark_bits, (obj)) #define RVALUE_PAGE_WB_UNPROTECTED(page, obj) MARKED_IN_BITMAP((page)->wb_unprotected_bits, (obj)) #define RVALUE_PAGE_UNCOLLECTIBLE(page, obj) MARKED_IN_BITMAP((page)->uncollectible_bits, (obj)) #define RVALUE_PAGE_MARKING(page, obj) MARKED_IN_BITMAP((page)->marking_bits, (obj)) @@ -1624,10 +1628,10 @@ check_rvalue_consistency_force(const VALUE obj, int terminate) ; } else { - const int wb_unprotected_bit = RVALUE_WB_UNPROTECTED(obj); - const int uncollectible_bit = RVALUE_UNCOLLECTIBLE(obj) != 0; - const int mark_bit = RVALUE_MARKED(obj); - const int marking_bit = RVALUE_MARKING(obj); + const int wb_unprotected_bit = RVALUE_WB_UNPROTECTED_BITMAP(obj) != 0; + const int uncollectible_bit = RVALUE_UNCOLLECTIBLE_BITMAP(obj) != 0; + const int mark_bit = RVALUE_MARKED_BITMAP(obj); + const int marking_bit = RVALUE_MARKING_BITMAP(obj); const int remembered_bit = MARKED_IN_BITMAP(GET_HEAP_PAGE(obj)->remembered_bits, obj) != 0; const int age = RVALUE_AGE_GET((VALUE)obj);