From 1a43231534ba9976655aa4885e1b267475b00fed Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Fri, 3 Apr 2015 14:15:02 -0700 Subject: [PATCH] [sgen] Don't assert in GC.GetTotalMemory. --- mono/metadata/sgen-marksweep.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mono/metadata/sgen-marksweep.c b/mono/metadata/sgen-marksweep.c index bbb420415c8..90a9a84c8c0 100644 --- a/mono/metadata/sgen-marksweep.c +++ b/mono/metadata/sgen-marksweep.c @@ -208,11 +208,13 @@ static SgenPointerQueue allocated_blocks; static void *empty_blocks = NULL; static size_t num_empty_blocks = 0; -#define FOREACH_BLOCK_NO_LOCK(bl) { \ +#define FOREACH_BLOCK_NO_LOCK_CONDITION(cond,bl) { \ size_t __index; \ - SGEN_ASSERT (0, sgen_is_world_stopped () && !sweep_in_progress (), "Can't iterate blocks while the world is running or sweep is in progress."); \ + SGEN_ASSERT (0, (cond) && !sweep_in_progress (), "Can't iterate blocks while the world is running or sweep is in progress."); \ for (__index = 0; __index < allocated_blocks.next_slot; ++__index) { \ (bl) = BLOCK_UNTAG (allocated_blocks.data [__index]); +#define FOREACH_BLOCK_NO_LOCK(bl) \ + FOREACH_BLOCK_NO_LOCK_CONDITION(sgen_is_world_stopped (), bl) #define FOREACH_BLOCK_HAS_REFERENCES_NO_LOCK(bl,hr) { \ size_t __index; \ SGEN_ASSERT (0, sgen_is_world_stopped () && !sweep_in_progress (), "Can't iterate blocks while the world is running or sweep is in progress."); \ @@ -1997,7 +1999,13 @@ major_get_used_size (void) gint64 size = 0; MSBlockInfo *block; - FOREACH_BLOCK_NO_LOCK (block) { + /* + * We're holding the GC lock, but the sweep thread might be running. Make sure it's + * finished, then we can iterate over the block array. + */ + major_finish_sweep_checking (); + + FOREACH_BLOCK_NO_LOCK_CONDITION (TRUE, block) { int count = MS_BLOCK_FREE / block->obj_size; void **iter; size += count * block->obj_size; -- 2.25.1