Bug 1341255 - Profiler tidyups: remove StackEntry, rename ProfileEntry to ProfileBufferEntry (part 1: remove StackEntry). r=n.nethercote.
authorJulian Seward <jseward@acm.org>
Thu, 23 Feb 2017 23:04:13 +0100
changeset 373704 5cb0e7cf804be7479edfd75b3cbffd9179691b53
parent 373703 5fc0af6d26ce88ebb456d55e80a7f24f66fc6d87
child 373705 6ef5dd99b45cf4b556e7204ba29c6446f550702a
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersn
bugs1341255
milestone54.0a1
Bug 1341255 - Profiler tidyups: remove StackEntry, rename ProfileEntry to ProfileBufferEntry (part 1: remove StackEntry). r=n.nethercote.
tools/profiler/core/platform.cpp
tools/profiler/public/PseudoStack.h
xpcom/threads/ThreadStackHelper.cpp
xpcom/threads/ThreadStackHelper.h
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -246,22 +246,22 @@ AddDynamicCodeLocationTag(ThreadInfo& aI
     j += sizeof(void*) / sizeof(char);
 
     // Cast to *((void**) to pass the text data to a void*.
     aInfo.addTag(ProfileEntry::EmbeddedString(*((void**)(&text[0]))));
   }
 }
 
 static void
-AddPseudoEntry(volatile StackEntry& entry, ThreadInfo& aInfo,
+AddPseudoEntry(volatile js::ProfileEntry& entry, ThreadInfo& aInfo,
                PseudoStack* stack, void* lastpc)
 {
   // Pseudo-frames with the BEGIN_PSEUDO_JS flag are just annotations and
   // should not be recorded in the profile.
-  if (entry.hasFlag(StackEntry::BEGIN_PSEUDO_JS)) {
+  if (entry.hasFlag(js::ProfileEntry::BEGIN_PSEUDO_JS)) {
     return;
   }
 
   int lineno = -1;
 
   // First entry has kind CodeLocation. Check for magic pointer bit 1 to
   // indicate copy.
   const char* sampleLabel = entry.label();
@@ -302,18 +302,18 @@ AddPseudoEntry(volatile StackEntry& entr
     }
   }
 
   if (lineno != -1) {
     aInfo.addTag(ProfileEntry::LineNumber(lineno));
   }
 
   uint32_t category = entry.category();
-  MOZ_ASSERT(!(category & StackEntry::IS_CPP_ENTRY));
-  MOZ_ASSERT(!(category & StackEntry::FRAME_LABEL_COPY));
+  MOZ_ASSERT(!(category & js::ProfileEntry::IS_CPP_ENTRY));
+  MOZ_ASSERT(!(category & js::ProfileEntry::FRAME_LABEL_COPY));
 
   if (category) {
     aInfo.addTag(ProfileEntry::Category((int)category));
   }
 }
 
 struct NativeStack
 {
@@ -340,17 +340,17 @@ struct AutoWalkJSStack
   }
 };
 
 static void
 MergeStacksIntoProfile(ThreadInfo& aInfo, TickSample* aSample,
                        NativeStack& aNativeStack)
 {
   PseudoStack* pseudoStack = aInfo.Stack();
-  volatile StackEntry* pseudoFrames = pseudoStack->mStack;
+  volatile js::ProfileEntry* pseudoFrames = pseudoStack->mStack;
   uint32_t pseudoCount = pseudoStack->stackSize();
 
   // Make a copy of the JS stack into a JSFrame array. This is necessary since,
   // like the native stack, the JS stack is iterated youngest-to-oldest and we
   // need to iterate oldest-to-youngest when adding entries to aInfo.
 
   // Synchronous sampling reports an invalid buffer generation to
   // ProfilingFrameIterator to avoid incorrectly resetting the generation of
@@ -415,17 +415,17 @@ MergeStacksIntoProfile(ThreadInfo& aInfo
   // Iterate as long as there is at least one frame remaining.
   while (pseudoIndex != pseudoCount || jsIndex >= 0 || nativeIndex >= 0) {
     // There are 1 to 3 frames available. Find and add the oldest.
     uint8_t* pseudoStackAddr = nullptr;
     uint8_t* jsStackAddr = nullptr;
     uint8_t* nativeStackAddr = nullptr;
 
     if (pseudoIndex != pseudoCount) {
-      volatile StackEntry& pseudoFrame = pseudoFrames[pseudoIndex];
+      volatile js::ProfileEntry& pseudoFrame = pseudoFrames[pseudoIndex];
 
       if (pseudoFrame.isCpp()) {
         lastPseudoCppStackAddr = (uint8_t*) pseudoFrame.stackAddress();
       }
 
       // Skip any pseudo-stack JS frames which are marked isOSR. Pseudostack
       // frames are marked isOSR when the JS interpreter enters a jit frame on
       // a loop edge (via on-stack-replacement, or OSR). To avoid both the
@@ -466,17 +466,17 @@ MergeStacksIntoProfile(ThreadInfo& aInfo
     MOZ_ASSERT_IF(jsStackAddr, jsStackAddr != pseudoStackAddr &&
                                jsStackAddr != nativeStackAddr);
     MOZ_ASSERT_IF(nativeStackAddr, nativeStackAddr != pseudoStackAddr &&
                                    nativeStackAddr != jsStackAddr);
 
     // Check to see if pseudoStack frame is top-most.
     if (pseudoStackAddr > jsStackAddr && pseudoStackAddr > nativeStackAddr) {
       MOZ_ASSERT(pseudoIndex < pseudoCount);
-      volatile StackEntry& pseudoFrame = pseudoFrames[pseudoIndex];
+      volatile js::ProfileEntry& pseudoFrame = pseudoFrames[pseudoIndex];
       AddPseudoEntry(pseudoFrame, aInfo, pseudoStack, nullptr);
       pseudoIndex++;
       continue;
     }
 
     // Check to see if JS jit stack frame is top-most
     if (jsStackAddr > nativeStackAddr) {
       MOZ_ASSERT(jsIndex >= 0);
@@ -611,17 +611,17 @@ DoNativeBacktrace(ThreadInfo& aInfo, Tic
 
   // The pseudostack contains an "EnterJIT" frame whenever we enter
   // JIT code with profiling enabled; the stack pointer value points
   // the saved registers.  We use this to unwind resume unwinding
   // after encounting JIT code.
   for (uint32_t i = pseudoStack->stackSize(); i > 0; --i) {
     // The pseudostack grows towards higher indices, so we iterate
     // backwards (from callee to caller).
-    volatile StackEntry& entry = pseudoStack->mStack[i - 1];
+    volatile js::ProfileEntry& entry = pseudoStack->mStack[i - 1];
     if (!entry.isJs() && strcmp(entry.label(), "EnterJIT") == 0) {
       // Found JIT entry frame.  Unwind up to that point (i.e., force
       // the stack walk to stop before the block of saved registers;
       // note that it yields nondecreasing stack pointers), then restore
       // the saved state.
       uint32_t* vSP = reinterpret_cast<uint32_t*>(entry.stackAddress());
 
       nativeStack.count += EHABIStackWalk(*mcontext,
@@ -2481,17 +2481,17 @@ profiler_get_backtrace_noalloc(char *out
   MOZ_ASSERT(outputSize >= 2);
   char *bound = output + outputSize - 2;
   output[0] = output[1] = '\0';
   PseudoStack *pseudoStack = tlsPseudoStack.get();
   if (!pseudoStack) {
     return;
   }
 
-  volatile StackEntry *pseudoFrames = pseudoStack->mStack;
+  volatile js::ProfileEntry *pseudoFrames = pseudoStack->mStack;
   uint32_t pseudoCount = pseudoStack->stackSize();
 
   for (uint32_t i = 0; i < pseudoCount; i++) {
     size_t len = strlen(pseudoFrames[i].label());
     if (output + len >= bound)
       break;
     strcpy(output, pseudoFrames[i].label());
     output += len;
--- a/tools/profiler/public/PseudoStack.h
+++ b/tools/profiler/public/PseudoStack.h
@@ -44,28 +44,16 @@ LinuxKernelMemoryBarrierFunc pLinuxKerne
 # else
 #  error "Memory clobber not supported for your compiler."
 # endif
 
 #else
 # error "Memory clobber not supported for your platform."
 #endif
 
-// A stack entry exists to allow the JS engine to inform the Gecko Profiler of
-// the current backtrace, but also to instrument particular points in C++ in
-// case stack walking is not available on the platform we are running on.
-//
-// Each entry has a descriptive string, a relevant stack address, and some extra
-// information the JS engine might want to inform the Gecko Profiler of. This
-// class inherits from the JS engine's version of the entry to ensure that the
-// size and layout of the two representations are consistent.
-class StackEntry : public js::ProfileEntry
-{
-};
-
 class ProfilerMarkerPayload;
 template<typename T>
 class ProfilerLinkedList;
 class SpliceableJSONWriter;
 class UniqueStacks;
 
 class ProfilerMarker
 {
@@ -268,17 +256,17 @@ public:
   void push(const char* aName, js::ProfileEntry::Category aCategory,
             void* aStackAddress, bool aCopy, uint32_t line)
   {
     if (size_t(mStackPointer) >= mozilla::ArrayLength(mStack)) {
       mStackPointer++;
       return;
     }
 
-    volatile StackEntry& entry = mStack[mStackPointer];
+    volatile js::ProfileEntry& entry = mStack[mStackPointer];
 
     // Make sure we increment the pointer after the name has been written such
     // that mStack is always consistent.
     entry.initCppFrame(aStackAddress, line);
     entry.setLabel(aName);
     MOZ_ASSERT(entry.flags() == js::ProfileEntry::IS_CPP_ENTRY);
     entry.setCategory(aCategory);
 
@@ -407,17 +395,17 @@ private:
   // No copying.
   PseudoStack(const PseudoStack&) = delete;
   void operator=(const PseudoStack&) = delete;
 
   void flushSamplerOnJSShutdown();
 
 public:
   // The list of active checkpoints.
-  StackEntry volatile mStack[1024];
+  js::ProfileEntry volatile mStack[1024];
 
 private:
   // A list of pending markers that must be moved to the circular buffer.
   ProfilerSignalSafeLinkedList<ProfilerMarker> mPendingMarkers;
 
   // This may exceed the length of mStack, so instead use the stackSize() method
   // to determine the number of valid samples in mStack.
   mozilla::sig_safe_t mStackPointer;
--- a/xpcom/threads/ThreadStackHelper.cpp
+++ b/xpcom/threads/ThreadStackHelper.cpp
@@ -421,17 +421,17 @@ GetPathAfterComponent(const char* filena
     next = strstr(found - 1, component);
   }
   return found;
 }
 
 } // namespace
 
 const char*
-ThreadStackHelper::AppendJSEntry(const volatile StackEntry* aEntry,
+ThreadStackHelper::AppendJSEntry(const volatile js::ProfileEntry* aEntry,
                                  intptr_t& aAvailableBufferSize,
                                  const char* aPrevLabel)
 {
   // May be called from another thread or inside a signal handler.
   // We assume querying the script is safe but we must not manupulate it.
   // Also we must not allocate any memory from heap.
   MOZ_ASSERT(aEntry->isJs());
 
@@ -508,18 +508,18 @@ ThreadStackHelper::FillStackBuffer()
   MOZ_ASSERT(mStackToFill->empty());
 
 #ifdef MOZ_THREADSTACKHELPER_PSEUDO
   size_t reservedSize = mStackToFill->capacity();
   size_t reservedBufferSize = mStackToFill->AvailableBufferSize();
   intptr_t availableBufferSize = intptr_t(reservedBufferSize);
 
   // Go from front to back
-  const volatile StackEntry* entry = mPseudoStack->mStack;
-  const volatile StackEntry* end = entry + mPseudoStack->stackSize();
+  const volatile js::ProfileEntry* entry = mPseudoStack->mStack;
+  const volatile js::ProfileEntry* end = entry + mPseudoStack->stackSize();
   // Deduplicate identical, consecutive frames
   const char* prevLabel = nullptr;
   for (; reservedSize-- && entry != end; entry++) {
     /* We only accept non-copy labels, including js::RunScript,
        because we only want static labels in the hang stack. */
     if (entry->isCopyLabel()) {
       continue;
     }
--- a/xpcom/threads/ThreadStackHelper.h
+++ b/xpcom/threads/ThreadStackHelper.h
@@ -3,18 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ThreadStackHelper_h
 #define mozilla_ThreadStackHelper_h
 
 #include "mozilla/ThreadHangStats.h"
-
-#include "GeckoProfiler.h"
+#include "js/ProfilingStack.h"
 
 #include <stddef.h>
 
 #if defined(XP_LINUX)
 #include <signal.h>
 #include <semaphore.h>
 #include <sys/types.h>
 #elif defined(XP_WIN)
@@ -74,17 +73,17 @@ private:
   size_t mMaxStackSize;
   size_t mMaxBufferSize;
 #endif
 
   bool PrepareStackBuffer(Stack& aStack);
   void FillStackBuffer();
   void FillThreadContext(void* aContext = nullptr);
 #ifdef MOZ_THREADSTACKHELPER_PSEUDO
-  const char* AppendJSEntry(const volatile StackEntry* aEntry,
+  const char* AppendJSEntry(const volatile js::ProfileEntry* aEntry,
                             intptr_t& aAvailableBufferSize,
                             const char* aPrevLabel);
 #endif
 #ifdef MOZ_THREADSTACKHELPER_NATIVE
   void GetThreadStackBase();
 #endif
 
 public: