Bug 1159967 - Handle logging after threads have shut down, r=janv, a=sylvestre
authorBen Turner <bent.mozilla@gmail.com>
Thu, 30 Apr 2015 11:59:36 -0700
changeset 260353 257a4e9e8236
parent 260352 538fd67bb637
child 260354 27e5c6caa8db
child 260356 9de8328d90ac
child 260357 cadca20b227a
child 260360 19f3cb7674d2
push id761
push usersledru@mozilla.com
push date2015-05-03 17:00 +0000
treeherdermozilla-release@257a4e9e8236 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv, sylvestre
bugs1159967
milestone38.0
Bug 1159967 - Handle logging after threads have shut down, r=janv, a=sylvestre
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/ActorsChild.h
dom/indexedDB/ProfilerHelpers.h
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -66,16 +66,22 @@ ThreadLocal::ThreadLocal(const nsID& aBa
   , mCurrentTransaction(0)
 #ifdef DEBUG
   , mOwningThread(PR_GetCurrentThread())
 #endif
 {
   MOZ_ASSERT(mOwningThread);
 
   MOZ_COUNT_CTOR(mozilla::dom::indexedDB::ThreadLocal);
+
+  // NSID_LENGTH counts the null terminator, SetLength() does not.
+  mLoggingIdString.SetLength(NSID_LENGTH - 1);
+
+  aBackgroundChildLoggingId.ToProvidedString(
+    *reinterpret_cast<char(*)[NSID_LENGTH]>(mLoggingIdString.BeginWriting()));
 }
 
 ThreadLocal::~ThreadLocal()
 {
   MOZ_COUNT_DTOR(mozilla::dom::indexedDB::ThreadLocal);
 }
 
 #ifdef DEBUG
--- a/dom/indexedDB/ActorsChild.h
+++ b/dom/indexedDB/ActorsChild.h
@@ -49,16 +49,17 @@ class SerializedStructuredCloneReadInfo;
 
 class ThreadLocal
 {
   friend class nsAutoPtr<ThreadLocal>;
   friend class IDBFactory;
 
   LoggingInfo mLoggingInfo;
   IDBTransaction* mCurrentTransaction;
+  nsCString mLoggingIdString;
 
 #ifdef DEBUG
   PRThread* mOwningThread;
 #endif
 
 public:
   void
   AssertIsOnOwningThread() const
@@ -79,16 +80,24 @@ public:
   const nsID&
   Id() const
   {
     AssertIsOnOwningThread();
 
     return mLoggingInfo.backgroundChildLoggingId();
   }
 
+  const nsCString&
+  IdString() const
+  {
+    AssertIsOnOwningThread();
+
+    return mLoggingIdString;
+  }
+
   int64_t
   NextTransactionSN(IDBTransaction::Mode aMode)
   {
     AssertIsOnOwningThread();
     MOZ_ASSERT(mLoggingInfo.nextTransactionSerialNumber() < INT64_MAX);
     MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
                  INT64_MIN);
 
--- a/dom/indexedDB/ProfilerHelpers.h
+++ b/dom/indexedDB/ProfilerHelpers.h
@@ -39,44 +39,45 @@ namespace indexedDB {
 class MOZ_STACK_CLASS LoggingIdString final
   : public nsAutoCString
 {
 public:
   LoggingIdString()
   {
     using mozilla::ipc::BackgroundChildImpl;
 
-    BackgroundChildImpl::ThreadLocal* threadLocal =
-      BackgroundChildImpl::GetThreadLocalForCurrentThread();
-    MOZ_ASSERT(threadLocal);
-
-    ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
-    MOZ_ASSERT(idbThreadLocal);
-
-    Init(idbThreadLocal->Id());
+    if (IndexedDatabaseManager::GetLoggingMode() !=
+          IndexedDatabaseManager::Logging_Disabled) {
+      const BackgroundChildImpl::ThreadLocal* threadLocal =
+        BackgroundChildImpl::GetThreadLocalForCurrentThread();
+      if (threadLocal) {
+        const ThreadLocal* idbThreadLocal = threadLocal->mIndexedDBThreadLocal;
+        if (idbThreadLocal) {
+          Assign(idbThreadLocal->IdString());
+        }
+      }
+    }
   }
 
   explicit
   LoggingIdString(const nsID& aID)
   {
-    Init(aID);
-  }
-
-private:
-  void
-  Init(const nsID& aID)
-  {
     static_assert(NSID_LENGTH > 1, "NSID_LENGTH is set incorrectly!");
+    static_assert(NSID_LENGTH <= kDefaultStorageSize,
+                  "nID string won't fit in our storage!");
     MOZ_ASSERT(Capacity() > NSID_LENGTH);
 
-    // NSID_LENGTH counts the null terminator, SetLength() does not.
-    SetLength(NSID_LENGTH - 1);
+    if (IndexedDatabaseManager::GetLoggingMode() !=
+          IndexedDatabaseManager::Logging_Disabled) {
+      // NSID_LENGTH counts the null terminator, SetLength() does not.
+      SetLength(NSID_LENGTH - 1);
 
-    aID.ToProvidedString(
-      *reinterpret_cast<char(*)[NSID_LENGTH]>(BeginWriting()));
+      aID.ToProvidedString(
+        *reinterpret_cast<char(*)[NSID_LENGTH]>(BeginWriting()));
+    }
   }
 };
 
 class MOZ_STACK_CLASS LoggingString final
   : public nsAutoCString
 {
   static const char kQuote = '\"';
   static const char kOpenBracket = '[';