Resolve "you are registering twice the same counter address" warning on Windows Relea...
authorlateralusX <lateralusx.github@gmail.com>
Tue, 20 Sep 2016 15:07:02 +0000 (17:07 +0200)
committerlateralusX <lateralusx.github@gmail.com>
Tue, 20 Sep 2016 15:07:02 +0000 (17:07 +0200)
When registering profile counters on optimized Windows build you will get the following logging twice:

"you are registering twice the same counter address"

This happens since the optimizer will collapse cpu_load_1min, cpu_load_5min and cpu_load15min into
the same function on optimized Windows builds and that is not expected by register_internal.

By preventing inlining of cpu_load we can keep the different callback methods unique and optimizer
won't fold them into one single representation in the final binary.

mono/utils/mono-counters.c

index ae33b4a9f39336cb31f1c31f31d43ee7e4d497ed..f867960803ba46f7c81f828b8a4e56fc614fd382 100644 (file)
@@ -347,6 +347,13 @@ page_faults (void)
        return mono_process_get_data (GINT_TO_POINTER (mono_process_current_pid ()), MONO_PROCESS_FAULTS);
 }
 
+
+// If cpu_load gets inlined on Windows then cpu_load_1min, cpu_load_5min and cpu_load_15min can be folded into a single function and that will
+// cause a failure when registering counters since the same function address will be used by all three functions. Preventing this method from being inlined
+// will make sure the registered callback functions remains unique.
+#ifdef _MSC_VER
+__declspec(noinline)
+#endif
 static double
 cpu_load (int kind)
 {