From 661418b10ca810b03165932199ee5f068913d3ed Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Mon, 9 Sep 2019 16:39:51 -0400 Subject: [PATCH] Refactored where the varaibles for allocation count live. Commit migrated from https://github.com/mono/mono/commit/f7dcc20bc63febff0b8c800ec2fbcfcc16f7e252 --- src/mono/mono/metadata/sgen-mono.c | 27 +++------------------------ src/mono/mono/sgen/sgen-alloc.c | 36 +++++++++++++++++++++++++++++++++++- src/mono/mono/sgen/sgen-gc.h | 4 +++- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/mono/mono/metadata/sgen-mono.c b/src/mono/mono/metadata/sgen-mono.c index 24c4cc8..c9c57af 100644 --- a/src/mono/mono/metadata/sgen-mono.c +++ b/src/mono/mono/metadata/sgen-mono.c @@ -56,13 +56,6 @@ 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 by all attached threads. - * This is not constantly syncrhonized, but only updated on each GC. */ -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, @@ -2062,7 +2055,7 @@ sgen_client_thread_detach_with_lock (SgenThreadInfo *p) mono_tls_set_sgen_thread_info (NULL); - bytes_allocated_detached += p->total_bytes_allocated; + increment_bytes_allocated_detached(p->total_bytes_allocated); tid = mono_thread_info_get_tid (p); @@ -2504,11 +2497,7 @@ mono_gc_get_los_limit (void) return SGEN_MAX_SMALL_OBJ_SIZE; } -void -sgen_set_bytes_allocated_attached (guint64 bytes) -{ - bytes_allocated_attached = bytes; -} + guint64 mono_gc_get_allocated_bytes_for_current_thread (void) @@ -2523,17 +2512,7 @@ mono_gc_get_allocated_bytes_for_current_thread (void) guint64 mono_gc_get_total_allocated_bytes (MonoBoolean precise) { - if (precise) { - LOCK_GC; - sgen_stop_world (0, FALSE); - - sgen_update_allocation_count (); - - sgen_restart_world (0, FALSE); - UNLOCK_GC; - } - - return bytes_allocated_attached + bytes_allocated_detached; + return sgen_get_total_allocated_bytes (precise); } diff --git a/src/mono/mono/sgen/sgen-alloc.c b/src/mono/mono/sgen/sgen-alloc.c index d5679f0..e096dee 100644 --- a/src/mono/mono/sgen/sgen-alloc.c +++ b/src/mono/mono/sgen/sgen-alloc.c @@ -45,9 +45,15 @@ static guint64 stat_objects_alloced = 0; static guint64 stat_bytes_alloced = 0; static guint64 stat_bytes_alloced_los = 0; - #endif +/* 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 bytes_allocated_attached = 0; + +/* Total bytes allocated so far in program exevution by detached threads */ +static guint64 bytes_allocated_detached = 0; + /* * Allocation is done from a Thread Local Allocation Buffer (TLAB). TLABs are allocated * from nursery fragments. @@ -535,6 +541,34 @@ void sgen_update_allocation_count (void) sgen_set_bytes_allocated_attached (total_bytes_allocated_globally); } +void +sgen_set_bytes_allocated_attached (guint64 bytes) +{ + bytes_allocated_attached = bytes; +} + +void +increment_bytes_allocated_detached(guint64 bytes) +{ + bytes_allocated_detached += bytes; +} + +guint64 +sgen_get_total_allocated_bytes (MonoBoolean precise) +{ + if (precise) { + LOCK_GC; + sgen_stop_world (0, FALSE); + + sgen_update_allocation_count (); + + sgen_restart_world (0, FALSE); + UNLOCK_GC; + } + + return bytes_allocated_attached + bytes_allocated_detached; +} + void sgen_init_allocator (void) diff --git a/src/mono/mono/sgen/sgen-gc.h b/src/mono/mono/sgen/sgen-gc.h index a3e08d4..35a4665 100644 --- a/src/mono/mono/sgen/sgen-gc.h +++ b/src/mono/mono/sgen/sgen-gc.h @@ -477,7 +477,8 @@ int sgen_get_current_collection_generation (void); gboolean sgen_collection_is_concurrent (void); gboolean sgen_get_concurrent_collection_in_progress (void); -void sgen_set_bytes_allocated_attached (guint64); +void sgen_set_bytes_allocated_attached (guint64 bytes); +void increment_bytes_allocated_detached(guint64 bytes); typedef struct _SgenFragment SgenFragment; @@ -1078,6 +1079,7 @@ typedef enum { void sgen_clear_tlabs (void); void sgen_update_allocation_count (void); +guint64 sgen_get_total_allocated_bytes (MonoBoolean precise); GCObject* sgen_alloc_obj (GCVTable vtable, size_t size) MONO_PERMIT (need (sgen_lock_gc, sgen_stop_world)); -- 2.7.4