Bug 1436768 - Add debug code to LazyLogModule. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Wed, 09 May 2018 11:16:27 -0700
changeset 421443 0014f483953e0066b86796da1d6512214c5be737
parent 421442 91323a17cfa214729ada294f3e974e4cff3f25fb
child 421444 189125be1c9baddeb257771511acaeccc6c4dcb7
push id34093
push useraiakab@mozilla.com
push dateTue, 05 Jun 2018 21:58:58 +0000
treeherdermozilla-central@da28b92efe6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1436768
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1436768 - Add debug code to LazyLogModule. r=froydnj
mfbt/Poison.h
xpcom/base/Logging.cpp
xpcom/base/Logging.h
--- a/mfbt/Poison.h
+++ b/mfbt/Poison.h
@@ -76,18 +76,19 @@ namespace mozilla {
  * so enables us to narrow down the location where the corruption is occurring.
  * A pleasant side-effect of these additional Check() calls is that crash
  * signatures may become more regular, as crashes will ideally occur
  * consolidated at the point of a Check(), rather than scattered about at
  * various uses of the corrupted memory.
  */
 class CorruptionCanary {
 public:
-  CorruptionCanary() {
-    mValue = kCanarySet;
+  constexpr CorruptionCanary()
+    : mValue(kCanarySet)
+  {
   }
 
   ~CorruptionCanary() {
     Check();
     mValue = mozPoisonValue();
   }
 
   void Check() const {
--- a/xpcom/base/Logging.cpp
+++ b/xpcom/base/Logging.cpp
@@ -51,16 +51,18 @@ LazyLogModule::operator LogModule*()
   //     than once, but that's okay as it will be set to the same LogModule
   //     instance each time. Also note LogModule::Get is thread-safe.
   LogModule* tmp = mLog;
   if (MOZ_UNLIKELY(!tmp)) {
     tmp = LogModule::Get(mLogName);
     mLog = tmp;
   }
 
+  mCanary.Check();
+
   return tmp;
 }
 
 namespace detail {
 
 void log_print(const LogModule* aModule,
                LogLevel aLevel,
                const char* aFmt, ...)
--- a/xpcom/base/Logging.h
+++ b/xpcom/base/Logging.h
@@ -9,16 +9,17 @@
 
 #include <string.h>
 #include <stdarg.h>
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Likely.h"
+#include "mozilla/Poison.h"
 
 // We normally have logging enabled everywhere, but measurements showed that
 // having logging enabled on Android is quite expensive (hundreds of kilobytes
 // for both the format strings for logging and the code to perform all the
 // logging calls).  Because retrieving logs from a mobile device is
 // comparatively more difficult for Android than it is for desktop and because
 // desktop machines tend to be less space/bandwidth-constrained than Android
 // devices, we've chosen to leave logging enabled on desktop, but disabled on
@@ -169,16 +170,17 @@ public:
     , mLog(nullptr)
   {
   }
 
   operator LogModule*();
 
 private:
   const char* const mLogName;
+  CorruptionCanary mCanary;
   Atomic<LogModule*, ReleaseAcquire> mLog;
 };
 
 namespace detail {
 
 inline bool log_test(const LogModule* module, LogLevel level) {
   MOZ_ASSERT(level != LogLevel::Disabled);
   return module && module->ShouldLog(level);