From 5853defbf4d88416f231f430c02962c6853c0b66 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Tue, 12 May 2015 14:06:59 -0700 Subject: [PATCH] [sgen] Register GC handle counters & avoid 64-bit CAS. The GC handle counters were not being registered; probably got lost when rebasing this code atop the independent SGen. This also avoids 64-bit CAS on these counters, so that platforms without it still have stats. --- mono/sgen/sgen-gc.c | 1 + mono/sgen/sgen-gchandles.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mono/sgen/sgen-gc.c b/mono/sgen/sgen-gc.c index 92e965b5d95..59919d0f7f3 100644 --- a/mono/sgen/sgen-gc.c +++ b/mono/sgen/sgen-gc.c @@ -2859,6 +2859,7 @@ sgen_gc_init (void) sgen_init_descriptors (); sgen_init_gray_queues (); sgen_init_allocator (); + sgen_init_gchandles (); sgen_register_fixed_internal_mem_type (INTERNAL_MEM_SECTION, SGEN_SIZEOF_GC_MEM_SECTION); sgen_register_fixed_internal_mem_type (INTERNAL_MEM_GRAY_QUEUE, sizeof (GrayQueueSection)); diff --git a/mono/sgen/sgen-gchandles.c b/mono/sgen/sgen-gchandles.c index 8e96c718dd3..367c2c32604 100644 --- a/mono/sgen/sgen-gchandles.c +++ b/mono/sgen/sgen-gchandles.c @@ -25,8 +25,8 @@ #include "mono/utils/mono-membar.h" #ifdef HEAVY_STATISTICS -static volatile guint64 stat_gc_handles_allocated = 0; -static volatile guint64 stat_gc_handles_max_allocated = 0; +static volatile guint32 stat_gc_handles_allocated = 0; +static volatile guint32 stat_gc_handles_max_allocated = 0; #endif #define BUCKETS (32 - MONO_GC_HANDLE_TYPE_SHIFT) @@ -274,7 +274,7 @@ retry: break; } while (!InterlockedCompareExchange ((volatile gint32 *)&handles->max_index, index, max_index)); #ifdef HEAVY_STATISTICS - InterlockedIncrement64 ((volatile gint64 *)&stat_gc_handles_allocated); + InterlockedIncrement ((volatile gint32 *)&stat_gc_handles_allocated); if (stat_gc_handles_allocated > stat_gc_handles_max_allocated) stat_gc_handles_max_allocated = stat_gc_handles_allocated; #endif @@ -326,7 +326,7 @@ sgen_gchandle_iterate (GCHandleType handle_type, int max_generation, SgenGCHandl if (result) SGEN_ASSERT (0, MONO_GC_HANDLE_OCCUPIED (result), "Why did the callback return an unoccupied entry?"); else - HEAVY_STAT (InterlockedDecrement64 ((volatile gint64 *)&stat_gc_handles_allocated)); + HEAVY_STAT (InterlockedDecrement ((volatile gint32 *)&stat_gc_handles_allocated)); protocol_gchandle_update (handle_type, (gpointer)&entries [offset], hidden, result); entries [offset] = result; } @@ -527,7 +527,7 @@ mono_gchandle_free (guint32 gchandle) if (index < handles->capacity && MONO_GC_HANDLE_OCCUPIED (slot)) { handles->entries [bucket] [offset] = NULL; protocol_gchandle_update (handles->type, (gpointer)&handles->entries [bucket] [offset], slot, NULL); - HEAVY_STAT (InterlockedDecrement64 ((volatile gint64 *)&stat_gc_handles_allocated)); + HEAVY_STAT (InterlockedDecrement ((volatile gint32 *)&stat_gc_handles_allocated)); } else { /* print a warning? */ } @@ -613,8 +613,8 @@ void sgen_init_gchandles (void) { #ifdef HEAVY_STATISTICS - mono_counters_register ("GC handles allocated", MONO_COUNTER_GC | MONO_COUNTER_ULONG, &stat_gc_handles_allocated); - mono_counters_register ("max GC handles allocated", MONO_COUNTER_GC | MONO_COUNTER_ULONG, &stat_gc_handles_max_allocated); + mono_counters_register ("GC handles allocated", MONO_COUNTER_GC | MONO_COUNTER_UINT, (void *)&stat_gc_handles_allocated); + mono_counters_register ("max GC handles allocated", MONO_COUNTER_GC | MONO_COUNTER_UINT, (void *)&stat_gc_handles_max_allocated); #endif } -- 2.25.1