Backed out 27 changesets (bug 1323100) for clipboard leaktest failures a=backout
authorWes Kocher <wkocher@mozilla.com>
Thu, 29 Dec 2016 16:28:36 -0800
changeset 358481 dbe5b7ff43b6b1307923d0e14bf53b165b670eac
parent 358480 77cbde755c30cc4adff4bedc5363e15dfd702edb
child 358482 67611ffb1fef3d6f664a7d878995da81b0d56122
push id17
push userfmarier@mozilla.com
push dateFri, 13 Jan 2017 22:14:57 +0000
reviewersbackout
bugs1323100
milestone53.0a1
backs out84fb749698abd1b1c73e2f0a48dce6a3b60aa5e0
d6d25e8bd001ff063ab7063d3bfb06356b0cd350
1b0855bb0c387415b4c619b7aa9562442ba14615
b6953e3f573984c322e59219ffc8e57b2689e9f6
5572f3b63215abb059e49c366a4769a55b2cc80f
12fb4c533659d2a60bca185d910e44bb4baf9f3c
c36524e4e9194d13522fb62f41b2f8128c06d46d
1e3b3eddbe26220bce2e02079ddbcdc0403eff58
061110f1ae12eb473f3382149651afbec2bad1cc
413dbd31725ba5609e9306db857cce2819e3f0db
06550f7eca620ed7d4100ce35e70430f1f3f1ece
940933b13b36195606aca5ac78070f92f9a823bd
a6d75c1cd72460604976b865bfbb6f5c9b79ae5e
681cacbbaa3be89fc75fbb23b49633069e2b915b
3d53787293f63547deb2fab24015e7b1d0286a80
c0340dfe4766390fbfb09c5b452ea33ee4d667e3
9f554991549da15653d9286f70563bcc271a9c56
757539e7039ae05a903ee76fb3b56a1e4b772f54
a3c9b45aa917fd64140893789593ebde315da2ce
23d69df98a660f491348909043da2102ef1b7aad
1297ded6a01da759b6a2daefaad1d7bbc38bc352
f4235b97257f6996ac56250d6d948a52c68a3229
93419cb4f29f9be412ff04fc4fba5fddc6af438f
865d1b81c804490a833d913963873ddfcce17f88
54acf4ef8e84be51cbd8e1489e752c0f04e4906f
88d17bcd8205b597edd3a5a6f03580b042d00148
0c466e5e8933a0ef719004deac33377949b33a5a
Backed out 27 changesets (bug 1323100) for clipboard leaktest failures a=backout Backed out changeset 84fb749698ab (bug 1323100) Backed out changeset d6d25e8bd001 (bug 1323100) Backed out changeset 1b0855bb0c38 (bug 1323100) Backed out changeset b6953e3f5739 (bug 1323100) Backed out changeset 5572f3b63215 (bug 1323100) Backed out changeset 12fb4c533659 (bug 1323100) Backed out changeset c36524e4e919 (bug 1323100) Backed out changeset 1e3b3eddbe26 (bug 1323100) Backed out changeset 061110f1ae12 (bug 1323100) Backed out changeset 413dbd31725b (bug 1323100) Backed out changeset 06550f7eca62 (bug 1323100) Backed out changeset 940933b13b36 (bug 1323100) Backed out changeset a6d75c1cd724 (bug 1323100) Backed out changeset 681cacbbaa3b (bug 1323100) Backed out changeset 3d53787293f6 (bug 1323100) Backed out changeset c0340dfe4766 (bug 1323100) Backed out changeset 9f554991549d (bug 1323100) Backed out changeset 757539e7039a (bug 1323100) Backed out changeset a3c9b45aa917 (bug 1323100) Backed out changeset 23d69df98a66 (bug 1323100) Backed out changeset 1297ded6a01d (bug 1323100) Backed out changeset f4235b97257f (bug 1323100) Backed out changeset 93419cb4f29f (bug 1323100) Backed out changeset 865d1b81c804 (bug 1323100) Backed out changeset 54acf4ef8e84 (bug 1323100) Backed out changeset 88d17bcd8205 (bug 1323100) Backed out changeset 0c466e5e8933 (bug 1323100)
dom/gamepad/cocoa/CocoaGamepad.cpp
dom/gamepad/windows/WindowsGamepad.cpp
dom/indexedDB/ActorsParent.cpp
dom/media/FileBlockCache.cpp
dom/media/GraphDriver.cpp
dom/media/MediaRecorder.cpp
dom/media/android/AndroidMediaResourceServer.cpp
dom/media/gtest/TestMP4Reader.cpp
dom/media/webaudio/blink/HRTFDatabaseLoader.cpp
dom/plugins/base/android/ANPAudio.cpp
dom/storage/DOMStorageDBThread.cpp
dom/system/gonk/GonkGPSGeolocationProvider.cpp
gfx/layers/LayerScope.cpp
hal/gonk/GonkHal.cpp
image/DecodePool.cpp
image/test/gtest/TestDecodeToSurface.cpp
ipc/chromium/src/base/thread.cc
ipc/glue/BackgroundImpl.cpp
js/xpconnect/src/XPCJSContext.cpp
media/mtransport/nr_socket_prsock.cpp
netwerk/base/BackgroundFileSaver.cpp
netwerk/base/nsPACMan.cpp
netwerk/base/nsPACMan.h
netwerk/base/nsSocketTransportService2.cpp
netwerk/cache2/CacheIOThread.cpp
netwerk/dns/nsHostResolver.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/system/win32/nsNotifyAddrListener.cpp
netwerk/test/TestFileInput2.cpp
netwerk/wifi/nsWifiMonitor.cpp
security/manager/ssl/CryptoTask.cpp
security/manager/ssl/nsKeygenThread.cpp
security/manager/ssl/nsProtectedAuthThread.cpp
security/manager/ssl/nsSmartCardMonitor.cpp
startupcache/StartupCache.cpp
storage/mozStorageConnection.cpp
storage/test/gtest/test_service_init_background_thread.cpp
toolkit/components/filewatcher/NativeFileWatcherWin.cpp
toolkit/components/terminator/nsTerminator.cpp
toolkit/components/url-classifier/tests/gtest/Common.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/identity/IdentityCryptoService.cpp
toolkit/xre/EventTracer.cpp
toolkit/xre/nsUpdateDriver.cpp
tools/profiler/public/GeckoProfiler.h
tools/profiler/public/GeckoProfilerImpl.h
widget/windows/LSPAnnotator.cpp
widget/windows/nsSound.cpp
xpcom/build/MainThreadIOLogger.cpp
xpcom/glue/nsThreadUtils.cpp
xpcom/glue/nsThreadUtils.h
xpcom/tests/gtest/TestPipes.cpp
xpcom/tests/gtest/TestRacingServiceManager.cpp
xpcom/tests/gtest/TestThreads.cpp
xpcom/tests/gtest/TestTimers.cpp
xpcom/threads/BackgroundHangMonitor.cpp
xpcom/threads/HangMonitor.cpp
xpcom/threads/LazyIdleThread.cpp
xpcom/threads/TimerThread.cpp
xpcom/threads/nsIThreadManager.idl
xpcom/threads/nsProcessCommon.cpp
xpcom/threads/nsThread.cpp
xpcom/threads/nsThread.h
xpcom/threads/nsThreadManager.cpp
xpcom/threads/nsThreadPool.cpp
--- a/dom/gamepad/cocoa/CocoaGamepad.cpp
+++ b/dom/gamepad/cocoa/CocoaGamepad.cpp
@@ -536,19 +536,18 @@ DarwinGamepadService::StartupInternal()
   // CFRunLoopRun() is a blocking message loop when it's called in
   // non-main thread so this thread cannot receive any other runnables
   // and nsITimer timeout events after it's called.
   CFRunLoopRun();
 }
 
 void DarwinGamepadService::Startup()
 {
-  Unused << NS_NewNamedThread("Gamepad",
-                              getter_AddRefs(mMonitorThread),
-                              new DarwinGamepadServiceStartupRunnable(this));
+  Unused << NS_NewThread(getter_AddRefs(mMonitorThread),
+                         new DarwinGamepadServiceStartupRunnable(this));
 }
 
 void DarwinGamepadService::Shutdown()
 {
   IOHIDManagerRef manager = (IOHIDManagerRef)mManager;
   CFRunLoopStop(mMonitorRunLoop);
   if (manager) {
     IOHIDManagerClose(manager, 0);
--- a/dom/gamepad/windows/WindowsGamepad.cpp
+++ b/dom/gamepad/windows/WindowsGamepad.cpp
@@ -1060,17 +1060,17 @@ void
 StartGamepadMonitoring()
 {
   AssertIsOnBackgroundThread();
 
   if (gMonitorThread || gService) {
     return;
   }
   sIsShutdown = false;
-  NS_NewNamedThread("Gamepad", getter_AddRefs(gMonitorThread));
+  NS_NewThread(getter_AddRefs(gMonitorThread));
   gMonitorThread->Dispatch(new StartWindowsGamepadServiceRunnable(),
                            NS_DISPATCH_NORMAL);
 }
 
 void
 StopGamepadMonitoring()
 {
   AssertIsOnBackgroundThread();
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -5715,21 +5715,16 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   uint32_t
   SerialNumber() const
   {
     return mSerialNumber;
   }
 
-  nsCString GetThreadName() const
-  {
-    return nsPrintfCString("IndexedDB #%lu", mSerialNumber);
-  }
-
 private:
   ~ThreadRunnable() override;
 
   NS_DECL_NSIRUNNABLE
 };
 
 class ConnectionPool::TransactionInfo final
 {
@@ -12571,20 +12566,17 @@ ConnectionPool::ScheduleTransaction(Tran
     if (mIdleThreads.IsEmpty()) {
       bool created = false;
 
       if (mTotalThreadCount < kMaxConnectionThreadCount) {
         // This will set the thread up with the profiler.
         RefPtr<ThreadRunnable> runnable = new ThreadRunnable();
 
         nsCOMPtr<nsIThread> newThread;
-        nsresult rv =
-          NS_NewNamedThread(runnable->GetThreadName(),
-                            getter_AddRefs(newThread), runnable);
-        if (NS_SUCCEEDED(rv)) {
+        if (NS_SUCCEEDED(NS_NewThread(getter_AddRefs(newThread), runnable))) {
           MOZ_ASSERT(newThread);
 
           IDB_DEBUG_LOG(("ConnectionPool created thread %lu",
                          runnable->SerialNumber()));
 
           dbInfo->mThreadInfo.mThread.swap(newThread);
           dbInfo->mThreadInfo.mRunnable.swap(runnable);
 
@@ -13287,27 +13279,43 @@ ThreadRunnable::~ThreadRunnable()
 }
 
 NS_IMPL_ISUPPORTS_INHERITED0(ConnectionPool::ThreadRunnable, Runnable)
 
 nsresult
 ConnectionPool::
 ThreadRunnable::Run()
 {
+#ifdef MOZ_ENABLE_PROFILER_SPS
+  char stackTopGuess;
+#endif // MOZ_ENABLE_PROFILER_SPS
+
   MOZ_ASSERT(!IsOnBackgroundThread());
   MOZ_ASSERT(mContinueRunning);
 
   if (!mFirstRun) {
     mContinueRunning = false;
     return NS_OK;
   }
 
   mFirstRun = false;
 
   {
+    // Scope for the thread name. Both PR_SetCurrentThreadName() and
+    // profiler_register_thread() copy the string so we don't need to keep it.
+    const nsPrintfCString threadName("IndexedDB #%lu", mSerialNumber);
+
+    PR_SetCurrentThreadName(threadName.get());
+
+#ifdef MOZ_ENABLE_PROFILER_SPS
+    profiler_register_thread(threadName.get(), &stackTopGuess);
+#endif // MOZ_ENABLE_PROFILER_SPS
+  }
+
+  {
     // Scope for the profiler label.
     PROFILER_LABEL("IndexedDB",
                    "ConnectionPool::ThreadRunnable::Run",
                    js::ProfileEntry::Category::STORAGE);
 
     nsIThread* currentThread = NS_GetCurrentThread();
     MOZ_ASSERT(currentThread);
 
@@ -13338,16 +13346,20 @@ ThreadRunnable::Run()
         MOZ_ALWAYS_TRUE(
           PR_Sleep(PR_MillisecondsToInterval(kDEBUGTransactionThreadSleepMS)) ==
             PR_SUCCESS);
       }
 #endif // DEBUG
     }
   }
 
+#ifdef MOZ_ENABLE_PROFILER_SPS
+  profiler_unregister_thread();
+#endif // MOZ_ENABLE_PROFILER_SPS
+
   return NS_OK;
 }
 
 ConnectionPool::
 ThreadInfo::ThreadInfo()
 {
   AssertIsOnBackgroundThread();
 
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -17,20 +17,19 @@ nsresult FileBlockCache::Open(PRFileDesc
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   NS_ENSURE_TRUE(aFD != nullptr, NS_ERROR_FAILURE);
   {
     MonitorAutoLock mon(mFileMonitor);
     mFD = aFD;
   }
   {
     MonitorAutoLock mon(mDataMonitor);
-    nsresult res = NS_NewNamedThread("FileBlockCache",
-                                     getter_AddRefs(mThread),
-                                     nullptr,
-                                     SharedThreadPool::kStackSize);
+    nsresult res = NS_NewThread(getter_AddRefs(mThread),
+                                nullptr,
+                                SharedThreadPool::kStackSize);
     mIsOpen = NS_SUCCEEDED(res);
     return res;
   }
 }
 
 FileBlockCache::FileBlockCache()
   : mFileMonitor("MediaCache.Writer.IO.Monitor"),
     mFD(nullptr),
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -34,16 +34,29 @@ extern mozilla::LazyLogModule gMediaStre
 #else
 #define LIFECYCLE_LOG(...)
 #endif
 
 namespace mozilla {
 
 StaticRefPtr<nsIThreadPool> AsyncCubebTask::sThreadPool;
 
+struct AutoProfilerUnregisterThread
+{
+  // The empty ctor is used to silence a pre-4.8.0 GCC unused variable warning.
+  AutoProfilerUnregisterThread()
+  {
+  }
+
+  ~AutoProfilerUnregisterThread()
+  {
+    profiler_unregister_thread();
+  }
+};
+
 GraphDriver::GraphDriver(MediaStreamGraphImpl* aGraphImpl)
   : mIterationStart(0),
     mIterationEnd(0),
     mGraphImpl(aGraphImpl),
     mWaitState(WAITSTATE_RUNNING),
     mCurrentTimeStamp(TimeStamp::Now()),
     mPreviousDriver(nullptr),
     mNextDriver(nullptr)
@@ -178,17 +191,19 @@ ThreadedDriver::~ThreadedDriver()
 class MediaStreamGraphInitThreadRunnable : public Runnable {
 public:
   explicit MediaStreamGraphInitThreadRunnable(ThreadedDriver* aDriver)
     : mDriver(aDriver)
   {
   }
   NS_IMETHOD Run() override
   {
+    char aLocal;
     STREAM_LOG(LogLevel::Debug, ("Starting system thread"));
+    profiler_register_thread("MediaStreamGraph", &aLocal);
     LIFECYCLE_LOG("Starting a new system driver for graph %p\n",
                   mDriver->mGraphImpl);
 
     GraphDriver* previousDriver = nullptr;
     {
       MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
       previousDriver = mDriver->PreviousDriver();
     }
@@ -296,16 +311,18 @@ bool
 SystemClockDriver::IsFallback()
 {
   return mIsFallback;
 }
 
 void
 ThreadedDriver::RunThread()
 {
+  AutoProfilerUnregisterThread autoUnregister;
+
   bool stillProcessing = true;
   while (stillProcessing) {
     mIterationStart = IterationEnd();
     mIterationEnd += GetIntervalForIteration();
 
     GraphTime stateComputedTime = StateComputedTime();
     if (stateComputedTime < mIterationEnd) {
       STREAM_LOG(LogLevel::Warning, ("Media graph global underrun detected"));
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -278,16 +278,18 @@ class MediaRecorder::Session: public nsI
         mSession->Extract(false);
         nsCOMPtr<nsIRunnable> event = new ExtractRunnable(mSession);
         if (NS_FAILED(NS_DispatchToCurrentThread(event))) {
           NS_WARNING("Failed to dispatch ExtractRunnable to encoder thread");
         }
       } else {
         // Flush out remaining encoded data.
         mSession->Extract(true);
+        if (mSession->mIsRegisterProfiler)
+           profiler_unregister_thread();
         if (NS_FAILED(NS_DispatchToMainThread(
                         new DestroyRunnable(mSession)))) {
           MOZ_ASSERT(false, "NS_DispatchToMainThread DestroyRunnable failed");
         }
       }
       return NS_OK;
     }
 
@@ -412,16 +414,17 @@ class MediaRecorder::Session: public nsI
   friend class TracksAvailableCallback;
 
 public:
   Session(MediaRecorder* aRecorder, int32_t aTimeSlice)
     : mRecorder(aRecorder)
     , mTimeSlice(aTimeSlice)
     , mStopIssued(false)
     , mIsStartEventFired(false)
+    , mIsRegisterProfiler(false)
     , mNeedSessionEndTask(true)
     , mSelectedVideoTrackID(TRACK_NONE)
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     uint32_t maxMem = Preferences::GetUint("media.recorder.max_memory",
                                            MAX_ALLOW_MEMORY_BUFFER);
     mEncodedBufferCache = new EncodedBufferCache(maxMem);
@@ -599,16 +602,22 @@ private:
   // Destroy this session object in the end of this function.
   // If the bool aForceFlush is true, we will force to dispatch a
   // PushBlobRunnable to main thread.
   void Extract(bool aForceFlush)
   {
     MOZ_ASSERT(NS_GetCurrentThread() == mReadThread);
     LOG(LogLevel::Debug, ("Session.Extract %p", this));
 
+    if (!mIsRegisterProfiler) {
+      char aLocal;
+      profiler_register_thread("Media_Encoder", &aLocal);
+      mIsRegisterProfiler = true;
+    }
+
     PROFILER_LABEL("MediaRecorder", "Session Extract",
       js::ProfileEntry::Category::OTHER);
 
     // Pull encoded media data from MediaEncoder
     nsTArray<nsTArray<uint8_t> > encodedBuf;
     mEncoder->GetEncodedData(&encodedBuf, mMimeType);
 
     // Append pulled data into cache buffer.
@@ -908,16 +917,18 @@ private:
   // handler. "mTimeSlice < 0" means Session object does not push encoded data to
   // onDataAvailable, instead, it passive wait the client side pull encoded data
   // by calling requestData API.
   const int32_t mTimeSlice;
   // Indicate this session's stop has been called.
   bool mStopIssued;
   // Indicate the session had fire start event. Encoding thread only.
   bool mIsStartEventFired;
+  // The register flag for "Media_Encoder" thread to profiler
+  bool mIsRegisterProfiler;
   // False if the InitEncoder called successfully, ensure the
   // ExtractRunnable/DestroyRunnable will end the session.
   // Main thread only.
   bool mNeedSessionEndTask;
   TrackID mSelectedVideoTrackID;
 };
 
 NS_IMPL_ISUPPORTS(MediaRecorder::Session, nsIObserver)
--- a/dom/media/android/AndroidMediaResourceServer.cpp
+++ b/dom/media/android/AndroidMediaResourceServer.cpp
@@ -370,17 +370,17 @@ ResourceSocketListener::OnSocketAccepted
 
   rv = aTrans->OpenInputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(input));
   if (NS_FAILED(rv)) return rv;
 
   rv = aTrans->OpenOutputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(output));
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIThread> thread;
-  rv = NS_NewNamedThread("ServeResource", getter_AddRefs(thread));
+  rv = NS_NewThread(getter_AddRefs(thread));
   if (NS_FAILED(rv)) return rv;
 
   nsCOMPtr<nsIRunnable> event = new ServeResourceEvent(input.get(), output.get(), mServer);
   return thread->Dispatch(event, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 ResourceSocketListener::OnStopListening(nsIServerSocket* aServ, nsresult aStatus)
--- a/dom/media/gtest/TestMP4Reader.cpp
+++ b/dom/media/gtest/TestMP4Reader.cpp
@@ -39,17 +39,17 @@ public:
     // This needs to be done before invoking GetBuffered. This is normally
     // done by MediaDecoderStateMachine.
     reader->DispatchSetStartTime(0);
   }
 
   void Init() {
     nsCOMPtr<nsIThread> thread;
     nsCOMPtr<nsIRunnable> r = NewRunnableMethod(this, &TestBinding::ReadMetadata);
-    nsresult rv = NS_NewNamedThread("ReadMetadata", getter_AddRefs(thread), r);
+    nsresult rv = NS_NewThread(getter_AddRefs(thread), r);
     EXPECT_EQ(NS_OK, rv);
     thread->Shutdown();
   }
 
 private:
   virtual ~TestBinding()
   {
     {
--- a/dom/media/webaudio/blink/HRTFDatabaseLoader.cpp
+++ b/dom/media/webaudio/blink/HRTFDatabaseLoader.cpp
@@ -23,17 +23,16 @@
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "HRTFDatabaseLoader.h"
 #include "HRTFDatabase.h"
-#include "GeckoProfiler.h"
 
 using namespace mozilla;
 
 namespace WebCore {
 
 // Singleton
 nsTHashtable<HRTFDatabaseLoader::LoaderByRateEntry>*
     HRTFDatabaseLoader::s_loaderMap = nullptr;
@@ -147,17 +146,16 @@ void HRTFDatabaseLoader::MainThreadRelea
         // on this (main) thread.
         delete this;
     }
 }
 
 // Asynchronously load the database in this thread.
 static void databaseLoaderEntry(void* threadData)
 {
-    AutoProfilerRegister registerThread("HRTFDatabaseLdr");
     PR_SetCurrentThreadName("HRTFDatabaseLdr");
 
     HRTFDatabaseLoader* loader = reinterpret_cast<HRTFDatabaseLoader*>(threadData);
     MOZ_ASSERT(loader);
     loader->load();
 }
 
 void HRTFDatabaseLoader::load()
--- a/dom/plugins/base/android/ANPAudio.cpp
+++ b/dom/plugins/base/android/ANPAudio.cpp
@@ -117,16 +117,18 @@ public:
   }
 
   ANPAudioTrack* mTrack;
 };
 
 NS_IMETHODIMP
 AudioRunnable::Run()
 {
+  PR_SetCurrentThreadName("Android Audio");
+
   JNIEnv* const jenv = mozilla::jni::GetEnvForThread();
 
   mozilla::AutoLocalJNIFrame autoFrame(jenv, 2);
 
   jbyteArray bytearray = jenv->NewByteArray(mTrack->bufferSize);
   if (!bytearray) {
     LOG("AudioRunnable:: Run.  Could not create bytearray");
     return NS_ERROR_FAILURE;
@@ -314,17 +316,17 @@ anp_audio_start(ANPAudioTrack* s)
 
   s->isStopped = false;
   s->keepGoing = true;
 
   // AudioRunnable now owns the ANPAudioTrack
   RefPtr<AudioRunnable> runnable = new AudioRunnable(s);
 
   nsCOMPtr<nsIThread> thread;
-  NS_NewNamedThread("Android Audio", getter_AddRefs(thread), runnable);
+  NS_NewThread(getter_AddRefs(thread), runnable);
 }
 
 void
 anp_audio_pause(ANPAudioTrack* s)
 {
   if (s == nullptr || s->output_unit == nullptr) {
     return;
   }
--- a/dom/storage/DOMStorageDBThread.cpp
+++ b/dom/storage/DOMStorageDBThread.cpp
@@ -22,17 +22,16 @@
 #include "mozIStorageValueArray.h"
 #include "mozIStorageFunction.h"
 #include "mozilla/BasePrincipal.h"
 #include "nsIObserverService.h"
 #include "nsVariant.h"
 #include "mozilla/IOInterposer.h"
 #include "mozilla/Services.h"
 #include "mozilla/Tokenizer.h"
-#include "GeckoProfiler.h"
 
 // How long we collect write oprerations
 // before they are flushed to the database
 // In milliseconds.
 #define FLUSHING_INTERVAL_MS 5000
 
 // Write Ahead Log's maximum size is 512KB
 #define MAX_WAL_SIZE_BYTES 512 * 1024
@@ -333,17 +332,16 @@ DOMStorageDBThread::SetDefaultPriority()
   if (--mPriorityCounter <= 0) {
     PR_SetThreadPriority(mThread, PR_PRIORITY_LOW);
   }
 }
 
 void
 DOMStorageDBThread::ThreadFunc(void* aArg)
 {
-  AutoProfilerRegister registerThread("localStorage DB");
   PR_SetCurrentThreadName("localStorage DB");
   mozilla::IOInterposer::RegisterCurrentThread();
 
   DOMStorageDBThread* thread = static_cast<DOMStorageDBThread*>(aArg);
   thread->ThreadFunc();
   mozilla::IOInterposer::UnregisterCurrentThread();
 }
 
--- a/dom/system/gonk/GonkGPSGeolocationProvider.cpp
+++ b/dom/system/gonk/GonkGPSGeolocationProvider.cpp
@@ -551,17 +551,17 @@ GonkGPSGeolocationProvider::Startup()
     if (NS_FAILED(rv)) {
       NS_WARNING("geo: Gonk GPS AddObserver failed");
     } else {
       mObservingSettingsChange = true;
     }
   }
 
   if (!mInitThread) {
-    nsresult rv = NS_NewNamedThread("Gonk GPS", getter_AddRefs(mInitThread));
+    nsresult rv = NS_NewThread(getter_AddRefs(mInitThread));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   mInitThread->Dispatch(NewRunnableMethod(this, &GonkGPSGeolocationProvider::Init),
                         NS_DISPATCH_NORMAL);
 
   mNetworkLocationProvider = do_CreateInstance("@mozilla.org/geolocation/mls-provider;1");
   if (mNetworkLocationProvider) {
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -1564,17 +1564,17 @@ LayerScopeWebSocketManager::SocketHandle
 }
 
 // ----------------------------------------------
 // LayerScopeWebSocketManager implementation
 // ----------------------------------------------
 LayerScopeWebSocketManager::LayerScopeWebSocketManager()
     : mHandlerMutex("LayerScopeWebSocketManager::mHandlerMutex")
 {
-    NS_NewNamedThread("LayerScope", getter_AddRefs(mDebugSenderThread));
+    NS_NewThread(getter_AddRefs(mDebugSenderThread));
 
     mServerSocket = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID);
     int port = gfxPrefs::LayerScopePort();
     mServerSocket->Init(port, false, -1);
     mServerSocket->AsyncListen(new SocketListener);
 }
 
 LayerScopeWebSocketManager::~LayerScopeWebSocketManager()
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -390,17 +390,17 @@ void
 EnsureVibratorThreadInitialized()
 {
   if (sVibratorRunnable) {
     return;
   }
 
   sVibratorRunnable = new VibratorRunnable();
   nsCOMPtr<nsIThread> thread;
-  NS_NewNamedThread("Gonk Vibrator", getter_AddRefs(thread), sVibratorRunnable);
+  NS_NewThread(getter_AddRefs(thread), sVibratorRunnable);
 }
 
 } // namespace
 
 void
 Vibrate(const nsTArray<uint32_t> &pattern, const hal::WindowIdentifier &)
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/image/DecodePool.cpp
+++ b/image/DecodePool.cpp
@@ -55,16 +55,24 @@ public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(DecodePoolImpl)
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodePoolImpl)
 
   DecodePoolImpl()
     : mMonitor("DecodePoolImpl")
     , mShuttingDown(false)
   { }
 
+  /// Initialize the current thread for use by the decode pool.
+  void InitCurrentThread()
+  {
+    MOZ_ASSERT(!NS_IsMainThread());
+
+    mThreadNaming.SetThreadPoolName(NS_LITERAL_CSTRING("ImgDecoder"));
+  }
+
   /// Shut down the provided decode pool thread.
   static void ShutdownThread(nsIThread* aThisThread)
   {
     // Threads have to be shut down from another thread, so we'll ask the
     // main thread to do it for us.
     NS_DispatchToMainThread(NewRunnableMethod(aThisThread, &nsIThread::Shutdown));
   }
 
@@ -122,22 +130,16 @@ public:
         return work;
       }
 
       // Nothing to do; block until some work is available.
       mMonitor.Wait();
     } while (true);
   }
 
-  nsresult CreateThread(nsIThread** aThread, nsIRunnable* aInitialEvent)
-  {
-    return NS_NewNamedThread(mThreadNaming.GetNextThreadName("ImgDecoder"),
-                             aThread, aInitialEvent);
-  }
-
 private:
   ~DecodePoolImpl() { }
 
   Work PopWorkFromQueue(nsTArray<RefPtr<IDecodingTask>>& aQueue)
   {
     Work work;
     work.mType = Work::Type::TASK;
     work.mTask = aQueue.LastElement().forget();
@@ -159,21 +161,32 @@ class DecodePoolWorker : public Runnable
 {
 public:
   explicit DecodePoolWorker(DecodePoolImpl* aImpl)
     : mImpl(aImpl)
   { }
 
   NS_IMETHOD Run() override
   {
+#ifdef MOZ_ENABLE_PROFILER_SPS
+    char stackBaseGuess; // Need to be the first variable of main loop function.
+#endif // MOZ_ENABLE_PROFILER_SPS
+
     MOZ_ASSERT(!NS_IsMainThread());
 
+    mImpl->InitCurrentThread();
+
     nsCOMPtr<nsIThread> thisThread;
     nsThreadManager::get().GetCurrentThread(getter_AddRefs(thisThread));
 
+#ifdef MOZ_ENABLE_PROFILER_SPS
+    // InitCurrentThread() has assigned the thread name.
+    profiler_register_thread(PR_GetThreadName(PR_GetCurrentThread()), &stackBaseGuess);
+#endif // MOZ_ENABLE_PROFILER_SPS
+
     do {
       Work work = mImpl->PopWork();
       switch (work.mType) {
         case Work::Type::TASK:
           work.mTask->Run();
           break;
 
         case Work::Type::SHUTDOWN:
@@ -254,17 +267,17 @@ DecodePool::DecodePool()
   if (limit > 4 && XRE_IsParentProcess() && BrowserTabsRemoteAutostart()) {
     limit = 4;
   }
 
   // Initialize the thread pool.
   for (uint32_t i = 0 ; i < limit ; ++i) {
     nsCOMPtr<nsIRunnable> worker = new DecodePoolWorker(mImpl);
     nsCOMPtr<nsIThread> thread;
-    nsresult rv = mImpl->CreateThread(getter_AddRefs(thread), worker);
+    nsresult rv = NS_NewThread(getter_AddRefs(thread), worker);
     MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && thread,
                        "Should successfully create image decoding threads");
     mThreads.AppendElement(Move(thread));
   }
 
   // Initialize the I/O thread.
   nsresult rv = NS_NewNamedThread("ImageIO", getter_AddRefs(mIOThread));
   MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mIOThread,
--- a/image/test/gtest/TestDecodeToSurface.cpp
+++ b/image/test/gtest/TestDecodeToSurface.cpp
@@ -64,18 +64,17 @@ private:
 
 static void
 RunDecodeToSurface(const ImageTestCase& aTestCase)
 {
   nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
   ASSERT_TRUE(inputStream != nullptr);
 
   nsCOMPtr<nsIThread> thread;
-  nsresult rv =
-    NS_NewNamedThread("DecodeToSurface", getter_AddRefs(thread), nullptr);
+  nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   // We run the DecodeToSurface tests off-main-thread to ensure that
   // DecodeToSurface doesn't require any main-thread-only code.
   RefPtr<SourceSurface> surface;
   nsCOMPtr<nsIRunnable> runnable =
     new DecodeToSurfaceRunnable(surface, inputStream, aTestCase);
   thread->Dispatch(runnable, nsIThread::DISPATCH_SYNC);
--- a/ipc/chromium/src/base/thread.cc
+++ b/ipc/chromium/src/base/thread.cc
@@ -148,17 +148,18 @@ void Thread::StopSoon() {
   // to someone calling Quit() on our message loop directly.
   DCHECK(message_loop_);
 
   RefPtr<ThreadQuitTask> task = new ThreadQuitTask();
   message_loop_->PostTask(task.forget());
 }
 
 void Thread::ThreadMain() {
-  mozilla::AutoProfilerRegister registerThread(name_.c_str());
+  char aLocal;
+  profiler_register_thread(name_.c_str(), &aLocal);
   mozilla::IOInterposer::RegisterCurrentThread();
 
   // The message loop for this thread.
   MessageLoop message_loop(startup_data_->options.message_loop_type,
                            NS_GetCurrentThread());
 
   // Complete the initialization of our Thread object.
   thread_id_ = PlatformThread::CurrentId();
@@ -180,16 +181,17 @@ void Thread::ThreadMain() {
 
   // Let the thread do extra cleanup.
   CleanUp();
 
   // Assert that MessageLoop::Quit was called by ThreadQuitTask.
   DCHECK(GetThreadWasQuitProperly());
 
   mozilla::IOInterposer::UnregisterCurrentThread();
+  profiler_unregister_thread();
 
 #ifdef MOZ_TASK_TRACER
   mozilla::tasktracer::FreeTraceInfo();
 #endif
 
   // We can't receive messages anymore.
   message_loop_ = NULL;
   thread_id_ = 0;
--- a/ipc/glue/BackgroundImpl.cpp
+++ b/ipc/glue/BackgroundImpl.cpp
@@ -1339,16 +1339,18 @@ ParentImpl::ShutdownObserver::Observe(ns
 }
 
 NS_IMETHODIMP
 ParentImpl::RequestMessageLoopRunnable::Run()
 {
   AssertIsInMainProcess();
   MOZ_ASSERT(mTargetThread);
 
+  char stackBaseGuess;
+
   if (NS_IsMainThread()) {
     MOZ_ASSERT(mMessageLoop);
 
     if (!sBackgroundThread ||
         !SameCOMIdentity(mTargetThread.get(), sBackgroundThread.get())) {
       return NS_OK;
     }
 
@@ -1368,16 +1370,18 @@ ParentImpl::RequestMessageLoopRunnable::
           NS_WARNING("Failed to dispatch callback runnable!");
         }
       }
     }
 
     return NS_OK;
   }
 
+  profiler_register_thread("IPDL Background", &stackBaseGuess);
+
 #ifdef DEBUG
   {
     bool correctThread;
     MOZ_ASSERT(NS_SUCCEEDED(mTargetThread->IsOnCurrentThread(&correctThread)));
     MOZ_ASSERT(correctThread);
   }
 #endif
 
@@ -1405,16 +1409,18 @@ ParentImpl::ShutdownBackgroundThreadRunn
 {
   AssertIsInMainProcess();
 
   // It is possible that another background thread was created while this thread
   // was shutting down. In that case we can't assert anything about
   // sBackgroundPRThread and we should not modify it here.
   sBackgroundPRThread.compareExchange(PR_GetCurrentThread(), nullptr);
 
+  profiler_unregister_thread();
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ParentImpl::ForceCloseBackgroundActorsRunnable::Run()
 {
   AssertIsInMainProcess();
   MOZ_ASSERT(mActorArray);
--- a/js/xpconnect/src/XPCJSContext.cpp
+++ b/js/xpconnect/src/XPCJSContext.cpp
@@ -1161,17 +1161,16 @@ AutoLockWatchdog::AutoLockWatchdog(Watch
 AutoLockWatchdog::~AutoLockWatchdog()
 {
     PR_Unlock(mWatchdog->GetLock());
 }
 
 static void
 WatchdogMain(void* arg)
 {
-    mozilla::AutoProfilerRegister registerThread("JS Watchdog");
     PR_SetCurrentThreadName("JS Watchdog");
 
     Watchdog* self = static_cast<Watchdog*>(arg);
     WatchdogManager* manager = self->Manager();
 
     // Lock lasts until we return
     AutoLockWatchdog lock(self);
 
--- a/media/mtransport/nr_socket_prsock.cpp
+++ b/media/mtransport/nr_socket_prsock.cpp
@@ -207,19 +207,20 @@ public:
    */
   MozExternalRefCountType AddUse()
   {
     MOZ_ASSERT(mParentThread == NS_GetCurrentThread());
     MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt");
     nsrefcnt count = ++mUseCount;
     if (count == 1) {
       // idle -> in-use
-      nsresult rv = NS_NewNamedThread(mName, getter_AddRefs(mThread));
+      nsresult rv = NS_NewThread(getter_AddRefs(mThread));
       MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mThread,
                          "Should successfully create mtransport I/O thread");
+      NS_SetThreadName(mThread, mName);
       r_log(LOG_GENERIC,LOG_DEBUG,"Created wrapped SingletonThread %p",
             mThread.get());
     }
     r_log(LOG_GENERIC,LOG_DEBUG,"AddUse: %lu", (unsigned long) count);
     return count;
   }
 
   MozExternalRefCountType ReleaseUse()
--- a/netwerk/base/BackgroundFileSaver.cpp
+++ b/netwerk/base/BackgroundFileSaver.cpp
@@ -147,17 +147,17 @@ BackgroundFileSaver::Init()
   rv = NS_NewPipe2(getter_AddRefs(mPipeInputStream),
                    getter_AddRefs(mPipeOutputStream), true, true, 0,
                    HasInfiniteBuffer() ? UINT32_MAX : 0);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = NS_GetCurrentThread(getter_AddRefs(mControlThread));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = NS_NewNamedThread("BgFileSaver", getter_AddRefs(mWorkerThread));
+  rv = NS_NewThread(getter_AddRefs(mWorkerThread));
   NS_ENSURE_SUCCESS(rv, rv);
 
   sThreadCount++;
   if (sThreadCount > sTelemetryMaxThreadCount) {
     sTelemetryMaxThreadCount = sThreadCount;
   }
 
   return NS_OK;
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -737,21 +737,33 @@ nsPACMan::AsyncOnChannelRedirect(nsIChan
   // However do track the most recent URI in the redirect change
   // as mPACURIRedirectSpec so that URI can be allowed to bypass
   // the proxy and actually fetch the pac file.
 
   callback->OnRedirectVerifyCallback(NS_OK);
   return NS_OK;
 }
 
+void
+nsPACMan::NamePACThread()
+{
+  MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
+  PR_SetCurrentThreadName("Proxy Resolution");
+}
+
 nsresult
 nsPACMan::Init(nsISystemProxySettings *systemProxySettings)
 {
   mSystemProxySettings = systemProxySettings;
 
-  nsresult rv =
-    NS_NewNamedThread("ProxyResolution", getter_AddRefs(mPACThread));
+  nsresult rv = NS_NewThread(getter_AddRefs(mPACThread), nullptr);
+  if (NS_FAILED(rv))
+    return rv;
 
-  return rv;
+  // don't check return value as it is not a big deal for this to fail.
+  mPACThread->Dispatch(NewRunnableMethod(this, &nsPACMan::NamePACThread),
+                       nsIEventTarget::DISPATCH_NORMAL);
+
+  return NS_OK;
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/base/nsPACMan.h
+++ b/netwerk/base/nsPACMan.h
@@ -209,16 +209,17 @@ private:
    * execute the queue if it was otherwise empty
    */
   nsresult PostQuery(PendingPACQuery *query);
 
   // PAC thread operations only
   void PostProcessPendingQ();
   void PostCancelPendingQ(nsresult);
   bool ProcessPending();
+  void NamePACThread();
 
 private:
   ProxyAutoConfig mPAC;
   nsCOMPtr<nsIThread>           mPACThread;
   nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
 
   LinkedList<PendingPACQuery> mPendingQ; /* pac thread only */
 
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -828,16 +828,21 @@ void
 nsSocketTransportService::MarkTheLastElementOfPendingQueue()
 {
     mServingPendingQueue = false;
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::Run()
 {
+#ifdef MOZ_ENABLE_PROFILER_SPS
+    char stackBaseGuess; // Need to be the first variable of main loop function.
+    profiler_register_thread(PR_GetThreadName(PR_GetCurrentThread()), &stackBaseGuess);
+#endif // MOZ_ENABLE_PROFILER_SPS
+
     SOCKET_LOG(("STS thread init %d sockets\n", gMaxCount));
 
     psm::InitializeSSLServerCertVerificationThreads();
 
     gSocketThread = PR_GetCurrentThread();
 
     {
         MutexAutoLock lock(mLock);
@@ -1009,16 +1014,20 @@ nsSocketTransportService::Run()
     NS_ProcessPendingEvents(mRawThread);
 
     gSocketThread = nullptr;
 
     psm::StopSSLServerCertVerificationThreads();
 
     SOCKET_LOG(("STS thread exit\n"));
 
+#ifdef MOZ_ENABLE_PROFILER_SPS
+    profiler_unregister_thread();
+#endif // MOZ_ENABLE_PROFILER_SPS
+
     return NS_OK;
 }
 
 void
 nsSocketTransportService::DetachSocketWithGuard(bool aGuardLocals,
                                                 SocketContext *socketList,
                                                 int32_t index)
 {
--- a/netwerk/cache2/CacheIOThread.cpp
+++ b/netwerk/cache2/CacheIOThread.cpp
@@ -5,17 +5,16 @@
 #include "CacheIOThread.h"
 #include "CacheFileIOManager.h"
 
 #include "nsIRunnable.h"
 #include "nsISupportsImpl.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
 #include "mozilla/IOInterposer.h"
-#include "GeckoProfiler.h"
 
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 #ifdef MOZ_TASK_TRACER
 #include "GeckoTaskTracer.h"
 #include "TracedTaskCommon.h"
@@ -433,17 +432,16 @@ already_AddRefed<nsIEventTarget> CacheIO
   }
 
   return target.forget();
 }
 
 // static
 void CacheIOThread::ThreadFunc(void* aClosure)
 {
-  AutoProfilerRegister registerThread("Cache2 I/O");
   PR_SetCurrentThreadName("Cache2 I/O");
   mozilla::IOInterposer::RegisterCurrentThread();
   CacheIOThread* thread = static_cast<CacheIOThread*>(aClosure);
   thread->ThreadFunc();
   mozilla::IOInterposer::UnregisterCurrentThread();
 }
 
 void CacheIOThread::ThreadFunc()
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -24,17 +24,16 @@
 #include "prerror.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
 #include "PLDHashTable.h"
 #include "plstr.h"
 #include "nsURLHelper.h"
 #include "nsThreadUtils.h"
 #include "GetAddrInfo.h"
-#include "GeckoProfiler.h"
 
 #include "mozilla/HashFunctions.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
@@ -1431,25 +1430,20 @@ nsHostResolver::SizeOfIncludingThis(Mall
     //   |mDB| is measured.
 
     return n;
 }
 
 void
 nsHostResolver::ThreadFunc(void *arg)
 {
-    char stackTop;
-
     LOG(("DNS lookup thread - starting execution.\n"));
 
     static nsThreadPoolNaming naming;
-    nsCString name = naming.GetNextThreadName("DNS Resolver");
-
-    PR_SetCurrentThreadName(name.BeginReading());
-    profiler_register_thread(name.BeginReading(), &stackTop);
+    naming.SetThreadPoolName(NS_LITERAL_CSTRING("DNS Resolver"));
 
 #if defined(RES_RETRY_ON_FAILURE)
     nsResState rs;
 #endif
     nsHostResolver *resolver = (nsHostResolver *)arg;
     nsHostRecord *rec  = nullptr;
     AddrInfo *ai = nullptr;
 
@@ -1510,18 +1504,16 @@ nsHostResolver::ThreadFunc(void *arg)
                  LOG_HOST(rec->host, rec->netInterface)));
         } else {
             rec = nullptr;
         }
     }
     resolver->mThreadCount--;
     NS_RELEASE(resolver);
     LOG(("DNS lookup thread - queue empty, thread finished.\n"));
-
-    profiler_unregister_thread();
 }
 
 nsresult
 nsHostResolver::Create(uint32_t maxCacheEntries,
                        uint32_t defaultCacheEntryLifetime,
                        uint32_t defaultGracePeriod,
                        nsHostResolver **result)
 {
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -2321,19 +2321,18 @@ private:
 
 int32_t
 DataChannelConnection::SendBlob(uint16_t stream, nsIInputStream *aBlob)
 {
   DataChannel *channel = mStreams[stream];
   NS_ENSURE_TRUE(channel, 0);
   // Spawn a thread to send the data
   if (!mInternalIOThread) {
-    nsresult rv = NS_NewNamedThread("DataChannel IO",
-                                    getter_AddRefs(mInternalIOThread));
-    if (NS_FAILED(rv)) {
+    nsresult res = NS_NewThread(getter_AddRefs(mInternalIOThread));
+    if (NS_FAILED(res)) {
       return -1;
     }
   }
 
   mInternalIOThread->Dispatch(do_AddRef(new ReadBlobRunnable(this, stream, aBlob)), NS_DISPATCH_NORMAL);
   return 0;
 }
 
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -318,16 +318,18 @@ nsNotifyAddrListener::nextCoalesceWaitTi
         return static_cast<DWORD>
             (kNetworkChangeCoalescingPeriod - period);
     }
 }
 
 NS_IMETHODIMP
 nsNotifyAddrListener::Run()
 {
+    PR_SetCurrentThreadName("Link Monitor");
+
     mStartTime = TimeStamp::Now();
 
     calculateNetworkId();
 
     DWORD waitTime = INFINITE;
 
     if (!sNotifyIpInterfaceChange || !sCancelMibChangeNotify2 || !mIPv6Changes) {
         // For Windows versions which are older than Vista which lack
@@ -414,17 +416,17 @@ nsNotifyAddrListener::Init(void)
     Preferences::AddBoolVarCache(&mAllowChangedEvent,
                                  NETWORK_NOTIFY_CHANGED_PREF, true);
     Preferences::AddBoolVarCache(&mIPv6Changes,
                                  NETWORK_NOTIFY_IPV6_PREF, false);
 
     mCheckEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
     NS_ENSURE_TRUE(mCheckEvent, NS_ERROR_OUT_OF_MEMORY);
 
-    rv = NS_NewNamedThread("Link Monitor", getter_AddRefs(mThread), this);
+    rv = NS_NewThread(getter_AddRefs(mThread), this);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }
 
 nsresult
 nsNotifyAddrListener::Shutdown(void)
 {
--- a/netwerk/test/TestFileInput2.cpp
+++ b/netwerk/test/TestFileInput2.cpp
@@ -310,17 +310,17 @@ protected:
     uint32_t            mBufferSize;
 };
 
 NS_IMPL_ISUPPORTS(FileChannelWorker, nsIRunnable)
 
 ////////////////////////////////////////////////////////////////////////////////
 
 void
-Test(CreateFun create, const char* name, uint32_t count,
+Test(CreateFun create, uint32_t count,
      nsIFile* inDirSpec, nsIFile* outDirSpec, uint32_t bufSize)
 {
     nsresult rv;
     uint32_t i;
 
     nsAutoCString inDir;
     nsAutoCString outDir;
     (void)inDirSpec->GetNativePath(inDir);
@@ -370,18 +370,17 @@ Test(CreateFun create, const char* name,
         nsCOMPtr<nsIThread> thread;
         nsCOMPtr<nsIRunnable> worker;
         rv = create(getter_AddRefs(worker), 
                     inSpec,
                     outSpec,
                     bufSize);
         if (NS_FAILED(rv)) goto done;
 
-        rv = NS_NewNamedThread(name, getter_AddRefs(thread),
-                               worker, 0, PR_JOINABLE_THREAD);
+        rv = NS_NewThread(getter_AddRefs(thread), worker, 0, PR_JOINABLE_THREAD);
         if (NS_FAILED(rv)) goto done;
 
         bool inserted = threads.InsertObjectAt(thread, i);
         NS_ASSERTION(inserted, "not inserted");
 
         i++;
     }
 
@@ -429,54 +428,52 @@ main(int argc, char* argv[])
         rv = NS_NewNativeLocalFile(nsDependentCString(inDir), false, getter_AddRefs(inDirFile));
         if (NS_FAILED(rv)) return rv;
 
         nsCOMPtr<nsIFile> outDirFile;
         rv = NS_NewNativeLocalFile(nsDependentCString(outDir), false, getter_AddRefs(outDirFile));
         if (NS_FAILED(rv)) return rv;
 
         CreateFun create = FileChannelWorker::Create;
-        const char* name = "FileChannelWorker";
         Test(create, 1, inDirFile, outDirFile, 16 * 1024);
 #if 1
         printf("FileChannelWorker *****************************\n");
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
 #endif
         create = FileSpecWorker::Create;
-        name = "FileSpecWorker";
         printf("FileSpecWorker ********************************\n");
 #if 1
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 16 * 1024);
 #endif
 #if 1
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
-        Test(create, name, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
+        Test(create, 20, inDirFile, outDirFile, 4 * 1024);
 #endif
     } // this scopes the nsCOMPtrs
     // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
     rv = NS_ShutdownXPCOM(nullptr);
     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
     return 0;
 }
 
--- a/netwerk/wifi/nsWifiMonitor.cpp
+++ b/netwerk/wifi/nsWifiMonitor.cpp
@@ -79,17 +79,17 @@ NS_IMETHODIMP nsWifiMonitor::StartWatchi
       // but if DoScan returns with an error before shutdown (i.e. !mKeepGoing)
       // then we will respawn the thread.
       LOG(("nsWifiMonitor::StartWatching %p restarting thread\n", this));
       mThreadComplete = false;
       mThread = nullptr;
   }
 
   if (!mThread) {
-    rv = NS_NewNamedThread("Wifi Monitor", getter_AddRefs(mThread), this);
+    rv = NS_NewThread(getter_AddRefs(mThread), this);
     if (NS_FAILED(rv))
       return rv;
   }
 
 
   mListeners.AppendElement(nsWifiListener(new nsMainThreadPtrHolder<nsIWifiListener>(aListener)));
 
   // tell ourselves that we have a new watcher.
@@ -150,16 +150,18 @@ NS_IMETHODIMP nsPassErrorToWifiListeners
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsWifiMonitor::Run()
 {
   LOG(("@@@@@ wifi monitor run called\n"));
 
+  PR_SetCurrentThreadName("Wifi Monitor");
+
   nsresult rv = DoScan();
   LOG(("@@@@@ wifi monitor run::doscan complete %x\n", rv));
 
   nsAutoPtr<WifiListenerArray> currentListeners;
   bool doError = false;
 
   {
       ReentrantMonitorAutoEnter mon(mReentrantMonitor);
--- a/security/manager/ssl/CryptoTask.cpp
+++ b/security/manager/ssl/CryptoTask.cpp
@@ -26,23 +26,23 @@ CryptoTask::Dispatch(const nsACString& t
 
   // Ensure that NSS is initialized, since presumably CalculateResult
   // will use NSS functions
   if (!EnsureNSSInitializedChromeOrContent()) {
     return NS_ERROR_FAILURE;
   }
 
   // Can't add 'this' as the event to run, since mThread may not be set yet
-  nsresult rv = NS_NewNamedThread(taskThreadName, getter_AddRefs(mThread),
-                                  nullptr,
-                                  nsIThreadManager::DEFAULT_STACK_SIZE);
+  nsresult rv = NS_NewThread(getter_AddRefs(mThread), nullptr,
+                             nsIThreadManager::DEFAULT_STACK_SIZE);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  NS_SetThreadName(mThread, taskThreadName);
   // Note: event must not null out mThread!
   return mThread->Dispatch(this, NS_DISPATCH_NORMAL);
 }
 
 NS_IMETHODIMP
 CryptoTask::Run()
 {
   if (!NS_IsMainThread()) {
--- a/security/manager/ssl/nsKeygenThread.cpp
+++ b/security/manager/ssl/nsKeygenThread.cpp
@@ -7,17 +7,16 @@
 #include "pk11func.h"
 #include "nsCOMPtr.h"
 #include "nsThreadUtils.h"
 #include "nsKeygenThread.h"
 #include "nsIObserver.h"
 #include "nsNSSShutDown.h"
 #include "PSMRunnable.h"
 #include "mozilla/DebugOnly.h"
-#include "GeckoProfiler.h"
 
 using namespace mozilla;
 using namespace mozilla::psm;
 
 NS_IMPL_ISUPPORTS(nsKeygenThread, nsIKeygenThread)
 
 
 nsKeygenThread::nsKeygenThread()
@@ -110,17 +109,16 @@ nsresult nsKeygenThread::ConsumeResult(
       rv = NS_ERROR_FAILURE;
     }
   
   return rv;
 }
 
 static void nsKeygenThreadRunner(void *arg)
 {
-  AutoProfilerRegister registerThread("Keygen");
   PR_SetCurrentThreadName("Keygen");
   nsKeygenThread *self = static_cast<nsKeygenThread *>(arg);
   self->Run();
 }
 
 nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver)
 {
   if (!NS_IsMainThread()) {
--- a/security/manager/ssl/nsProtectedAuthThread.cpp
+++ b/security/manager/ssl/nsProtectedAuthThread.cpp
@@ -6,26 +6,24 @@
 #include "mozilla/DebugOnly.h"
 #include "mozilla/RefPtr.h"
 #include "nsCOMPtr.h"
 #include "PSMRunnable.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsPKCS11Slot.h"
 #include "nsProtectedAuthThread.h"
-#include "GeckoProfiler.h"
 
 using namespace mozilla;
 using namespace mozilla::psm;
 
 NS_IMPL_ISUPPORTS(nsProtectedAuthThread, nsIProtectedAuthThread)
 
 static void nsProtectedAuthThreadRunner(void *arg)
 {
-    AutoProfilerRegister registerThread("Protected Auth");
     PR_SetCurrentThreadName("Protected Auth");
 
     nsProtectedAuthThread *self = static_cast<nsProtectedAuthThread *>(arg);
     self->Run();
 }
 
 nsProtectedAuthThread::nsProtectedAuthThread()
 : mMutex("nsProtectedAuthThread.mMutex")
--- a/security/manager/ssl/nsSmartCardMonitor.cpp
+++ b/security/manager/ssl/nsSmartCardMonitor.cpp
@@ -5,17 +5,16 @@
 #include "nsSmartCardMonitor.h"
 
 #include "ScopedNSSTypes.h"
 #include "mozilla/Services.h"
 #include "mozilla/Unused.h"
 #include "nsIObserverService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
-#include "GeckoProfiler.h"
 #include "nspr.h"
 #include "pk11func.h"
 
 using namespace mozilla;
 
 //
 // The SmartCard monitoring thread should start up for each module we load
 // that has removable tokens. This code calls an NSS function which waits
@@ -386,13 +385,12 @@ void SmartCardMonitoringThread::Execute(
 const SECMODModule* SmartCardMonitoringThread::GetModule()
 {
   return mModule;
 }
 
 // C-like calling sequence to glue into PR_CreateThread.
 void SmartCardMonitoringThread::LaunchExecute(void* arg)
 {
-  AutoProfilerRegister registerThread("SmartCard");
   PR_SetCurrentThreadName("SmartCard");
 
   ((SmartCardMonitoringThread*)arg)->Execute();
 }
--- a/startupcache/StartupCache.cpp
+++ b/startupcache/StartupCache.cpp
@@ -31,17 +31,16 @@
 #include "nsWeakReference.h"
 #include "nsZipArchive.h"
 #include "mozilla/Omnijar.h"
 #include "prenv.h"
 #include "mozilla/Telemetry.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsIProtocolHandler.h"
-#include "GeckoProfiler.h"
 
 #ifdef IS_BIG_ENDIAN
 #define SC_ENDIAN "big"
 #else
 #define SC_ENDIAN "little"
 #endif
 
 #if PR_BYTES_PER_WORD == 4
@@ -499,17 +498,16 @@ StartupCache::WaitOnWriteThread()
 
   PR_JoinThread(mWriteThread);
   mWriteThread = nullptr;
 }
 
 void
 StartupCache::ThreadedWrite(void *aClosure)
 {
-  AutoProfilerRegister registerThread("StartupCache");
   PR_SetCurrentThreadName("StartupCache");
   mozilla::IOInterposer::RegisterCurrentThread();
   /*
    * It is safe to use the pointer passed in aClosure to reference the
    * StartupCache object because the thread's lifetime is tightly coupled to
    * the lifetime of the StartupCache object; this thread is joined in the
    * StartupCache destructor, guaranteeing that this function runs if and only
    * if the StartupCache object is valid.
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -584,23 +584,24 @@ Connection::getAsyncExecutionTarget()
   MutexAutoLock lockedScope(sharedAsyncExecutionMutex);
 
   // If we are shutting down the asynchronous thread, don't hand out any more
   // references to the thread.
   if (mAsyncExecutionThreadShuttingDown)
     return nullptr;
 
   if (!mAsyncExecutionThread) {
-    static nsThreadPoolNaming naming;
-    nsresult rv = NS_NewNamedThread(naming.GetNextThreadName("mozStorage"),
-                                    getter_AddRefs(mAsyncExecutionThread));
+    nsresult rv = ::NS_NewThread(getter_AddRefs(mAsyncExecutionThread));
     if (NS_FAILED(rv)) {
       NS_WARNING("Failed to create async thread.");
       return nullptr;
     }
+    static nsThreadPoolNaming naming;
+    naming.SetThreadPoolName(NS_LITERAL_CSTRING("mozStorage"),
+                             mAsyncExecutionThread);
   }
 
 #ifdef DEBUG
   mAsyncExecutionThreadIsAlive = true;
 #endif
 
   return mAsyncExecutionThread;
 }
--- a/storage/test/gtest/test_service_init_background_thread.cpp
+++ b/storage/test/gtest/test_service_init_background_thread.cpp
@@ -41,16 +41,16 @@ public:
 // a death test -- even though it doesn't use any of the normal death test
 // features -- which ensures this is the first storage test to run.
 TEST(storage_service_init_background_thread_DeathTest, Test)
 {
   nsCOMPtr<nsIRunnable> event = new ServiceInitializer();
   do_check_true(event);
 
   nsCOMPtr<nsIThread> thread;
-  do_check_success(NS_NewNamedThread("StorageService", getter_AddRefs(thread)));
+  do_check_success(NS_NewThread(getter_AddRefs(thread)));
 
   do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL));
 
   // Shutting down the thread will spin the event loop until all work in its
   // event queue is completed.  This will act as our thread synchronization.
   do_check_success(thread->Shutdown());
 }
--- a/toolkit/components/filewatcher/NativeFileWatcherWin.cpp
+++ b/toolkit/components/filewatcher/NativeFileWatcherWin.cpp
@@ -1248,25 +1248,27 @@ NativeFileWatcherService::Init()
   if (!observerService) {
     return NS_ERROR_FAILURE;
   }
 
   observerService->AddObserver(this, "xpcom-shutdown-threads", false);
 
   // Start the IO worker thread.
   mWorkerIORunnable = new NativeFileWatcherIOTask(completionPort);
-  nsresult rv = NS_NewNamedThread("FileWatcher IO", getter_AddRefs(mIOThread),
-                                  mWorkerIORunnable);
+  nsresult rv = NS_NewThread(getter_AddRefs(mIOThread), mWorkerIORunnable);
   if (NS_FAILED(rv)) {
     FILEWATCHERLOG(
       "NativeFileWatcherIOTask::Init - Unable to create and dispatch the worker thread (%x).",
       rv);
     return rv;
   }
 
+  // Set the name for the worker thread.
+  NS_SetThreadName(mIOThread, "FileWatcher IO");
+
   mIOCompletionPort = completionPort.forget();
 
   return NS_OK;
 }
 
 /**
  * Watches a path for changes: monitors the creations, name changes and
  * content changes to the files contained in the watched path.
--- a/toolkit/components/terminator/nsTerminator.cpp
+++ b/toolkit/components/terminator/nsTerminator.cpp
@@ -27,17 +27,16 @@
 #include "nsDirectoryServiceUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
 
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #if defined(MOZ_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #endif
-#include "GeckoProfiler.h"
 
 #if defined(XP_WIN)
 #include <windows.h>
 #else
 #include <unistd.h>
 #endif
 
 #include "mozilla/ArrayUtils.h"
@@ -120,17 +119,16 @@ struct Options {
 };
 
 /**
  * Entry point for the watchdog thread
  */
 void
 RunWatchdog(void* arg)
 {
-  AutoProfilerRegister registerThread("Shutdown Hang Terminator");
   PR_SetCurrentThreadName("Shutdown Hang Terminator");
 
   // Let's copy and deallocate options, that's one less leak to worry
   // about.
   UniquePtr<Options> options((Options*)arg);
   uint32_t crashAfterTicks = options->crashAfterTicks;
   options = nullptr;
 
@@ -211,17 +209,16 @@ public:
 // The data written by the writer thread will be read by another
 // module upon the next restart and fed to Telemetry.
 //
 Atomic<nsCString*> gWriteData(nullptr);
 PRMonitor* gWriteReady = nullptr;
 
 void RunWriter(void* arg)
 {
-  AutoProfilerRegister registerThread("Shutdown Statistics Writer");
   PR_SetCurrentThreadName("Shutdown Statistics Writer");
 
   MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(arg);
   // Shutdown will generally complete before we have a chance to
   // deallocate. This is not a leak.
 
   // Setup destinationPath and tmpFilePath
 
--- a/toolkit/components/url-classifier/tests/gtest/Common.cpp
+++ b/toolkit/components/url-classifier/tests/gtest/Common.cpp
@@ -9,18 +9,17 @@
 
 using namespace mozilla;
 using namespace mozilla::safebrowsing;
 
 template<typename Function>
 void RunTestInNewThread(Function&& aFunction) {
   nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(mozilla::Forward<Function>(aFunction));
   nsCOMPtr<nsIThread> testingThread;
-  nsresult rv =
-    NS_NewNamedThread("Testing Thread", getter_AddRefs(testingThread), r);
+  nsresult rv = NS_NewThread(getter_AddRefs(testingThread), r);
   ASSERT_EQ(rv, NS_OK);
   testingThread->Shutdown();
 }
 
 already_AddRefed<nsIFile>
 GetFile(const nsTArray<nsString>& path)
 {
   nsCOMPtr<nsIFile> file;
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -3604,17 +3604,17 @@ InjectCrashReporterIntoProcess(DWORD pro
 {
   if (!GetEnabled())
     return;
 
   if (!OOPInitialized())
     OOPInit();
 
   if (!sInjectorThread) {
-    if (NS_FAILED(NS_NewNamedThread("CrashRep Inject", &sInjectorThread)))
+    if (NS_FAILED(NS_NewThread(&sInjectorThread)))
       return;
   }
 
   {
     MutexAutoLock lock(*dumpMapLock);
     ChildProcessData* pd = pidToMinidump->PutEntry(processID);
     MOZ_ASSERT(!pd->minidump && !pd->callback);
     pd->callback = cb;
--- a/toolkit/identity/IdentityCryptoService.cpp
+++ b/toolkit/identity/IdentityCryptoService.cpp
@@ -200,18 +200,17 @@ IdentityCryptoService::GenerateKeyPair(
   } else if (keyTypeString.Equals(DSA_KEY_TYPE_STRING)) {
     keyType = dsaKey;
   } else {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsCOMPtr<nsIRunnable> r = new KeyGenRunnable(keyType, callback);
   nsCOMPtr<nsIThread> thread;
-  nsresult rv = NS_NewNamedThread("GenerateKeyPair", getter_AddRefs(thread),
-                                  r);
+  nsresult rv = NS_NewThread(getter_AddRefs(thread), r);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 IdentityCryptoService::Base64UrlEncode(const nsACString & utf8Input,
                                        nsACString & result)
@@ -305,17 +304,17 @@ NS_IMETHODIMP
 KeyPair::Sign(const nsACString & textToSign,
               nsIIdentitySignCallback* callback)
 {
   MOZ_ASSERT(NS_IsMainThread());
   nsCOMPtr<nsIRunnable> r = new SignRunnable(textToSign, mPrivateKey,
                                              callback);
 
   nsCOMPtr<nsIThread> thread;
-  nsresult rv = NS_NewNamedThread("KeyPair Sign", getter_AddRefs(thread), r);
+  nsresult rv = NS_NewThread(getter_AddRefs(thread), r);
   return rv;
 }
 
 KeyGenRunnable::KeyGenRunnable(KeyType keyType,
                                nsIIdentityKeyGenCallback * callback)
   : mKeyType(keyType)
   , mCallback(new nsMainThreadPtrHolder<nsIIdentityKeyGenCallback>(callback))
   , mRv(NS_ERROR_NOT_INITIALIZED)
--- a/toolkit/xre/EventTracer.cpp
+++ b/toolkit/xre/EventTracer.cpp
@@ -117,17 +117,16 @@ class EventLoopLagDispatcher : public Ru
  * it will not send another event until the previous response is received.
  *
  * The output defaults to stdout, but can be redirected to a file by
  * settting the environment variable MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT
  * to the name of a file to use.
  */
 void TracerThread(void *arg)
 {
-  AutoProfilerRegister registerThread("Event Tracer");
   PR_SetCurrentThreadName("Event Tracer");
 
   TracerStartClosure* threadArgs = static_cast<TracerStartClosure*>(arg);
 
   // These are the defaults. They can be overridden by environment vars.
   // This should be set to the maximum latency we'd like to allow
   // for responsiveness.
   int32_t thresholdInterval = threadArgs->mThresholdInterval;
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -1241,18 +1241,17 @@ nsUpdateProcessor::ProcessUpdate(nsIUpda
       LOG(("Can't create nsIFile for OS apply to dir"));
       return rv;
     }
   }
 #endif
 
   MOZ_ASSERT(NS_IsMainThread(), "not main thread");
   nsCOMPtr<nsIRunnable> r = NewRunnableMethod(this, &nsUpdateProcessor::StartStagedUpdate);
-  return NS_NewNamedThread("Update Watcher", getter_AddRefs(mProcessWatcher),
-                           r);
+  return NS_NewThread(getter_AddRefs(mProcessWatcher), r);
 }
 
 
 
 void
 nsUpdateProcessor::StartStagedUpdate()
 {
   MOZ_ASSERT(!NS_IsMainThread(), "main thread");
--- a/tools/profiler/public/GeckoProfiler.h
+++ b/tools/profiler/public/GeckoProfiler.h
@@ -243,24 +243,16 @@ static inline void profiler_js_operation
 static inline double profiler_time() { return 0; }
 static inline double profiler_time(const mozilla::TimeStamp& aTime) { return 0; }
 
 static inline bool profiler_in_privacy_mode() { return false; }
 
 static inline void profiler_log(const char *str) {}
 static inline void profiler_log(const char *fmt, va_list args) {}
 
-class AutoProfilerRegister final MOZ_STACK_CLASS
-{
-  AutoProfilerRegister(const char* aName) {}
-private:
-  AutoProfilerRegister(const AutoProfilerRegister&) = delete;
-  AutoProfilerRegister& operator=(const AutoProfilerRegister&) = delete;
-};
-
 #else
 
 #include "GeckoProfilerImpl.h"
 
 #endif
 
 class MOZ_RAII GeckoProfilerInitRAII {
 public:
--- a/tools/profiler/public/GeckoProfilerImpl.h
+++ b/tools/profiler/public/GeckoProfilerImpl.h
@@ -456,36 +456,16 @@ public:
   ~SamplerStackFramePrintfRAII() {
     mozilla_sampler_call_exit(mHandle);
   }
 private:
   char mDest[SAMPLER_MAX_STRING];
   void* mHandle;
 };
 
-/**
- * Convenience class to register and unregister a thread with the profiler.
- * Needs to be the first object on the stack of the thread.
- */
-class MOZ_STACK_CLASS AutoProfilerRegister final
-{
-public:
-  explicit AutoProfilerRegister(const char* aName)
-  {
-    profiler_register_thread(aName, this);
-  }
-  ~AutoProfilerRegister()
-  {
-    profiler_unregister_thread();
-  }
-private:
-  AutoProfilerRegister(const AutoProfilerRegister&) = delete;
-  AutoProfilerRegister& operator=(const AutoProfilerRegister&) = delete;
-};
-
 } // namespace mozilla
 
 inline PseudoStack* mozilla_get_pseudo_stack(void)
 {
   if (!stack_key_initialized)
     return nullptr;
   return tlsPseudoStack.get();
 }
--- a/widget/windows/LSPAnnotator.cpp
+++ b/widget/windows/LSPAnnotator.cpp
@@ -146,13 +146,13 @@ LSPAnnotationGatherer::Run()
   return NS_OK;
 }
 
 void LSPAnnotate()
 {
   nsCOMPtr<nsIThread> thread;
   nsCOMPtr<nsIRunnable> runnable =
     do_QueryObject(new LSPAnnotationGatherer());
-  NS_NewNamedThread("LSP Annotate", getter_AddRefs(thread), runnable);
+  NS_NewThread(getter_AddRefs(thread), runnable);
 }
 
 } // namespace crashreporter
 } // namespace mozilla
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -236,19 +236,17 @@ NS_IMETHODIMP nsSound::PlaySystemSound(c
   ShutdownOldPlayerThread();
   PurgeLastSound();
 
   if (!NS_IsMozAliasSound(aSoundAlias)) {
     if (aSoundAlias.IsEmpty())
       return NS_OK;
     nsCOMPtr<nsIRunnable> player = new nsSoundPlayer(this, aSoundAlias);
     NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
-    nsresult rv =
-      NS_NewNamedThread("PlaySystemSound", getter_AddRefs(mPlayerThread),
-                        player);
+    nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player);
     NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
 
   uint32_t eventId;
   if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
@@ -296,13 +294,12 @@ NS_IMETHODIMP nsSound::PlayEventSound(ui
       // Win32 plays no sounds at NS_SYSSOUND_PROMPT_DIALOG and
       // NS_SYSSOUND_SELECT_DIALOG.
       return NS_OK;
   }
   NS_ASSERTION(sound, "sound is null");
 
   nsCOMPtr<nsIRunnable> player = new nsSoundPlayer(this, sound);
   NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
-  nsresult rv =
-    NS_NewNamedThread("PlayEventSound", getter_AddRefs(mPlayerThread), player);
+  nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
--- a/xpcom/build/MainThreadIOLogger.cpp
+++ b/xpcom/build/MainThreadIOLogger.cpp
@@ -109,17 +109,16 @@ MainThreadIOLoggerImpl::Init()
     return false;
   }
   return true;
 }
 
 /* static */ void
 MainThreadIOLoggerImpl::sIOThreadFunc(void* aArg)
 {
-  AutoProfilerRegister registerThread("MainThreadIOLogger");
   PR_SetCurrentThreadName("MainThreadIOLogger");
   MainThreadIOLoggerImpl* obj = static_cast<MainThreadIOLoggerImpl*>(aArg);
   obj->IOThreadFunc();
 }
 
 void
 MainThreadIOLoggerImpl::IOThreadFunc()
 {
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -90,35 +90,32 @@ IncrementalRunnable::SetDeadline(TimeSta
   // Do nothing
 }
 
 #endif  // XPCOM_GLUE_AVOID_NSPR
 
 //-----------------------------------------------------------------------------
 
 nsresult
-NS_NewNamedThread(const nsACString& aName,
-                  nsIThread** aResult,
-                  nsIRunnable* aEvent,
-                  uint32_t aStackSize)
+NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
 {
   nsCOMPtr<nsIThread> thread;
 #ifdef MOZILLA_INTERNAL_API
   nsresult rv =
-    nsThreadManager::get().nsThreadManager::NewNamedThread(aName, aStackSize,
-                                                           getter_AddRefs(thread));
+    nsThreadManager::get().nsThreadManager::NewThread(0, aStackSize,
+                                                      getter_AddRefs(thread));
 #else
   nsresult rv;
   nsCOMPtr<nsIThreadManager> mgr =
     do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  rv = mgr->NewNamedThread(aName, aStackSize, getter_AddRefs(thread));
+  rv = mgr->NewThread(0, aStackSize, getter_AddRefs(thread));
 #endif
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (aEvent) {
     rv = thread->Dispatch(aEvent, NS_DISPATCH_NORMAL);
     if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -127,22 +124,16 @@ NS_NewNamedThread(const nsACString& aNam
   }
 
   *aResult = nullptr;
   thread.swap(*aResult);
   return NS_OK;
 }
 
 nsresult
-NS_NewThread(nsIThread** aResult, nsIRunnable* aEvent, uint32_t aStackSize)
-{
-  return NS_NewNamedThread(NS_LITERAL_CSTRING(""), aResult, aEvent, aStackSize);
-}
-
-nsresult
 NS_GetCurrentThread(nsIThread** aResult)
 {
 #ifdef MOZILLA_INTERNAL_API
   return nsThreadManager::get().nsThreadManager::GetCurrentThread(aResult);
 #else
   nsresult rv;
   nsCOMPtr<nsIThreadManager> mgr =
     do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
@@ -385,32 +376,92 @@ NS_ProcessNextEvent(nsIThread* aThread, 
     }
     aThread = current.get();
   }
 #endif
   bool val;
   return NS_SUCCEEDED(aThread->ProcessNextEvent(aMayWait, &val)) && val;
 }
 
+#ifndef XPCOM_GLUE_AVOID_NSPR
+
+namespace {
+
+class nsNameThreadRunnable final : public nsIRunnable
+{
+  ~nsNameThreadRunnable() {}
+
+public:
+  explicit nsNameThreadRunnable(const nsACString& aName) : mName(aName) {}
+
+  NS_DECL_THREADSAFE_ISUPPORTS
+  NS_DECL_NSIRUNNABLE
+
+protected:
+  const nsCString mName;
+};
+
+NS_IMPL_ISUPPORTS(nsNameThreadRunnable, nsIRunnable)
+
+NS_IMETHODIMP
+nsNameThreadRunnable::Run()
+{
+  PR_SetCurrentThreadName(mName.BeginReading());
+  return NS_OK;
+}
+
+} // namespace
+
+void
+NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
+{
+  if (!aThread) {
+    return;
+  }
+
+  aThread->Dispatch(new nsNameThreadRunnable(aName),
+                    nsIEventTarget::DISPATCH_NORMAL);
+}
+
+#else // !XPCOM_GLUE_AVOID_NSPR
+
+void
+NS_SetThreadName(nsIThread* aThread, const nsACString& aName)
+{
+  // No NSPR, no love.
+}
+
+#endif
+
 #ifdef MOZILLA_INTERNAL_API
 nsIThread*
 NS_GetCurrentThread()
 {
   return nsThreadManager::get().GetCurrentThread();
 }
 #endif
 
 // nsThreadPoolNaming
-nsCString
-nsThreadPoolNaming::GetNextThreadName(const nsACString& aPoolName)
+void
+nsThreadPoolNaming::SetThreadPoolName(const nsACString& aPoolName,
+                                      nsIThread* aThread)
 {
   nsCString name(aPoolName);
   name.AppendLiteral(" #");
-  name.AppendInt(++mCounter, 10); // The counter is declared as atomic
-  return name;
+  name.AppendInt(++mCounter, 10); // The counter is declared as volatile
+
+  if (aThread) {
+    // Set on the target thread
+    NS_SetThreadName(aThread, name);
+  } else {
+    // Set on the current thread
+#ifndef XPCOM_GLUE_AVOID_NSPR
+    PR_SetCurrentThreadName(name.BeginReading());
+#endif
+  }
 }
 
 // nsAutoLowPriorityIO
 nsAutoLowPriorityIO::nsAutoLowPriorityIO()
 {
 #if defined(XP_WIN)
   lowIOPrioritySet = IsVistaOrLater() &&
                      SetThreadPriority(GetCurrentThread(),
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -28,16 +28,34 @@
 #include "mozilla/Tuple.h"
 #include "mozilla/TypeTraits.h"
 
 //-----------------------------------------------------------------------------
 // These methods are alternatives to the methods on nsIThreadManager, provided
 // for convenience.
 
 /**
+ * Set name of the target thread.  This operation is asynchronous.
+ */
+extern void NS_SetThreadName(nsIThread* aThread, const nsACString& aName);
+
+/**
+ * Static length version of the above function checking length of the
+ * name at compile time.
+ */
+template<size_t LEN>
+inline void
+NS_SetThreadName(nsIThread* aThread, const char (&aName)[LEN])
+{
+  static_assert(LEN <= 16,
+                "Thread name must be no more than 16 characters");
+  NS_SetThreadName(aThread, nsDependentCString(aName));
+}
+
+/**
  * Create a new thread, and optionally provide an initial event for the thread.
  *
  * @param aResult
  *   The resulting nsIThread object.
  * @param aInitialEvent
  *   The initial event to run on this thread.  This parameter may be null.
  * @param aStackSize
  *   The size in bytes to reserve for the thread's stack.
@@ -48,33 +66,38 @@
 extern nsresult
 NS_NewThread(nsIThread** aResult,
              nsIRunnable* aInitialEvent = nullptr,
              uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
 
 /**
  * Creates a named thread, otherwise the same as NS_NewThread
  */
-extern nsresult
-NS_NewNamedThread(const nsACString& aName,
-                  nsIThread** aResult,
-                  nsIRunnable* aInitialEvent = nullptr,
-                  uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE);
-
 template<size_t LEN>
 inline nsresult
 NS_NewNamedThread(const char (&aName)[LEN],
                   nsIThread** aResult,
                   nsIRunnable* aInitialEvent = nullptr,
                   uint32_t aStackSize = nsIThreadManager::DEFAULT_STACK_SIZE)
 {
-  static_assert(LEN <= 16,
-                "Thread name must be no more than 16 characters");
-  return NS_NewNamedThread(nsDependentCString(aName, LEN - 1),
-                           aResult, aInitialEvent, aStackSize);
+  // Hold a ref while dispatching the initial event to match NS_NewThread()
+  nsCOMPtr<nsIThread> thread;
+  nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr, aStackSize);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  NS_SetThreadName<LEN>(thread, aName);
+  if (aInitialEvent) {
+    rv = thread->Dispatch(aInitialEvent, NS_DISPATCH_NORMAL);
+    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Initial event dispatch failed");
+  }
+
+  *aResult = nullptr;
+  thread.swap(*aResult);
+  return rv;
 }
 
 /**
  * Get a reference to the current thread.
  *
  * @param aResult
  *   The resulting nsIThread object.
  */
@@ -998,25 +1021,22 @@ private:
  * with incremental numbers.
  */
 class nsThreadPoolNaming
 {
 public:
   nsThreadPoolNaming() : mCounter(0) {}
 
   /**
-   * Returns a thread name as "<aPoolName> #<n>" and increments the counter.
+   * Creates and sets next thread name as "<aPoolName> #<n>"
+   * on the specified thread.  If no thread is specified (aThread
+   * is null) then the name is synchronously set on the current thread.
    */
-  nsCString GetNextThreadName(const nsACString& aPoolName);
-
-  template<size_t LEN>
-  nsCString GetNextThreadName(const char (&aPoolName)[LEN])
-  {
-    return GetNextThreadName(nsDependentCString(aPoolName, LEN - 1));
-  }
+  void SetThreadPoolName(const nsACString& aPoolName,
+                         nsIThread* aThread = nullptr);
 
 private:
   mozilla::Atomic<uint32_t> mCounter;
 
   nsThreadPoolNaming(const nsThreadPoolNaming&) = delete;
   void operator=(const nsThreadPoolNaming&) = delete;
 };
 
--- a/xpcom/tests/gtest/TestPipes.cpp
+++ b/xpcom/tests/gtest/TestPipes.cpp
@@ -102,17 +102,17 @@ TestPipe(nsIInputStream* in, nsIOutputSt
 {
     RefPtr<nsReceiver> receiver = new nsReceiver(in);
     if (!receiver)
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsresult rv;
 
     nsCOMPtr<nsIThread> thread;
-    rv = NS_NewNamedThread("TestPipe", getter_AddRefs(thread), receiver);
+    rv = NS_NewThread(getter_AddRefs(thread), receiver);
     if (NS_FAILED(rv)) return rv;
 
     uint32_t total = 0;
     PRIntervalTime start = PR_IntervalNow();
     for (uint32_t i = 0; i < ITERATIONS; i++) {
         uint32_t writeCount;
         char *buf = PR_smprintf("%d %s", i, kTestPattern);
         uint32_t len = strlen(buf);
@@ -220,18 +220,17 @@ TestShortWrites(nsIInputStream* in, nsIO
 {
     RefPtr<nsShortReader> receiver = new nsShortReader(in);
     if (!receiver)
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsresult rv;
 
     nsCOMPtr<nsIThread> thread;
-    rv = NS_NewNamedThread("TestShortWrites", getter_AddRefs(thread),
-                           receiver);
+    rv = NS_NewThread(getter_AddRefs(thread), receiver);
     if (NS_FAILED(rv)) return rv;
 
     uint32_t total = 0;
     for (uint32_t i = 0; i < ITERATIONS; i++) {
         uint32_t writeCount;
         char* buf = PR_smprintf("%d %s", i, kTestPattern);
         uint32_t len = strlen(buf);
         len = len * rand() / RAND_MAX;
@@ -326,25 +325,24 @@ TEST(Pipes, ChainedPipes)
     nsCOMPtr<nsIOutputStream> out2;
     rv = NS_NewPipe(getter_AddRefs(in2), getter_AddRefs(out2), 200, 401);
     if (NS_FAILED(rv)) return;
 
     RefPtr<nsPump> pump = new nsPump(in1, out2);
     if (pump == nullptr) return;
 
     nsCOMPtr<nsIThread> thread;
-    rv = NS_NewNamedThread("ChainedPipePump", getter_AddRefs(thread), pump);
+    rv = NS_NewThread(getter_AddRefs(thread), pump);
     if (NS_FAILED(rv)) return;
 
     RefPtr<nsReceiver> receiver = new nsReceiver(in2);
     if (receiver == nullptr) return;
 
     nsCOMPtr<nsIThread> receiverThread;
-    rv = NS_NewNamedThread("ChainedPipeRecv", getter_AddRefs(receiverThread),
-                           receiver);
+    rv = NS_NewThread(getter_AddRefs(receiverThread), receiver);
     if (NS_FAILED(rv)) return;
 
     uint32_t total = 0;
     for (uint32_t i = 0; i < ITERATIONS; i++) {
         uint32_t writeCount;
         char* buf = PR_smprintf("%d %s", i, kTestPattern);
         uint32_t len = strlen(buf);
         len = len * rand() / RAND_MAX;
--- a/xpcom/tests/gtest/TestRacingServiceManager.cpp
+++ b/xpcom/tests/gtest/TestRacingServiceManager.cpp
@@ -250,17 +250,17 @@ TEST(RacingServiceManager, Test)
 
   AutoCreateAndDestroyReentrantMonitor mon1(&gReentrantMonitor);
 
   RefPtr<TestRunnable> runnable = new TestRunnable();
   ASSERT_TRUE(runnable);
 
   // Run the classID test
   nsCOMPtr<nsIThread> newThread;
-  rv = NS_NewNamedThread("RacingServMan", getter_AddRefs(newThread), runnable);
+  rv = NS_NewThread(getter_AddRefs(newThread), runnable);
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   {
     ReentrantMonitorAutoEnter mon2(*gReentrantMonitor);
 
     gMainThreadWaiting = true;
     mon2.Notify();
 
--- a/xpcom/tests/gtest/TestThreads.cpp
+++ b/xpcom/tests/gtest/TestThreads.cpp
@@ -44,17 +44,17 @@ NS_IMPL_ISUPPORTS(nsRunner, nsIRunnable)
 TEST(Threads, Main)
 {
     nsresult rv;
 
     nsCOMPtr<nsIRunnable> event = new nsRunner(0);
     EXPECT_TRUE(event);
 
     nsCOMPtr<nsIThread> runner;
-    rv = NS_NewNamedThread("TestThreadsMain", getter_AddRefs(runner), event);
+    rv = NS_NewThread(getter_AddRefs(runner), event);
     EXPECT_TRUE(NS_SUCCEEDED(rv));
 
     nsCOMPtr<nsIThread> thread;
     rv = NS_GetCurrentThread(getter_AddRefs(thread));
     EXPECT_TRUE(NS_SUCCEEDED(rv));
 
     rv = runner->Shutdown();     // wait for the runner to die before quitting
     EXPECT_TRUE(NS_SUCCEEDED(rv));
@@ -107,18 +107,17 @@ TEST(Threads, Stress)
 
         int k;
         nsIThread** array = new nsIThread*[threads];
 
         EXPECT_EQ(nsStressRunner::GetGlobalCount(), 0);
 
         for (k = 0; k < threads; k++) {
             nsCOMPtr<nsIThread> t;
-            nsresult rv = NS_NewNamedThread("StressRunner", getter_AddRefs(t),
-                                            new nsStressRunner(k));
+            nsresult rv = NS_NewThread(getter_AddRefs(t), new nsStressRunner(k));
             EXPECT_TRUE(NS_SUCCEEDED(rv));
             NS_ADDREF(array[k] = t);
         }
 
         for (k = threads-1; k >= 0; k--) {
             array[k]->Shutdown();
             NS_RELEASE(array[k]);    
         }
@@ -165,18 +164,17 @@ public:
         mWasRun = true;
 
         nsCOMPtr<nsIThread> t;
         nsresult rv;
 
         {
           mozilla::MonitorAutoLock lock(*gBeginAsyncShutdownMonitor);
 
-          rv = NS_NewNamedThread("AsyncShutdownPr", getter_AddRefs(t),
-                                 new AsyncShutdownPreparer());
+          rv = NS_NewThread(getter_AddRefs(t), new AsyncShutdownPreparer());
           EXPECT_TRUE(NS_SUCCEEDED(rv));
 
           lock.Wait();
         }
 
         rv = t->AsyncShutdown();
         EXPECT_TRUE(NS_SUCCEEDED(rv));
 
@@ -218,18 +216,17 @@ TEST(Threads, AsyncShutdown)
   gBeginAsyncShutdownMonitor = new mozilla::Monitor("gBeginAsyncShutdown");
 
   nsCOMPtr<nsIThread> t;
   nsresult rv;
 
   {
     mozilla::MonitorAutoLock lock(*gAsyncShutdownReadyMonitor);
 
-    rv = NS_NewNamedThread("AsyncShutdownWt", getter_AddRefs(t),
-                           new AsyncShutdownWaiter());
+    rv = NS_NewThread(getter_AddRefs(t), new AsyncShutdownWaiter());
     EXPECT_TRUE(NS_SUCCEEDED(rv));
 
     lock.Wait();
   }
 
   NS_DispatchToCurrentThread(new SameThreadSentinel());
   rv = t->Shutdown();
   EXPECT_TRUE(NS_SUCCEEDED(rv));
--- a/xpcom/tests/gtest/TestTimers.cpp
+++ b/xpcom/tests/gtest/TestTimers.cpp
@@ -26,17 +26,17 @@ using namespace mozilla;
 
 typedef nsresult(*TestFuncPtr)();
 
 class AutoTestThread
 {
 public:
   AutoTestThread() {
     nsCOMPtr<nsIThread> newThread;
-    nsresult rv = NS_NewNamedThread("AutoTestThread", getter_AddRefs(newThread));
+    nsresult rv = NS_NewThread(getter_AddRefs(newThread));
     if (NS_FAILED(rv))
       return;
 
     newThread.swap(mThread);
   }
 
   ~AutoTestThread() {
     mThread->Shutdown();
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -17,17 +17,16 @@
 
 #include "prinrval.h"
 #include "prthread.h"
 #include "ThreadStackHelper.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "nsXULAppAPI.h"
-#include "GeckoProfiler.h"
 
 #include <algorithm>
 
 // Activate BHR only for one every BHR_BETA_MOD users.
 // This is now 100% of Beta population for the Beta 45/46 e10s A/B trials
 // It can be scaled back again in the future
 #define BHR_BETA_MOD 1;
 
@@ -50,17 +49,16 @@ namespace mozilla {
  * manages all instances of BackgroundHangThread.
  */
 class BackgroundHangManager : public nsIObserver
 {
 private:
   // Background hang monitor thread function
   static void MonitorThread(void* aData)
   {
-    AutoProfilerRegister registerThread("BgHangMonitor");
     PR_SetCurrentThreadName("BgHangManager");
 
     /* We do not hold a reference to BackgroundHangManager here
        because the monitor thread only exists as long as the
        BackgroundHangManager instance exists. We stop the monitor
        thread in the BackgroundHangManager destructor, and we can
        only get to the destructor if we don't hold a reference here. */
     static_cast<BackgroundHangManager*>(aData)->RunMonitorThread();
--- a/xpcom/threads/HangMonitor.cpp
+++ b/xpcom/threads/HangMonitor.cpp
@@ -16,17 +16,16 @@
 #include "mozilla/UniquePtr.h"
 #include "nsReadableUtils.h"
 #include "mozilla/StackWalk.h"
 #ifdef _WIN64
 #include "mozilla/StackWalk_windows.h"
 #endif
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
-#include "GeckoProfiler.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 #ifdef XP_WIN
 #include <windows.h>
 #endif
@@ -205,17 +204,16 @@ GetChromeHangReport(Telemetry::Processed
   }
 }
 
 #endif
 
 void
 ThreadMain(void*)
 {
-  AutoProfilerRegister registerThread("Hang Monitor");
   PR_SetCurrentThreadName("Hang Monitor");
 
   MonitorAutoLock lock(*gMonitor);
 
   // In order to avoid issues with the hang monitor incorrectly triggering
   // during a general system stop such as sleeping, the monitor thread must
   // run twice to trigger hang protection.
   PRIntervalTime lastTimestamp = 0;
--- a/xpcom/threads/LazyIdleThread.cpp
+++ b/xpcom/threads/LazyIdleThread.cpp
@@ -164,27 +164,32 @@ LazyIdleThread::EnsureThread()
   }
 
   nsCOMPtr<nsIRunnable> runnable =
     NewRunnableMethod(this, &LazyIdleThread::InitThread);
   if (NS_WARN_IF(!runnable)) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  rv = NS_NewNamedThread("Lazy Idle", getter_AddRefs(mThread), runnable);
+  rv = NS_NewThread(getter_AddRefs(mThread), runnable);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 void
 LazyIdleThread::InitThread()
 {
+  char aLocal;
+  profiler_register_thread(mName.get(), &aLocal);
+
+  PR_SetCurrentThreadName(mName.get());
+
   // Happens on mThread but mThread may not be set yet...
 
   nsCOMPtr<nsIThreadInternal> thread(do_QueryInterface(NS_GetCurrentThread()));
   MOZ_ASSERT(thread, "This should always succeed!");
 
   if (NS_FAILED(thread->SetObserver(this))) {
     NS_WARNING("Failed to set thread observer!");
   }
@@ -201,16 +206,18 @@ LazyIdleThread::CleanupThread()
   }
 
   {
     MutexAutoLock lock(mMutex);
 
     MOZ_ASSERT(!mThreadIsShuttingDown, "Shouldn't be true ever!");
     mThreadIsShuttingDown = true;
   }
+
+  profiler_unregister_thread();
 }
 
 void
 LazyIdleThread::ScheduleTimer()
 {
   ASSERT_OWNING_THREAD();
 
   bool shouldSchedule;
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -318,18 +318,17 @@ TimerThread::Init()
 
     return NS_OK;
   }
 
   nsTimerEvent::Init();
 
   if (mInitInProgress.exchange(true) == false) {
     // We hold on to mThread to keep the thread alive.
-    nsresult rv =
-      NS_NewNamedThread("Timer Thread", getter_AddRefs(mThread), this);
+    nsresult rv = NS_NewThread(getter_AddRefs(mThread), this);
     if (NS_FAILED(rv)) {
       mThread = nullptr;
     } else {
       RefPtr<TimerObserverRunnable> r = new TimerObserverRunnable(this);
       if (NS_IsMainThread()) {
         r->Run();
       } else {
         NS_DispatchToMainThread(r);
--- a/xpcom/threads/nsIThreadManager.idl
+++ b/xpcom/threads/nsIThreadManager.idl
@@ -31,30 +31,16 @@ interface nsIThreadManager : nsISupports
    *   Number of bytes to reserve for the thread's stack.
    *
    * @returns
    *   The newly created nsIThread object.
    */
   nsIThread newThread(in unsigned long creationFlags, [optional] in unsigned long stackSize);
 
   /**
-   * Create a new thread (a global, user PRThread) with the specified name.
-   *
-   * @param name
-   *   The name of the thread. Passing an empty name is equivalent to
-   *   calling newThread(0, stackSize), i.e. the thread will not be named.
-   * @param stackSize
-   *   Number of bytes to reserve for the thread's stack.
-   *
-   * @returns
-   *   The newly created nsIThread object.
-   */
-  [noscript] nsIThread newNamedThread(in ACString name, [optional] in unsigned long stackSize);
-
-  /**
    * Get the nsIThread object (if any) corresponding to the given PRThread.
    * This method returns null if there is no corresponding nsIThread.
    *
    * @param prthread
    *   The PRThread of the nsIThread being requested.
    *
    * @returns
    *   The nsIThread object corresponding to the given PRThread or null if no
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -20,17 +20,16 @@
 #include "nsProcess.h"
 #include "prio.h"
 #include "prenv.h"
 #include "nsCRT.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/Services.h"
-#include "GeckoProfiler.h"
 
 #include <stdlib.h>
 
 #if defined(PROCESSMODEL_WINAPI)
 #include "prmem.h"
 #include "nsString.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
@@ -231,23 +230,20 @@ assembleCmdLine(char* const* aArgv, wcha
   PR_Free(cmdLine);
   return 0;
 }
 #endif
 
 void
 nsProcess::Monitor(void* aArg)
 {
-  char stackBaseGuess;
-
   RefPtr<nsProcess> process = dont_AddRef(static_cast<nsProcess*>(aArg));
 
   if (!process->mBlocking) {
     PR_SetCurrentThreadName("RunProcess");
-    profiler_register_thread("RunProcess", &stackBaseGuess);
   }
 
 #if defined(PROCESSMODEL_WINAPI)
   DWORD dwRetVal;
   unsigned long exitCode = -1;
 
   dwRetVal = WaitForSingleObject(process->mProcess, INFINITE);
   if (dwRetVal != WAIT_FAILED) {
@@ -303,20 +299,16 @@ nsProcess::Monitor(void* aArg)
 
   // If we ran a background thread for the monitor then notify on the main
   // thread
   if (NS_IsMainThread()) {
     process->ProcessComplete();
   } else {
     NS_DispatchToMainThread(NewRunnableMethod(process, &nsProcess::ProcessComplete));
   }
-
-  if (!process->mBlocking) {
-    profiler_unregister_thread();
-  }
 }
 
 void
 nsProcess::ProcessComplete()
 {
   if (mThread) {
     nsCOMPtr<nsIObserverService> os =
       mozilla::services::GetObserverService();
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -33,17 +33,16 @@
 #include "mozilla/ChaosMode.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsIIdlePeriod.h"
 #include "nsIIncrementalRunnable.h"
 #include "nsThreadSyncDispatch.h"
 #include "LeakRefPtr.h"
-#include "GeckoProfiler.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsServiceManagerUtils.h"
 #include "nsICrashReporter.h"
 #include "mozilla/dom/ContentChild.h"
 #endif
 
 #ifdef XP_LINUX
@@ -428,61 +427,39 @@ SetupCurrentThreadForChaosMode()
 #endif
 
   // Force half the threads to CPU 0 so they compete for CPU
   if (ChaosMode::randomUint32LessThan(2)) {
     SetThreadAffinity(0);
   }
 }
 
-namespace {
-
-struct ThreadInitData {
-  nsThread* thread;
-  const nsACString& name;
-};
-
-}
-
 /*static*/ void
 nsThread::ThreadFunc(void* aArg)
 {
   using mozilla::ipc::BackgroundChild;
 
-  char stackTop;
-
-  ThreadInitData* initData = static_cast<ThreadInitData*>(aArg);
-  nsThread* self = initData->thread;  // strong reference
-
+  nsThread* self = static_cast<nsThread*>(aArg);  // strong reference
   self->mThread = PR_GetCurrentThread();
   SetupCurrentThreadForChaosMode();
 
-  if (initData->name.Length() > 0) {
-    PR_SetCurrentThreadName(initData->name.BeginReading());
-
-    profiler_register_thread(initData->name.BeginReading(), &stackTop);
-  }
-
   // Inform the ThreadManager
   nsThreadManager::get().RegisterCurrentThread(*self);
 
   mozilla::IOInterposer::RegisterCurrentThread();
 
   // Wait for and process startup event
   nsCOMPtr<nsIRunnable> event;
   {
     MutexAutoLock lock(self->mLock);
     if (!self->mEvents->GetEvent(true, getter_AddRefs(event), lock)) {
       NS_WARNING("failed waiting for thread startup event");
       return;
     }
   }
-
-  initData = nullptr; // clear before unblocking nsThread::Init
-
   event->Run();  // unblocks nsThread::Init
   event = nullptr;
 
   {
     // Scope for MessageLoop.
     nsAutoPtr<MessageLoop> loop(
       new MessageLoop(MessageLoop::TYPE_MOZILLA_NONMAINTHREAD, self));
 
@@ -519,18 +496,16 @@ nsThread::ThreadFunc(void* aArg)
     }
   }
 
   mozilla::IOInterposer::UnregisterCurrentThread();
 
   // Inform the threadmanager that this thread is going away
   nsThreadManager::get().UnregisterCurrentThread(*self);
 
-  profiler_unregister_thread();
-
   // Dispatch shutdown ACK
   NotNull<nsThreadShutdownContext*> context =
     WrapNotNull(self->mShutdownContext);
   MOZ_ASSERT(context->mTerminatingThread == self);
   event = do_QueryObject(new nsThreadShutdownAckEvent(context));
   context->mJoiningThread->Dispatch(event, NS_DISPATCH_NORMAL);
 
   // Release any observer of the thread here.
@@ -648,31 +623,29 @@ nsThread::~nsThread()
   // the leak.
   for (size_t i = 0; i < mRequestedShutdownContexts.Length(); ++i) {
     Unused << mRequestedShutdownContexts[i].forget();
   }
 #endif
 }
 
 nsresult
-nsThread::Init(const nsACString& aName)
+nsThread::Init()
 {
   // spawn thread and wait until it is fully setup
   RefPtr<nsThreadStartupEvent> startup = new nsThreadStartupEvent();
 
   NS_ADDREF_THIS();
 
   mIdlePeriod = new IdlePeriod();
 
   mShutdownRequired = true;
 
-  ThreadInitData initData = { this, aName };
-
   // ThreadFunc is responsible for setting mThread
-  if (!PR_CreateThread(PR_USER_THREAD, ThreadFunc, &initData,
+  if (!PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
                        PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                        PR_JOINABLE_THREAD, mStackSize)) {
     NS_RELEASE_THIS();
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // ThreadFunc will wait for this event to be run before it tries to access
   // mThread.  By delaying insertion of this event into the queue, we ensure
--- a/xpcom/threads/nsThread.h
+++ b/xpcom/threads/nsThread.h
@@ -43,18 +43,18 @@ public:
   enum MainThreadFlag
   {
     MAIN_THREAD,
     NOT_MAIN_THREAD
   };
 
   nsThread(MainThreadFlag aMainThread, uint32_t aStackSize);
 
-  // Initialize this as a wrapper for a new PRThread, and optionally give it a name.
-  nsresult Init(const nsACString& aName = NS_LITERAL_CSTRING(""));
+  // Initialize this as a wrapper for a new PRThread.
+  nsresult Init();
 
   // Initialize this as a wrapper for the current PRThread.
   nsresult InitCurrentThread();
 
   // The PRThread corresponding to this thread.
   PRThread* GetPRThread()
   {
     return mThread;
--- a/xpcom/threads/nsThreadManager.cpp
+++ b/xpcom/threads/nsThreadManager.cpp
@@ -244,33 +244,25 @@ nsThreadManager::GetCurrentThread()
   return thread.get();  // reference held in TLS
 }
 
 NS_IMETHODIMP
 nsThreadManager::NewThread(uint32_t aCreationFlags,
                            uint32_t aStackSize,
                            nsIThread** aResult)
 {
-  return NewNamedThread(NS_LITERAL_CSTRING(""), aStackSize, aResult);
-}
-
-NS_IMETHODIMP
-nsThreadManager::NewNamedThread(const nsACString& aName,
-                                uint32_t aStackSize,
-                                nsIThread** aResult)
-{
   // Note: can be called from arbitrary threads
   
   // No new threads during Shutdown
   if (NS_WARN_IF(!mInitialized)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsThread> thr = new nsThread(nsThread::NOT_MAIN_THREAD, aStackSize);
-  nsresult rv = thr->Init(aName);  // Note: blocks until the new thread has been set up
+  nsresult rv = thr->Init();  // Note: blocks until the new thread has been set up
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // At this point, we expect that the thread has been registered in mThreadByPRThread;
   // however, it is possible that it could have also been replaced by now, so
   // we cannot really assert that it was added.  Instead, kill it if we entered
   // Shutdown() during/before Init()
--- a/xpcom/threads/nsThreadPool.cpp
+++ b/xpcom/threads/nsThreadPool.cpp
@@ -99,19 +99,18 @@ nsThreadPool::PutEvent(already_AddRefed<
   }
 
   LOG(("THRD-P(%p) put [spawn=%d]\n", this, spawnThread));
   if (!spawnThread) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIThread> thread;
-  nsresult rv = NS_NewNamedThread(mThreadNaming.GetNextThreadName(mName),
-                                  getter_AddRefs(thread), nullptr, stackSize);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
+  nsThreadManager::get().NewThread(0, stackSize, getter_AddRefs(thread));
+  if (NS_WARN_IF(!thread)) {
     return NS_ERROR_UNEXPECTED;
   }
 
   bool killThread = false;
   {
     MutexAutoLock lock(mMutex);
     if (mThreads.Count() < (int32_t)mThreadLimit) {
       mThreads.AppendObject(thread);
@@ -148,16 +147,18 @@ nsThreadPool::ShutdownThread(nsIThread* 
   // shutdown aThread from the main thread.
   NS_DispatchToMainThread(NewRunnableMethod(aThread,
                                             &nsIThread::AsyncShutdown));
 }
 
 NS_IMETHODIMP
 nsThreadPool::Run()
 {
+  mThreadNaming.SetThreadPoolName(mName);
+
   LOG(("THRD-P(%p) enter %s\n", this, mName.BeginReading()));
 
   nsCOMPtr<nsIThread> current;
   nsThreadManager::get().GetCurrentThread(getter_AddRefs(current));
 
   bool shutdownThreadOnExit = false;
   bool exitThread = false;
   bool wasIdle = false;