From e02944035d6508187e03358b8c35558c93de4dd0 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Thu, 24 Sep 2020 13:39:36 -0400 Subject: [PATCH] [Mono] [GC] Fix TotalBytesAllocated and reenable test (#20427) TotalBytesAllocated was sometimes not monotonically increasing on Mono. The reason was that when a thread was detached, we were not counting bytes allocated in its thread local allocation buffer. So, under the right circumstances the bytes would be counted while the thread is attached, but then get lost when the thread detached. Fixes: https://github.com/dotnet/runtime/issues/2280 Co-authored-by: naricc --- mono/metadata/sgen-mono.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c index 6f732aff6d2..efb3afbd799 100644 --- a/mono/metadata/sgen-mono.c +++ b/mono/metadata/sgen-mono.c @@ -2216,7 +2216,7 @@ sgen_client_thread_detach_with_lock (SgenThreadInfo *p) mono_tls_set_sgen_thread_info (NULL); - sgen_increment_bytes_allocated_detached (p->total_bytes_allocated); + sgen_increment_bytes_allocated_detached (p->total_bytes_allocated + (p->tlab_next - p->tlab_start)); tid = mono_thread_info_get_tid (p); -- 2.11.4.GIT