From 731eb09566f72f5f93ede957c52ca05192dfdbaf Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 30 Jun 2016 14:04:15 +0200 Subject: [PATCH] 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. --- .../telemetry/TelemetryHistogram.cpp | 4 +-- toolkit/xre/nsAppRunner.cpp | 29 ++++++++++++------- toolkit/xre/nsEmbedFunctions.cpp | 11 +++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/toolkit/components/telemetry/TelemetryHistogram.cpp b/toolkit/components/telemetry/TelemetryHistogram.cpp index 4a70593e24c7..12f8f0d19114 100644 --- a/toolkit/components/telemetry/TelemetryHistogram.cpp +++ b/toolkit/components/telemetry/TelemetryHistogram.cpp @@ -165,8 +165,8 @@ 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); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 6bf1445c4a5e..3a74c86ca461 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -4420,6 +4420,15 @@ void XRE_GlibInit() } #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 @@ -4430,6 +4439,16 @@ 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 @@ -4581,21 +4600,11 @@ 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; diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp index ee7039b6a4f3..f63b5e9d3879 100644 --- a/toolkit/xre/nsEmbedFunctions.cpp +++ b/toolkit/xre/nsEmbedFunctions.cpp @@ -317,9 +317,6 @@ XRE_InitChildProcess(int aArgc, 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. @@ -365,6 +362,14 @@ XRE_InitChildProcess(int aArgc, // 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;