Bug 1358074 (part 4) - Rename PS::{Mutex,AutoLock,LockRef} as PS{Mutex,AutoLock,LockRef}. r=mstange.
☠☠ backed out by 265931fd5e5a ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 21 Apr 2017 13:27:53 +1000
changeset 567055 3221b215b080881d3a31b4b6464e3a529bb4d5d4
parent 567054 adec21069065815d50cc16dba70bec4cd7cfefc8
child 567056 1d214f8ac8fdf99766b975ad6e9c20d82c61900b
push id55429
push userbmo:hskupin@gmail.com
push dateMon, 24 Apr 2017 10:48:57 +0000
reviewersmstange
bugs1358074
milestone55.0a1
Bug 1358074 (part 4) - Rename PS::{Mutex,AutoLock,LockRef} as PS{Mutex,AutoLock,LockRef}. r=mstange. A subsequent patch is going to split PS into two classes, and both classes will need access to these types. So this patch moves them to the top level.
tools/profiler/core/platform-linux-android.cpp
tools/profiler/core/platform-macos.cpp
tools/profiler/core/platform-win32.cpp
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform-linux-android.cpp
+++ b/tools/profiler/core/platform-linux-android.cpp
@@ -274,17 +274,17 @@ ThreadEntry(void* aArg)
 {
   auto thread = static_cast<SamplerThread*>(aArg);
   prctl(PR_SET_NAME, "SamplerThread", 0, 0, 0);
   thread->mSamplerTid = gettid();
   thread->Run();
   return nullptr;
 }
 
-SamplerThread::SamplerThread(PS::LockRef aLock, uint32_t aActivityGeneration,
+SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
                              double aIntervalMilliseconds)
   : mActivityGeneration(aActivityGeneration)
   , mIntervalMicroseconds(
       std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5))))
   , mMyPid(getpid())
   // We don't know what the sampler thread's ID will be until it runs, so set
   // mSamplerTid to a dummy value and fill it in for real in ThreadEntry().
   , mSamplerTid(-1)
@@ -338,30 +338,30 @@ SamplerThread::SamplerThread(PS::LockRef
 }
 
 SamplerThread::~SamplerThread()
 {
   pthread_join(mThread, nullptr);
 }
 
 void
-SamplerThread::Stop(PS::LockRef aLock)
+SamplerThread::Stop(PSLockRef aLock)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   // Restore old signal handler. This is global state so it's important that
   // we do it now, while gPSMutex is locked. It's safe to do this now even
   // though this SamplerThread is still alive, because the next time the main
   // loop of Run() iterates it won't get past the mActivityGeneration check,
   // and so won't send any signals.
   sigaction(SIGPROF, &mOldSigprofHandler, 0);
 }
 
 void
-SamplerThread::SuspendAndSampleAndResumeThread(PS::LockRef aLock,
+SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
                                                TickSample& aSample)
 {
   // Only one sampler thread can be sampling at once.  So we expect to have
   // complete control over |sSigHandlerCoordinator|.
   MOZ_ASSERT(!sSigHandlerCoordinator);
 
   int sampleeTid = aSample.mThreadId;
   MOZ_RELEASE_ASSERT(sampleeTid != mSamplerTid);
@@ -461,47 +461,47 @@ SamplerThread::SuspendAndSampleAndResume
 // In the parent, before the fork, record IsPaused, and then pause.
 static void
 paf_prepare()
 {
   // This function can run off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   gPS->SetWasPaused(lock, gPS->IsPaused(lock));
   gPS->SetIsPaused(lock, true);
 }
 
 // In the parent, after the fork, return IsPaused to the pre-fork state.
 static void
 paf_parent()
 {
   // This function can run off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   gPS->SetIsPaused(lock, gPS->WasPaused(lock));
   gPS->SetWasPaused(lock, false);
 }
 
 static void
-PlatformInit(PS::LockRef aLock)
+PlatformInit(PSLockRef aLock)
 {
   // Set up the fork handlers.
   pthread_atfork(paf_prepare, paf_parent, nullptr);
 }
 
 #else
 
 static void
-PlatformInit(PS::LockRef aLock)
+PlatformInit(PSLockRef aLock)
 {
 }
 
 #endif
 
 void
 TickSample::PopulateContext(ucontext_t* aContext)
 {
--- a/tools/profiler/core/platform-macos.cpp
+++ b/tools/profiler/core/platform-macos.cpp
@@ -96,17 +96,17 @@ static void*
 ThreadEntry(void* aArg)
 {
   auto thread = static_cast<SamplerThread*>(aArg);
   SetThreadName();
   thread->Run();
   return nullptr;
 }
 
-SamplerThread::SamplerThread(PS::LockRef aLock, uint32_t aActivityGeneration,
+SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
                              double aIntervalMilliseconds)
   : mActivityGeneration(aActivityGeneration)
   , mIntervalMicroseconds(
       std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5))))
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   pthread_attr_t* attr_ptr = nullptr;
@@ -116,23 +116,23 @@ SamplerThread::SamplerThread(PS::LockRef
 }
 
 SamplerThread::~SamplerThread()
 {
   pthread_join(mThread, nullptr);
 }
 
 void
-SamplerThread::Stop(PS::LockRef aLock)
+SamplerThread::Stop(PSLockRef aLock)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 }
 
 void
-SamplerThread::SuspendAndSampleAndResumeThread(PS::LockRef aLock,
+SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
                                                TickSample& aSample)
 {
   thread_act_t samplee_thread = aSample.mPlatformData->ProfiledThread();
 
   //----------------------------------------------------------------//
   // Suspend the samplee thread and get its context.
 
   // We're using thread_suspend on OS X because pthread_kill (which is what we
@@ -199,17 +199,17 @@ SamplerThread::SuspendAndSampleAndResume
   //
   // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 }
 
 // END SamplerThread target specifics
 ////////////////////////////////////////////////////////////////////////
 
 static void
-PlatformInit(PS::LockRef aLock)
+PlatformInit(PSLockRef aLock)
 {
 }
 
 void
 TickSample::PopulateContext(void* aContext)
 {
   MOZ_ASSERT(mIsSynchronous);
   MOZ_ASSERT(!aContext);
--- a/tools/profiler/core/platform-win32.cpp
+++ b/tools/profiler/core/platform-win32.cpp
@@ -93,17 +93,17 @@ static const HANDLE kNoThread = INVALID_
 static unsigned int __stdcall
 ThreadEntry(void* aArg)
 {
   auto thread = static_cast<SamplerThread*>(aArg);
   thread->Run();
   return 0;
 }
 
-SamplerThread::SamplerThread(PS::LockRef aLock, uint32_t aActivityGeneration,
+SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
                              double aIntervalMilliseconds)
     : mActivityGeneration(aActivityGeneration)
     , mIntervalMicroseconds(
         std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5))))
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   // By default we'll not adjust the timer resolution which tends to be
@@ -134,17 +134,17 @@ SamplerThread::~SamplerThread()
 
   // Close our own handle for the thread.
   if (mThread != kNoThread) {
     CloseHandle(mThread);
   }
 }
 
 void
-SamplerThread::Stop(PS::LockRef aLock)
+SamplerThread::Stop(PSLockRef aLock)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   // Disable any timer resolution changes we've made. Do it now while
   // gPSMutex is locked, i.e. before any other SamplerThread can be created
   // and call ::timeBeginPeriod().
   //
   // It's safe to do this now even though this SamplerThread is still alive,
@@ -152,17 +152,17 @@ SamplerThread::Stop(PS::LockRef aLock)
   // the mActivityGeneration check, and so it won't make any more ::Sleep()
   // calls.
   if (mIntervalMicroseconds < 10 * 1000) {
     ::timeEndPeriod(mIntervalMicroseconds / 1000);
   }
 }
 
 void
-SamplerThread::SuspendAndSampleAndResumeThread(PS::LockRef aLock,
+SamplerThread::SuspendAndSampleAndResumeThread(PSLockRef aLock,
                                                TickSample& aSample)
 {
   HANDLE profiled_thread = aSample.mPlatformData->ProfiledThread();
   if (profiled_thread == nullptr)
     return;
 
   // Context used for sampling the register state of the profiled thread.
   CONTEXT context;
@@ -224,17 +224,17 @@ SamplerThread::SuspendAndSampleAndResume
   //
   // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 }
 
 // END SamplerThread target specifics
 ////////////////////////////////////////////////////////////////////////
 
 static void
-PlatformInit(PS::LockRef aLock)
+PlatformInit(PSLockRef aLock)
 {
 }
 
 void
 TickSample::PopulateContext(CONTEXT* aContext)
 {
   MOZ_ASSERT(mIsSynchronous);
   MOZ_ASSERT(aContext);
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -105,41 +105,40 @@ public:
 };
 #endif
 
 class SamplerThread;
 
 // Per-thread state.
 MOZ_THREAD_LOCAL(PseudoStack *) tlsPseudoStack;
 
+class PSMutex : public mozilla::StaticMutex {};
+
+typedef mozilla::BaseAutoLock<PSMutex> PSAutoLock;
+
+// Only functions that take a PSLockRef arg can modify this class's fields.
+typedef const PSAutoLock& PSLockRef;
+
 // This class contains most of the profiler's global state. gPS is the single
 // instance. Most profile operations can't do anything useful when gPS is not
 // instantiated, so we release-assert its non-nullness in all such operations.
 //
 // Accesses to gPS are guarded by gPSMutex. Every getter and setter takes a
-// PS::AutoLock reference as an argument as proof that the gPSMutex is
-// currently locked. This makes it clear when gPSMutex is locked and helps
-// avoid accidental unlocked accesses to global state. There are ways to
-// circumvent this mechanism, but please don't do so without *very* good reason
-// and a detailed explanation.
+// PSAutoLock reference as an argument as proof that the gPSMutex is currently
+// locked. This makes it clear when gPSMutex is locked and helps avoid
+// accidental unlocked accesses to global state. There are ways to circumvent
+// this mechanism, but please don't do so without *very* good reason and a
+// detailed explanation.
 //
 // Other from the lock protection, this class is essentially a thin wrapper and
 // contains very little "smarts" itself.
 //
 class PS
 {
 public:
-  // Shorter names for local use.
-  class Mutex : public mozilla::StaticMutex {};
-
-  typedef mozilla::BaseAutoLock<Mutex> AutoLock;
-
-  // Only functions that take a LockRef arg can modify this class's fields.
-  typedef const AutoLock& LockRef;
-
   typedef std::vector<ThreadInfo*> ThreadVector;
 
   PS()
     : mEntries(0)
     , mInterval(0)
     , mFeatureDisplayListDump(false)
     , mFeatureGPU(false)
     , mFeatureJava(false)
@@ -163,28 +162,28 @@ public:
     , mLUL(nullptr)
 #endif
     , mInterposeObserver(nullptr)
     , mFrameNumber(0)
     , mLatestRecordedFrameNumber(0)
   {}
 
   #define GET_AND_SET(type_, name_) \
-    type_ name_(LockRef) const { return m##name_; } \
-    void Set##name_(LockRef, type_ a##name_) { m##name_ = a##name_; }
+    type_ name_(PSLockRef) const { return m##name_; } \
+    void Set##name_(PSLockRef, type_ a##name_) { m##name_ = a##name_; }
 
   GET_AND_SET(TimeStamp, ProcessStartTime)
 
   GET_AND_SET(int, Entries)
 
   GET_AND_SET(double, Interval)
 
-  Vector<std::string>& Features(LockRef) { return mFeatures; }
-
-  Vector<std::string>& ThreadNameFilters(LockRef) { return mThreadNameFilters; }
+  Vector<std::string>& Features(PSLockRef) { return mFeatures; }
+
+  Vector<std::string>& ThreadNameFilters(PSLockRef) { return mThreadNameFilters; }
 
   GET_AND_SET(bool, FeatureDisplayListDump)
   GET_AND_SET(bool, FeatureGPU)
   GET_AND_SET(bool, FeatureJava)
   GET_AND_SET(bool, FeatureJS)
   GET_AND_SET(bool, FeatureLayersDump)
   GET_AND_SET(bool, FeatureLeaf)
   GET_AND_SET(bool, FeatureMainThreadIO)
@@ -192,23 +191,23 @@ public:
   GET_AND_SET(bool, FeaturePrivacy)
   GET_AND_SET(bool, FeatureRestyle)
   GET_AND_SET(bool, FeatureStackWalk)
   GET_AND_SET(bool, FeatureTaskTracer)
   GET_AND_SET(bool, FeatureThreads)
 
   GET_AND_SET(ProfileBuffer*, Buffer)
 
-  ThreadVector& LiveThreads(LockRef) { return mLiveThreads; }
-  ThreadVector& DeadThreads(LockRef) { return mDeadThreads; }
-
-  static bool IsActive(LockRef) { return sActivityGeneration > 0; }
-  static uint32_t ActivityGeneration(LockRef) { return sActivityGeneration; }
-  static void SetInactive(LockRef) { sActivityGeneration = 0; }
-  static void SetActive(LockRef)
+  ThreadVector& LiveThreads(PSLockRef) { return mLiveThreads; }
+  ThreadVector& DeadThreads(PSLockRef) { return mDeadThreads; }
+
+  static bool IsActive(PSLockRef) { return sActivityGeneration > 0; }
+  static uint32_t ActivityGeneration(PSLockRef) { return sActivityGeneration; }
+  static void SetInactive(PSLockRef) { sActivityGeneration = 0; }
+  static void SetActive(PSLockRef)
   {
     sActivityGeneration = sNextActivityGeneration;
     // On overflow, reset to 1 instead of 0, because 0 means inactive.
     sNextActivityGeneration = (sNextActivityGeneration == 0xffffffff)
                             ? 1
                             : sNextActivityGeneration + 1;
   }
 
@@ -335,17 +334,17 @@ uint32_t PS::sNextActivityGeneration = 1
 
 // The core profiler state. Null at process startup, it is set to a non-null
 // value in profiler_init() and stays that way until profiler_shutdown() is
 // called. Therefore it can be checked to determine if the profiler has been
 // initialized but not yet shut down.
 static PS* gPS = nullptr;
 
 // The mutex that guards accesses to gPS.
-static PS::Mutex gPSMutex;
+static PSMutex gPSMutex;
 
 // The name of the main thread.
 static const char* const kMainThreadName = "GeckoMain";
 
 static bool
 CanNotifyObservers()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
@@ -468,17 +467,17 @@ AddDynamicCodeLocationTag(ProfileBuffer*
     // Cast to *((void**) to pass the text data to a void*.
     aBuffer->addTag(ProfileBufferEntry::EmbeddedString(*((void**)(&text[0]))));
   }
 }
 
 static const int SAMPLER_MAX_STRING_LENGTH = 128;
 
 static void
-AddPseudoEntry(PS::LockRef aLock, ProfileBuffer* aBuffer,
+AddPseudoEntry(PSLockRef aLock, ProfileBuffer* aBuffer,
                volatile js::ProfileEntry& entry, 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(js::ProfileEntry::BEGIN_PSEUDO_JS)) {
     return;
   }
@@ -570,17 +569,17 @@ struct AutoWalkJSStack
   ~AutoWalkJSStack() {
     if (walkAllowed) {
       WALKING_JS_STACK = false;
     }
   }
 };
 
 static void
-MergeStacksIntoProfile(PS::LockRef aLock, ProfileBuffer* aBuffer,
+MergeStacksIntoProfile(PSLockRef aLock, ProfileBuffer* aBuffer,
                        const TickSample& aSample, NativeStack& aNativeStack)
 {
   NotNull<PseudoStack*> pseudoStack = aSample.mPseudoStack;
   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
@@ -780,17 +779,17 @@ StackWalkCallback(uint32_t aFrameNumber,
   NativeStack* nativeStack = static_cast<NativeStack*>(aClosure);
   MOZ_ASSERT(nativeStack->count < nativeStack->size);
   nativeStack->sp_array[nativeStack->count] = aSP;
   nativeStack->pc_array[nativeStack->count] = aPC;
   nativeStack->count++;
 }
 
 static void
-DoNativeBacktrace(PS::LockRef aLock, ProfileBuffer* aBuffer,
+DoNativeBacktrace(PSLockRef aLock, ProfileBuffer* aBuffer,
                   const TickSample& aSample)
 {
   void* pc_array[1000];
   void* sp_array[1000];
   NativeStack nativeStack = {
     pc_array,
     sp_array,
     mozilla::ArrayLength(pc_array),
@@ -822,17 +821,17 @@ DoNativeBacktrace(PS::LockRef aLock, Pro
 #endif
 
   MergeStacksIntoProfile(aLock, aBuffer, aSample, nativeStack);
 }
 #endif
 
 #ifdef USE_EHABI_STACKWALK
 static void
-DoNativeBacktrace(PS::LockRef aLock, ProfileBuffer* aBuffer,
+DoNativeBacktrace(PSLockRef aLock, ProfileBuffer* aBuffer,
                   const TickSample& aSample)
 {
   void* pc_array[1000];
   void* sp_array[1000];
   NativeStack nativeStack = {
     pc_array,
     sp_array,
     mozilla::ArrayLength(pc_array),
@@ -911,17 +910,17 @@ ASAN_memcpy(void* aDst, const void* aSrc
 
   for (size_t i = 0; i < aLen; i++) {
     dst[i] = src[i];
   }
 }
 #endif
 
 static void
-DoNativeBacktrace(PS::LockRef aLock, ProfileBuffer* aBuffer,
+DoNativeBacktrace(PSLockRef aLock, ProfileBuffer* aBuffer,
                   const TickSample& aSample)
 {
   const mcontext_t* mc =
     &reinterpret_cast<ucontext_t*>(aSample.mContext)->uc_mcontext;
 
   lul::UnwindRegs startRegs;
   memset(&startRegs, 0, sizeof(startRegs));
 
@@ -1054,31 +1053,31 @@ DoNativeBacktrace(PS::LockRef aLock, Pro
   lul->mStats.mContext += 1;
   lul->mStats.mCFI     += framesUsed - 1 - scannedFramesAcquired;
   lul->mStats.mScanned += scannedFramesAcquired;
 }
 
 #endif
 
 static void
-DoSampleStackTrace(PS::LockRef aLock, ProfileBuffer* aBuffer,
+DoSampleStackTrace(PSLockRef aLock, ProfileBuffer* aBuffer,
                    const TickSample& aSample)
 {
   NativeStack nativeStack = { nullptr, nullptr, 0, 0 };
   MergeStacksIntoProfile(aLock, aBuffer, aSample, nativeStack);
 
   if (gPS->FeatureLeaf(aLock)) {
     aBuffer->addTag(ProfileBufferEntry::NativeLeafAddr((void*)aSample.mPC));
   }
 }
 
 // This function is called for each sampling period with the current program
 // counter. It is called within a signal and so must be re-entrant.
 static void
-Tick(PS::LockRef aLock, ProfileBuffer* aBuffer, const TickSample& aSample)
+Tick(PSLockRef aLock, ProfileBuffer* aBuffer, const TickSample& aSample)
 {
   aBuffer->addTagThreadId(aSample.mThreadId, aSample.mLastSample);
 
   mozilla::TimeDuration delta =
     aSample.mTimeStamp - gPS->ProcessStartTime(aLock);
   aBuffer->addTag(ProfileBufferEntry::Time(delta.ToMilliseconds()));
 
   NotNull<PseudoStack*> pseudoStack = aSample.mPseudoStack;
@@ -1182,17 +1181,17 @@ StreamNameAndThreadId(JSONWriter& aWrite
     }
     aWriter.IntProperty("tid", aThreadId);
   }
   aWriter.EndObject();
 }
 #endif
 
 static void
-StreamTaskTracer(PS::LockRef aLock, SpliceableJSONWriter& aWriter)
+StreamTaskTracer(PSLockRef aLock, SpliceableJSONWriter& aWriter)
 {
 #ifdef MOZ_TASK_TRACER
   aWriter.StartArrayProperty("data");
   {
     UniquePtr<nsTArray<nsCString>> data =
       mozilla::tasktracer::GetLoggedData(gPS->ProcessStartTime(aLock));
     for (uint32_t i = 0; i < data->Length(); ++i) {
       aWriter.StringElement((data->ElementAt(i)).get());
@@ -1217,17 +1216,17 @@ StreamTaskTracer(PS::LockRef aLock, Spli
   aWriter.EndArray();
 
   aWriter.DoubleProperty(
     "start", static_cast<double>(mozilla::tasktracer::GetStartTime()));
 #endif
 }
 
 static void
-StreamMetaJSCustomObject(PS::LockRef aLock, SpliceableJSONWriter& aWriter)
+StreamMetaJSCustomObject(PSLockRef aLock, SpliceableJSONWriter& aWriter)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   aWriter.IntProperty("version", 5);
   aWriter.DoubleProperty("interval", gPS->Interval(aLock));
   aWriter.IntProperty("stackwalk", gPS->FeatureStackWalk(aLock));
 
 #ifdef DEBUG
@@ -1349,17 +1348,19 @@ BuildJavaThreadJSObject(SpliceableJSONWr
       }
     }
   }
   aWriter.EndArray();
 }
 #endif
 
 static void
-locked_profiler_stream_json_for_this_process(PS::LockRef aLock, SpliceableJSONWriter& aWriter, double aSinceTime)
+locked_profiler_stream_json_for_this_process(PSLockRef aLock,
+                                             SpliceableJSONWriter& aWriter,
+                                             double aSinceTime)
 {
   LOG("locked_profiler_stream_json_for_this_process");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS && gPS->IsActive(aLock));
 
   // Put shared library info
   aWriter.StartArrayProperty("libs");
@@ -1425,17 +1426,17 @@ locked_profiler_stream_json_for_this_pro
 bool
 profiler_stream_json_for_this_process(SpliceableJSONWriter& aWriter, double aSinceTime)
 {
   LOG("profiler_stream_json_for_this_process");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock)) {
     return false;
   }
 
   locked_profiler_stream_json_for_this_process(lock, aWriter, aSinceTime);
   return true;
 }
@@ -1554,29 +1555,29 @@ struct SigHandlerCoordinator;
 // The sampler thread controls sampling and runs whenever the profiler is
 // active. It periodically runs through all registered threads, finds those
 // that should be sampled, then pauses and samples them.
 
 class SamplerThread
 {
 public:
   // Creates a sampler thread, but doesn't start it.
-  SamplerThread(PS::LockRef aLock, uint32_t aActivityGeneration,
+  SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
                 double aIntervalMilliseconds);
   ~SamplerThread();
 
   // This runs on the sampler thread.  It suspends and resumes the samplee
   // threads.
-  void SuspendAndSampleAndResumeThread(PS::LockRef aLock, TickSample& aSample);
+  void SuspendAndSampleAndResumeThread(PSLockRef aLock, TickSample& aSample);
 
   // This runs on (is!) the sampler thread.
   void Run();
 
   // This runs on the main thread.
-  void Stop(PS::LockRef aLock);
+  void Stop(PSLockRef aLock);
 
 private:
   // The activity generation, for detecting when the sampler thread must stop.
   const uint32_t mActivityGeneration;
 
   // The interval between samples, measured in microseconds.
   const int mIntervalMicroseconds;
 
@@ -1620,17 +1621,17 @@ SamplerThread::Run()
   // This will be positive if we are running behind schedule (sampling less
   // frequently than desired) and negative if we are ahead of schedule.
   TimeDuration lastSleepOvershoot = 0;
   TimeStamp sampleStart = TimeStamp::Now();
 
   while (true) {
     // This scope is for |lock|. It ends before we sleep below.
     {
-      PS::AutoLock lock(gPSMutex);
+      PSAutoLock lock(gPSMutex);
 
       // At this point profiler_stop() might have been called, and
       // profiler_start() might have been called on another thread.
       // Alternatively, profiler_shutdown() might have been called and gPS
       // may be null. In all these cases, PS::sActivityGeneration will no
       // longer equal mActivityGeneration, so we must exit immediately, but
       // without touching gPS. (This is why PS::sActivityGeneration must be
       // static.)
@@ -1753,17 +1754,17 @@ GeckoProfilerReporter::CollectReports(ns
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   size_t profSize = 0;
 #if defined(USE_LUL_STACKWALK)
   size_t lulSize = 0;
 #endif
 
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     if (gPS) {
       profSize = GeckoProfilerMallocSizeOf(gPS);
 
       const PS::ThreadVector& liveThreads = gPS->LiveThreads(lock);
       for (uint32_t i = 0; i < liveThreads.size(); i++) {
         ThreadInfo* info = liveThreads.at(i);
         profSize += info->SizeOfIncludingThis(GeckoProfilerMallocSizeOf);
@@ -1807,17 +1808,17 @@ GeckoProfilerReporter::CollectReports(ns
 #endif
 
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(GeckoProfilerReporter, nsIMemoryReporter)
 
 static bool
-ThreadSelected(PS::LockRef aLock, const char* aThreadName)
+ThreadSelected(PSLockRef aLock, const char* aThreadName)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
   const Vector<std::string>& threadNameFilters = gPS->ThreadNameFilters(aLock);
 
   if (threadNameFilters.empty()) {
@@ -1836,30 +1837,30 @@ ThreadSelected(PS::LockRef aLock, const 
       return true;
     }
   }
 
   return false;
 }
 
 static bool
-ShouldProfileThread(PS::LockRef aLock, ThreadInfo* aInfo)
+ShouldProfileThread(PSLockRef aLock, ThreadInfo* aInfo)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
   return ((aInfo->IsMainThread() || gPS->FeatureThreads(aLock)) &&
           ThreadSelected(aLock, aInfo->Name()));
 }
 
 // Find the ThreadInfo for the current thread. On success, *aIndexOut is set to
 // the index if it is non-null.
 static ThreadInfo*
-FindLiveThreadInfo(PS::LockRef aLock, int* aIndexOut = nullptr)
+FindLiveThreadInfo(PSLockRef aLock, int* aIndexOut = nullptr)
 {
   // This function runs both on and off the main thread.
 
   Thread::tid_t id = Thread::GetCurrentId();
   const PS::ThreadVector& liveThreads = gPS->LiveThreads(aLock);
   for (uint32_t i = 0; i < liveThreads.size(); i++) {
     ThreadInfo* info = liveThreads.at(i);
     if (info->ThreadId() == id) {
@@ -1868,17 +1869,17 @@ FindLiveThreadInfo(PS::LockRef aLock, in
       }
       return info;
     }
   }
   return nullptr;
 }
 
 static void
-locked_register_thread(PS::LockRef aLock, const char* aName, void* stackTop)
+locked_register_thread(PSLockRef aLock, const char* aName, void* stackTop)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
   MOZ_RELEASE_ASSERT(!FindLiveThreadInfo(aLock));
 
   if (!tlsPseudoStack.init()) {
@@ -1946,17 +1947,17 @@ NotifyObservers(const char* aTopic)
   if (!os) {
     return;
   }
 
   os->NotifyObservers(nullptr, aTopic, nullptr);
 }
 
 static void
-locked_profiler_start(PS::LockRef aLock, const int aEntries, double aInterval,
+locked_profiler_start(PSLockRef aLock, const int aEntries, double aInterval,
                       const char** aFeatures, uint32_t aFeatureCount,
                       const char** aThreadNameFilters, uint32_t aFilterCount);
 
 void
 profiler_init(void* aStackTop)
 {
   LOG("profiler_init");
 
@@ -1975,17 +1976,17 @@ profiler_init(void* aStackTop)
 
   const char* threadFilters[] = { "GeckoMain", "Compositor" };
 
   if (getenv("MOZ_PROFILER_HELP")) {
     PrintUsageThenExit(0); // terminates execution
   }
 
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     // We've passed the possible failure point. Instantiate gPS, which
     // indicates that the profiler has initialized successfully.
     gPS = new PS();
 
     bool ignore;
     gPS->SetProcessStartTime(lock, mozilla::TimeStamp::ProcessCreation(ignore));
 
@@ -2048,34 +2049,34 @@ profiler_init(void* aStackTop)
   // We do this with gPSMutex unlocked. The comment in profiler_stop() explains
   // why.
   NotifyProfilerStarted(PROFILE_DEFAULT_ENTRIES, PROFILE_DEFAULT_INTERVAL,
                         features, MOZ_ARRAY_LENGTH(features),
                         threadFilters, MOZ_ARRAY_LENGTH(threadFilters));
 }
 
 static void
-locked_profiler_save_profile_to_file(PS::LockRef aLock, const char* aFilename);
+locked_profiler_save_profile_to_file(PSLockRef aLock, const char* aFilename);
 
 static SamplerThread*
-locked_profiler_stop(PS::LockRef aLock);
+locked_profiler_stop(PSLockRef aLock);
 
 void
 profiler_shutdown()
 {
   LOG("profiler_shutdown");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
   // If the profiler is active we must get a handle to the SamplerThread before
   // gPS is destroyed, in order to delete it.
   SamplerThread* samplerThread = nullptr;
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     // Save the profile on shutdown if requested.
     if (gPS->IsActive(lock)) {
       const char* filename = getenv("MOZ_PROFILER_SHUTDOWN");
       if (filename) {
         locked_profiler_save_profile_to_file(lock, filename);
       }
 
@@ -2156,17 +2157,17 @@ profiler_get_start_params(int* aEntries,
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
   if (NS_WARN_IF(!aEntries) || NS_WARN_IF(!aInterval) ||
       NS_WARN_IF(!aFeatures) || NS_WARN_IF(!aFilters)) {
     return;
   }
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   *aEntries = gPS->Entries(lock);
   *aInterval = gPS->Interval(lock);
 
   const Vector<std::string>& features = gPS->Features(lock);
   MOZ_ALWAYS_TRUE(aFeatures->resize(features.length()));
   for (size_t i = 0; i < features.length(); ++i) {
     (*aFeatures)[i] = features[i].c_str();
@@ -2175,17 +2176,17 @@ profiler_get_start_params(int* aEntries,
   const Vector<std::string>& threadNameFilters = gPS->ThreadNameFilters(lock);
   MOZ_ALWAYS_TRUE(aFilters->resize(threadNameFilters.length()));
   for (uint32_t i = 0; i < threadNameFilters.length(); ++i) {
     (*aFilters)[i] = threadNameFilters[i].c_str();
   }
 }
 
 static void
-locked_profiler_save_profile_to_file(PS::LockRef aLock, const char* aFilename)
+locked_profiler_save_profile_to_file(PSLockRef aLock, const char* aFilename)
 {
   LOG("locked_profiler_save_profile_to_file(%s)", aFilename);
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS && gPS->IsActive(aLock));
 
   std::ofstream stream;
   stream.open(aFilename);
@@ -2209,17 +2210,17 @@ locked_profiler_save_profile_to_file(PS:
 void
 profiler_save_profile_to_file(const char* aFilename)
 {
   LOG("profiler_save_profile_to_file(%s)", aFilename);
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock)) {
     return;
   }
 
   locked_profiler_save_profile_to_file(lock, aFilename);
 }
 
@@ -2273,17 +2274,17 @@ profiler_get_buffer_info_helper(uint32_t
                                 uint32_t* aGeneration)
 {
   // This function is called by profiler_get_buffer_info(), which has already
   // zeroed the outparams.
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock)) {
     return;
   }
 
   *aCurrentPosition = gPS->Buffer(lock)->mWritePos;
   *aEntries = gPS->Entries(lock);
   *aGeneration = gPS->Buffer(lock)->mGeneration;
@@ -2296,17 +2297,17 @@ hasFeature(const char** aFeatures, uint3
     if (strcmp(aFeatures[i], aFeature) == 0) {
       return true;
     }
   }
   return false;
 }
 
 static void
-locked_profiler_start(PS::LockRef aLock, int aEntries, double aInterval,
+locked_profiler_start(PSLockRef aLock, int aEntries, double aInterval,
                       const char** aFeatures, uint32_t aFeatureCount,
                       const char** aThreadNameFilters, uint32_t aFilterCount)
 {
   if (LOG_TEST) {
     LOG("locked_profiler_start");
     LOG("- entries  = %d", aEntries);
     LOG("- interval = %.2f", aInterval);
     for (uint32_t i = 0; i < aFeatureCount; i++) {
@@ -2442,17 +2443,17 @@ profiler_start(int aEntries, double aInt
                const char** aThreadNameFilters, uint32_t aFilterCount)
 {
   LOG("profiler_start");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
   SamplerThread* samplerThread = nullptr;
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     // Initialize if necessary.
     if (!gPS) {
       profiler_init(nullptr);
     }
 
     // Reset the current state if the profiler is running.
     if (gPS->IsActive(lock)) {
@@ -2469,17 +2470,17 @@ profiler_start(int aEntries, double aInt
     NotifyObservers("profiler-stopped");
     delete samplerThread;
   }
   NotifyProfilerStarted(aEntries, aInterval, aFeatures, aFeatureCount,
                         aThreadNameFilters, aFilterCount);
 }
 
 static MOZ_MUST_USE SamplerThread*
-locked_profiler_stop(PS::LockRef aLock)
+locked_profiler_stop(PSLockRef aLock)
 {
   LOG("locked_profiler_stop");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS && gPS->IsActive(aLock));
 
   // We clear things in roughly reverse order to their setting in
   // locked_profiler_start().
@@ -2568,17 +2569,17 @@ profiler_stop()
 {
   LOG("profiler_stop");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
   SamplerThread* samplerThread;
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     if (!gPS->IsActive(lock)) {
       return;
     }
 
     samplerThread = locked_profiler_stop(lock);
   }
 
@@ -2600,17 +2601,17 @@ profiler_stop()
 }
 
 bool
 profiler_is_paused()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock)) {
     return false;
   }
 
   return gPS->IsPaused(lock);
 }
 
@@ -2618,17 +2619,17 @@ void
 profiler_pause()
 {
   LOG("profiler_pause");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
 
     if (!gPS->IsActive(lock)) {
       return;
     }
 
     gPS->SetIsPaused(lock, true);
   }
 
@@ -2639,17 +2640,17 @@ profiler_pause()
 void
 profiler_resume()
 {
   LOG("profiler_resume");
 
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   {
     if (!gPS->IsActive(lock)) {
       return;
     }
 
     gPS->SetIsPaused(lock, false);
   }
@@ -2660,17 +2661,17 @@ profiler_resume()
 
 bool
 profiler_feature_active(const char* aName)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock)) {
     return false;
   }
 
   if (strcmp(aName, "displaylistdump") == 0) {
     return gPS->FeatureDisplayListDump(lock);
   }
@@ -2692,54 +2693,54 @@ profiler_feature_active(const char* aNam
 
 bool
 profiler_is_active()
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   return gPS->IsActive(lock);
 }
 
 void
 profiler_set_frame_number(int aFrameNumber)
 {
   // This function runs both on (via tests) and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   gPS->SetFrameNumber(lock, aFrameNumber);
 }
 
 void
 profiler_register_thread(const char* aName, void* aGuessStackTop)
 {
   DEBUG_LOG("profiler_register_thread(%s)", aName);
 
   MOZ_RELEASE_ASSERT(!NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   void* stackTop = GetStackTop(aGuessStackTop);
   locked_register_thread(lock, aName, stackTop);
 }
 
 void
 profiler_unregister_thread()
 {
   MOZ_RELEASE_ASSERT(!NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   // We don't call PseudoStack::stopJSSampling() here; there's no point doing
   // that for a JS thread that is in the process of disappearing.
 
   int i;
   ThreadInfo* info = FindLiveThreadInfo(lock, &i);
   if (info) {
     DEBUG_LOG("profiler_unregister_thread: %s", info->Name());
@@ -2827,30 +2828,30 @@ profiler_js_interrupt_callback()
 
 double
 profiler_time()
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   mozilla::TimeDuration delta =
     mozilla::TimeStamp::Now() - gPS->ProcessStartTime(lock);
   return delta.ToMilliseconds();
 }
 
 UniqueProfilerBacktrace
 profiler_get_backtrace()
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock) || gPS->FeaturePrivacy(lock)) {
     return nullptr;
   }
 
   PseudoStack* stack = tlsPseudoStack.get();
   if (!stack) {
     MOZ_ASSERT(stack);
@@ -2903,17 +2904,17 @@ profiler_get_backtrace_noalloc(char *out
 
   PseudoStack *pseudoStack = tlsPseudoStack.get();
   if (!pseudoStack) {
     return;
   }
 
   bool includeDynamicString = true;
   {
-    PS::AutoLock lock(gPSMutex);
+    PSAutoLock lock(gPSMutex);
     includeDynamicString = !gPS->FeaturePrivacy(lock);
   }
 
   volatile js::ProfileEntry *pseudoFrames = pseudoStack->mStack;
   uint32_t pseudoCount = pseudoStack->stackSize();
 
   for (uint32_t i = 0; i < pseudoCount; i++) {
     const char* label = pseudoFrames[i].label();
@@ -2940,17 +2941,17 @@ profiler_get_backtrace_noalloc(char *out
       output += labelLength;
     }
     *output++ = '\0';
     *output = '\0';
   }
 }
 
 static void
-locked_profiler_add_marker(PS::LockRef aLock, const char* aMarker,
+locked_profiler_add_marker(PSLockRef aLock, const char* aMarker,
                            ProfilerMarkerPayload* aPayload)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
   MOZ_RELEASE_ASSERT(gPS->IsActive(aLock) && !gPS->FeaturePrivacy(aLock));
 
   // aPayload must be freed if we return early.
@@ -2970,17 +2971,17 @@ locked_profiler_add_marker(PS::LockRef a
 
 void
 profiler_add_marker(const char* aMarker, ProfilerMarkerPayload* aPayload)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   // aPayload must be freed if we return early.
   mozilla::UniquePtr<ProfilerMarkerPayload> payload(aPayload);
 
   if (!gPS->IsActive(lock) || gPS->FeaturePrivacy(lock)) {
     return;
   }
 
@@ -2990,17 +2991,17 @@ profiler_add_marker(const char* aMarker,
 void
 profiler_tracing(const char* aCategory, const char* aInfo,
                  TracingKind aKind)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock) || gPS->FeaturePrivacy(lock)) {
     return;
   }
 
   auto marker = new ProfilerMarkerTracing(aCategory, aKind);
   locked_profiler_add_marker(lock, aInfo, marker);
 }
@@ -3008,17 +3009,17 @@ profiler_tracing(const char* aCategory, 
 void
 profiler_tracing(const char* aCategory, const char* aInfo,
                  UniqueProfilerBacktrace aCause, TracingKind aKind)
 {
   // This function runs both on and off the main thread.
 
   MOZ_RELEASE_ASSERT(gPS);
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (!gPS->IsActive(lock) || gPS->FeaturePrivacy(lock)) {
     return;
   }
 
   auto marker =
     new ProfilerMarkerTracing(aCategory, aKind, mozilla::Move(aCause));
   locked_profiler_add_marker(lock, aInfo, marker);
@@ -3061,17 +3062,17 @@ profiler_clear_js_context()
 
   if (!stack->mContext) {
     return;
   }
 
   // On JS shut down, flush the current buffer as stringifying JIT samples
   // requires a live JSContext.
 
-  PS::AutoLock lock(gPSMutex);
+  PSAutoLock lock(gPSMutex);
 
   if (gPS->IsActive(lock)) {
     gPS->SetIsPaused(lock, true);
 
     // Flush this thread's ThreadInfo, if it is being profiled.
     ThreadInfo* info = FindLiveThreadInfo(lock);
     MOZ_RELEASE_ASSERT(info);
     if (info->IsBeingProfiled()) {