Bug 1279614 - 2,000 instances of "XPCOM objects created/destroyed from static ctor/dtor" emitted from xpcom/base/nsTraceRefcnt.cpp during linux64 debug testing. r=gfritzsche,jmathies.
authorJulian Seward <jseward@acm.org>
Thu, 30 Jun 2016 14:04:15 +0200
changeset 303303 da77b49e469af87a4573eba9d5c16b5907733bed
parent 303302 ff6f8a26f7b7327b0f969f4c8d0c4bac7e6d2fc4
child 303304 61bc9a864653e76dcf4a18a0aae929a3f15aa9c7
push id19839
push usercbook@mozilla.com
push dateFri, 01 Jul 2016 09:19:59 +0000
treeherderfx-team@499d8875de7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, jmathies
bugs1279614
milestone50.0a1
Bug 1279614 - 2,000 instances of "XPCOM objects created/destroyed from static ctor/dtor" emitted from xpcom/base/nsTraceRefcnt.cpp during linux64 debug testing. r=gfritzsche,jmathies.
toolkit/components/telemetry/TelemetryHistogram.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -160,18 +160,18 @@ typedef AutoHashtable<AddonEntryType> Ad
 //
 // PRIVATE STATE, SHARED BY ALL THREADS
 
 namespace {
 
 // Set to true once this global state has been initialized
 bool gInitDone = false;
 
-bool gCanRecordBase;
-bool gCanRecordExtended;
+bool gCanRecordBase = false;
+bool gCanRecordExtended = false;
 
 HistogramMapType gHistogramMap(mozilla::Telemetry::HistogramCount);
 
 KeyedHistogramMapType gKeyedHistograms;
 
 bool gCorruptHistograms[mozilla::Telemetry::HistogramCount];
 
 // This is for gHistograms, gHistogramStringTable
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4415,26 +4415,45 @@ void XRE_GlibInit()
     // g_type_init (2.32 <= gLib version < 2.36)."
     g_thread_init(nullptr);
     g_type_init();
     ran_once = true;
   }
 }
 #endif
 
+// Separate stub function to let us specifically suppress it in Valgrind
+void
+XRE_CreateStatsObject()
+{
+  // Initialize global variables used by histogram collection
+  // machinery that is used by by Telemetry.  Note: is never de-initialised.
+  Telemetry::CreateStatisticsRecorder();
+}
+
 /*
  * XRE_main - A class based main entry point used by most platforms.
  *            Note that on OSX, aAppData->xreDirectory will point to
  *            .app/Contents/Resources.
  */
 int
 XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
 {
   ScopedLogging log;
 
+  // NB: this must happen after the creation of |ScopedLogging log| since
+  // ScopedLogging::ScopedLogging calls NS_LogInit, and
+  // XRE_CreateStatsObject calls Telemetry::CreateStatisticsRecorder,
+  // and NS_LogInit must be called before Telemetry::CreateStatisticsRecorder.
+  // NS_LogInit must be called before Telemetry::CreateStatisticsRecorder
+  // so as to avoid many log messages of the form
+  //   WARNING: XPCOM objects created/destroyed from static ctor/dtor: [..]
+  // See bug 1279614.
+  XRE_CreateStatsObject();
+
 #if defined(MOZ_SANDBOX) && defined(XP_LINUX) && !defined(ANDROID)
   SandboxInfo::ThreadingCheck();
 #endif
 
   char aLocal;
   GeckoProfilerInitRAII profilerGuard(&aLocal);
 
   PROFILER_LABEL("Startup", "XRE_Main",
@@ -4576,31 +4595,21 @@ XREMain::XRE_main(int argc, char* argv[]
   return NS_FAILED(rv) ? 1 : 0;
 }
 
 void
 XRE_StopLateWriteChecks(void) {
   mozilla::StopLateWriteChecks();
 }
 
-// Separate stub function to let us specifically suppress it in Valgrind
-void
-XRE_CreateStatsObject()
-{
-  // Initialize global variables used by histogram collection
-  // machinery that is used by by Telemetry.  Note: is never de-initialised.
-  Telemetry::CreateStatisticsRecorder();
-}
-
 int
 XRE_main(int argc, char* argv[], const nsXREAppData* aAppData, uint32_t aFlags)
 {
   XREMain main;
 
-  XRE_CreateStatsObject();
   int result = main.XRE_main(argc, argv, aAppData);
   mozilla::RecordShutdownEndTimeStamp();
   return result;
 }
 
 nsresult
 XRE_InitCommandLine(int aArgc, char* aArgv[])
 {
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -312,19 +312,16 @@ XRE_InitChildProcess(int aArgc,
   DllBlocklist_Initialize();
 #endif
 
 #ifdef MOZ_JPROF
   // Call the code to install our handler
   setupProfilingStuff();
 #endif
 
-  // This is needed by Telemetry to initialize histogram collection.
-  Telemetry::CreateStatisticsRecorder();
-
 #if !defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_GONK)
   // On non-Fennec Gecko, the GMPLoader code resides in plugin-container,
   // and we must forward it through to the GMP code here.
   GMPProcessChild::SetGMPLoader(aChildData->gmpLoader.get());
 #else
   // On Fennec, the GMPLoader's code resides inside XUL (because for the time
   // being GMPLoader relies upon NSPR, which we can't use in plugin-container
   // on Android), so we create it here inside XUL and pass it to the GMP code.
@@ -360,16 +357,24 @@ XRE_InitChildProcess(int aArgc,
     SandboxTarget::Instance()->SetTargetServices(aChildData->sandboxTargetServices);
   }
 #endif
 #endif
 
   // NB: This must be called before profiler_init
   NS_LogInit();
 
+  // This is needed by Telemetry to initialize histogram collection.
+  // NB: This must be called after NS_LogInit().
+  // NS_LogInit must be called before Telemetry::CreateStatisticsRecorder
+  // so as to avoid many log messages of the form
+  //   WARNING: XPCOM objects created/destroyed from static ctor/dtor: [..]
+  // See bug 1279614.
+  Telemetry::CreateStatisticsRecorder();
+
   mozilla::LogModule::Init();
 
   char aLocal;
   profiler_init(&aLocal);
 
   PROFILER_LABEL("Startup", "XRE_InitChildProcess",
     js::ProfileEntry::Category::OTHER);