Bug 1023461 - Remove temporary stack buffer in ThreadStackHelper; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 20 Jun 2014 14:28:10 -0400
changeset 211800 c03a1baf9f47d480d42e3065736247a8bd20ec5a
parent 211799 bb4422ab5f084d2c6d7f2a18d033446819698dd4
child 211801 5cc1bec060f9ef4ab0ee8d07dfc3a1d781ff0345
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1023461
milestone33.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 1023461 - Remove temporary stack buffer in ThreadStackHelper; r=snorp
xpcom/threads/ThreadStackHelper.cpp
xpcom/threads/ThreadStackHelper.h
--- a/xpcom/threads/ThreadStackHelper.cpp
+++ b/xpcom/threads/ThreadStackHelper.cpp
@@ -52,18 +52,18 @@ ThreadStackHelper::Shutdown()
 #endif
 }
 
 ThreadStackHelper::ThreadStackHelper()
   :
 #ifdef MOZ_ENABLE_PROFILER_SPS
     mPseudoStack(mozilla_get_pseudo_stack()),
 #endif
-    mStackBuffer()
-  , mMaxStackSize(mStackBuffer.capacity())
+    mStackToFill(nullptr)
+  , mMaxStackSize(Stack::sMaxInlineStorage)
 {
 #if defined(XP_LINUX)
   mThreadID = ::syscall(SYS_gettid);
 #elif defined(XP_WIN)
   mInitialized = !!::DuplicateHandle(
     ::GetCurrentProcess(), ::GetCurrentThread(),
     ::GetCurrentProcess(), &mThreadID,
     THREAD_SUSPEND_RESUME, FALSE, 0);
@@ -160,17 +160,16 @@ ThreadStackHelper::GetStack(Stack& aStac
   if (::thread_suspend(mThreadID) != KERN_SUCCESS) {
     MOZ_ASSERT(false);
     return;
   }
   FillStackBuffer();
   MOZ_ALWAYS_TRUE(::thread_resume(mThreadID) == KERN_SUCCESS);
 
 #endif
-  aStack = Move(mStackBuffer);
 }
 
 #ifdef XP_LINUX
 
 int ThreadStackHelper::sInitialized;
 sem_t ThreadStackHelper::sSem;
 struct sigaction ThreadStackHelper::sOldSigAction;
 ThreadStackHelper* ThreadStackHelper::sCurrent;
@@ -198,18 +197,18 @@ ThreadStackHelper::PrepareStackBuffer(St
      may be disabled despite profiler being enabled. This is by-design and
      is not an error. */
 #ifdef MOZ_WIDGET_GONK
   if (!mPseudoStack) {
     return false;
   }
 #endif
   MOZ_ASSERT(mPseudoStack);
-  mStackBuffer.clear();
-  MOZ_ALWAYS_TRUE(mStackBuffer.reserve(mMaxStackSize));
+  MOZ_ALWAYS_TRUE(aStack.reserve(mMaxStackSize));
+  mStackToFill = &aStack;
   return true;
 #else
   return false;
 #endif
 }
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
 
@@ -245,17 +244,17 @@ ThreadStackHelper::AppendJSEntry(const v
     label = "(chrome script)";
   } else {
     label = "(content script)";
   }
 
   if (label == aPrevLabel) {
     return aPrevLabel;
   }
-  mStackBuffer.infallibleAppend(label);
+  mStackToFill->infallibleAppend(label);
   return label;
 }
 
 #endif // MOZ_ENABLE_PROFILER_SPS
 
 void
 ThreadStackHelper::FillStackBuffer()
 {
@@ -276,17 +275,17 @@ ThreadStackHelper::FillStackBuffer()
     if (entry->isJs()) {
       prevLabel = AppendJSEntry(entry, prevLabel);
       continue;
     }
     const char* const label = entry->label();
     if (label == prevLabel) {
       continue;
     }
-    mStackBuffer.infallibleAppend(label);
+    mStackToFill->infallibleAppend(label);
     prevLabel = label;
   }
   // If we exited early due to buffer size, expand the buffer for next time
   mMaxStackSize += (end - entry);
 #endif
 }
 
 } // namespace mozilla
--- a/xpcom/threads/ThreadStackHelper.h
+++ b/xpcom/threads/ThreadStackHelper.h
@@ -38,17 +38,17 @@ class ThreadStackHelper
 {
 public:
   typedef Telemetry::HangHistogram::Stack Stack;
 
 private:
 #ifdef MOZ_ENABLE_PROFILER_SPS
   const PseudoStack* const mPseudoStack;
 #endif
-  Stack mStackBuffer;
+  Stack* mStackToFill;
   size_t mMaxStackSize;
 
   bool PrepareStackBuffer(Stack& aStack);
   void FillStackBuffer();
 #ifdef MOZ_ENABLE_PROFILER_SPS
   const char* AppendJSEntry(const volatile StackEntry* aEntry,
                             const char* aPrevLabel);
 #endif