Added tracking for detached threads.
authorNathan Ricci <naricc@microsoft.com>
Thu, 22 Aug 2019 18:14:39 +0000 (14:14 -0400)
committerNathan Ricci <naricc@microsoft.com>
Thu, 22 Aug 2019 18:14:39 +0000 (14:14 -0400)
Commit migrated from https://github.com/mono/mono/commit/bfce92d9dd995d24f2563fef36ac77d2a15dee8f

src/mono/mono/metadata/sgen-mono.c
src/mono/mono/sgen/sgen-alloc.c
src/mono/mono/sgen/sgen-gc.h

index f38bba0..66d6d96 100644 (file)
@@ -56,9 +56,12 @@ gboolean sgen_mono_xdomain_checks = FALSE;
 /* Functions supplied by the runtime to be called by the GC */
 static MonoGCCallbacks gc_callbacks;
 
-/* The total number of bytes allocated so far in program exection.
+/* The total number of bytes allocated so far in program exection by all attached threads.
  * This is not constantly syncrhonized, but only updated on each GC. */
-static guint64 total_bytes_allocated = 0;
+static guint64 bytes_allocated_attached = 0;
+
+/* Total bytes allocated so far in program exevution by detached threads */ 
+static guint64 bytes_allocated_detached = 0;
 
 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
        a = i,
@@ -2073,6 +2076,8 @@ sgen_client_thread_detach_with_lock (SgenThreadInfo *p)
 
        mono_tls_set_sgen_thread_info (NULL);
 
+       bytes_allocated_detached += p->total_bytes_allocated;
+
        tid = mono_thread_info_get_tid (p);
 
        mono_threads_add_joinable_runtime_thread (&p->client_info.info);
@@ -2514,9 +2519,9 @@ mono_gc_get_los_limit (void)
 }
 
 void
-sgen_set_total_bytes_allocated(guint64 bytes)
+sgen_set_bytes_allocated_attached(guint64 bytes)
 {
-       total_bytes_allocated = bytes;
+       bytes_allocated_attached = bytes;
 }
 
 guint64
@@ -2538,7 +2543,7 @@ mono_gc_get_total_allocated_bytes(MonoBoolean precise)
                mono_gc_restart_world();
        }
        
-       return total_bytes_allocated;
+       return bytes_allocated_attached + bytes_allocated_detached;
 }
 
 
index b471ccb..2d4d788 100644 (file)
@@ -520,7 +520,7 @@ sgen_clear_tlabs (void)
                info->tlab_real_end = NULL;
        } FOREACH_THREAD_END
 
-       sgen_set_total_bytes_allocated(total_bytes_allocated_globally);
+       sgen_set_bytes_allocated_attached(total_bytes_allocated_globally);
 } 
 
 void sgen_update_allocation_count (void)
@@ -532,7 +532,7 @@ void sgen_update_allocation_count (void)
                total_bytes_allocated_globally += info->total_bytes_allocated;
        } FOREACH_THREAD_END
 
-       sgen_set_total_bytes_allocated(total_bytes_allocated_globally);
+       sgen_set_bytes_allocated_attached(total_bytes_allocated_globally);
 }
 
 
index 62f7b2e..85ceb1c 100644 (file)
@@ -477,7 +477,7 @@ int sgen_get_current_collection_generation (void);
 gboolean sgen_collection_is_concurrent (void);
 gboolean sgen_get_concurrent_collection_in_progress (void);
 
-void sgen_set_total_bytes_allocated(guint64);
+void sgen_set_bytes_allocated_attached(guint64);
 
 typedef struct _SgenFragment SgenFragment;