Bug 1323100 - Assign names to all remaining threads that are created through NS_NewThread and create them using NS_NewNamedThread instead. r=froydnj
authorMarkus Stange <mstange@themasta.com>
Wed, 21 Dec 2016 11:43:50 +0100
changeset 328282 6e204f4e079b21c2051b86b4ed78a0742b64ca01
parent 328281 35295d2aeadfa0c1dfa35c715f0345833011388b
child 328283 28586a45a1e9228faee963272a3a6b698afbd18f
push id31168
push userryanvm@gmail.com
push dateSat, 07 Jan 2017 16:20:16 +0000
treeherdermozilla-central@2d62b03b833b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1323100
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1323100 - Assign names to all remaining threads that are created through NS_NewThread and create them using NS_NewNamedThread instead. r=froydnj MozReview-Commit-ID: 7W1dt2BBKJZ
dom/gamepad/cocoa/CocoaGamepad.cpp
dom/gamepad/windows/WindowsGamepad.cpp
dom/media/FileBlockCache.cpp
dom/media/android/AndroidMediaResourceServer.cpp
dom/media/gtest/TestMP4Reader.cpp
dom/system/gonk/GonkGPSGeolocationProvider.cpp
gfx/layers/LayerScope.cpp
hal/gonk/GonkHal.cpp
image/test/gtest/TestDecodeToSurface.cpp
netwerk/base/BackgroundFileSaver.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/test/TestFileInput2.cpp
storage/test/gtest/test_service_init_background_thread.cpp
toolkit/components/url-classifier/tests/gtest/Common.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/identity/IdentityCryptoService.cpp
toolkit/xre/nsUpdateDriver.cpp
widget/windows/LSPAnnotator.cpp
widget/windows/nsSound.cpp
xpcom/tests/gtest/TestPipes.cpp
xpcom/tests/gtest/TestRacingServiceManager.cpp
xpcom/tests/gtest/TestThreads.cpp
xpcom/tests/gtest/TestTimers.cpp
xpcom/threads/LazyIdleThread.cpp
xpcom/threads/TimerThread.cpp
--- a/dom/gamepad/cocoa/CocoaGamepad.cpp
+++ b/dom/gamepad/cocoa/CocoaGamepad.cpp
@@ -536,18 +536,19 @@ 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_NewThread(getter_AddRefs(mMonitorThread),
-                         new DarwinGamepadServiceStartupRunnable(this));
+  Unused << NS_NewNamedThread("Gamepad",
+                              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
@@ -1068,17 +1068,17 @@ void
 StartGamepadMonitoring()
 {
   AssertIsOnBackgroundThread();
 
   if (gMonitorThread || gService) {
     return;
   }
   sIsShutdown = false;
-  NS_NewThread(getter_AddRefs(gMonitorThread));
+  NS_NewNamedThread("Gamepad", getter_AddRefs(gMonitorThread));
   gMonitorThread->Dispatch(new StartWindowsGamepadServiceRunnable(),
                            NS_DISPATCH_NORMAL);
 }
 
 void
 StopGamepadMonitoring()
 {
   AssertIsOnBackgroundThread();
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -17,19 +17,20 @@ 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_NewThread(getter_AddRefs(mThread),
-                                nullptr,
-                                SharedThreadPool::kStackSize);
+    nsresult res = NS_NewNamedThread("FileBlockCache",
+                                     getter_AddRefs(mThread),
+                                     nullptr,
+                                     SharedThreadPool::kStackSize);
     mIsOpen = NS_SUCCEEDED(res);
     return res;
   }
 }
 
 FileBlockCache::FileBlockCache()
   : mFileMonitor("MediaCache.Writer.IO.Monitor"),
     mFD(nullptr),
--- 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_NewThread(getter_AddRefs(thread));
+  rv = NS_NewNamedThread("ServeResource", 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_NewThread(getter_AddRefs(thread), r);
+    nsresult rv = NS_NewNamedThread("ReadMetadata", getter_AddRefs(thread), r);
     EXPECT_EQ(NS_OK, rv);
     thread->Shutdown();
   }
 
 private:
   virtual ~TestBinding()
   {
     {
--- 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_NewThread(getter_AddRefs(mInitThread));
+    nsresult rv = NS_NewNamedThread("Gonk GPS", 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_NewThread(getter_AddRefs(mDebugSenderThread));
+    NS_NewNamedThread("LayerScope", 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_NewThread(getter_AddRefs(thread), sVibratorRunnable);
+  NS_NewNamedThread("Gonk Vibrator", getter_AddRefs(thread), sVibratorRunnable);
 }
 
 } // namespace
 
 void
 Vibrate(const nsTArray<uint32_t> &pattern, const hal::WindowIdentifier &)
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/image/test/gtest/TestDecodeToSurface.cpp
+++ b/image/test/gtest/TestDecodeToSurface.cpp
@@ -64,17 +64,18 @@ private:
 
 static void
 RunDecodeToSurface(const ImageTestCase& aTestCase)
 {
   nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath);
   ASSERT_TRUE(inputStream != nullptr);
 
   nsCOMPtr<nsIThread> thread;
-  nsresult rv = NS_NewThread(getter_AddRefs(thread), nullptr);
+  nsresult rv =
+    NS_NewNamedThread("DecodeToSurface", 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/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_NewThread(getter_AddRefs(mWorkerThread));
+  rv = NS_NewNamedThread("BgFileSaver", getter_AddRefs(mWorkerThread));
   NS_ENSURE_SUCCESS(rv, rv);
 
   sThreadCount++;
   if (sThreadCount > sTelemetryMaxThreadCount) {
     sTelemetryMaxThreadCount = sThreadCount;
   }
 
   return NS_OK;
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -2321,18 +2321,19 @@ 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 res = NS_NewThread(getter_AddRefs(mInternalIOThread));
-    if (NS_FAILED(res)) {
+    nsresult rv = NS_NewNamedThread("DataChannel IO",
+                                    getter_AddRefs(mInternalIOThread));
+    if (NS_FAILED(rv)) {
       return -1;
     }
   }
 
   mInternalIOThread->Dispatch(do_AddRef(new ReadBlobRunnable(this, stream, aBlob)), NS_DISPATCH_NORMAL);
   return 0;
 }
 
--- 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, uint32_t count,
+Test(CreateFun create, const char* name, uint32_t count,
      nsIFile* inDirSpec, nsIFile* outDirSpec, uint32_t bufSize)
 {
     nsresult rv;
     uint32_t i;
 
     nsAutoCString inDir;
     nsAutoCString outDir;
     (void)inDirSpec->GetNativePath(inDir);
@@ -370,17 +370,18 @@ Test(CreateFun create, uint32_t count,
         nsCOMPtr<nsIThread> thread;
         nsCOMPtr<nsIRunnable> worker;
         rv = create(getter_AddRefs(worker), 
                     inSpec,
                     outSpec,
                     bufSize);
         if (NS_FAILED(rv)) goto done;
 
-        rv = NS_NewThread(getter_AddRefs(thread), worker, 0, PR_JOINABLE_THREAD);
+        rv = NS_NewNamedThread(name, 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++;
     }
 
@@ -428,52 +429,54 @@ 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, 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, 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);
 #endif
         create = FileSpecWorker::Create;
+        name = "FileSpecWorker";
         printf("FileSpecWorker ********************************\n");
 #if 1
-        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);
+        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);
 #endif
 #if 1
-        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);
+        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);
 #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/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_NewThread(getter_AddRefs(thread)));
+  do_check_success(NS_NewNamedThread("StorageService", 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/url-classifier/tests/gtest/Common.cpp
+++ b/toolkit/components/url-classifier/tests/gtest/Common.cpp
@@ -9,17 +9,18 @@
 
 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_NewThread(getter_AddRefs(testingThread), r);
+  nsresult rv =
+    NS_NewNamedThread("Testing Thread", 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_NewThread(&sInjectorThread)))
+    if (NS_FAILED(NS_NewNamedThread("CrashRep Inject", &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,17 +200,18 @@ 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_NewThread(getter_AddRefs(thread), r);
+  nsresult rv = NS_NewNamedThread("GenerateKeyPair", getter_AddRefs(thread),
+                                  r);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 IdentityCryptoService::Base64UrlEncode(const nsACString & utf8Input,
                                        nsACString & result)
@@ -304,17 +305,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_NewThread(getter_AddRefs(thread), r);
+  nsresult rv = NS_NewNamedThread("KeyPair Sign", 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/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -1241,17 +1241,18 @@ 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_NewThread(getter_AddRefs(mProcessWatcher), r);
+  return NS_NewNamedThread("Update Watcher", getter_AddRefs(mProcessWatcher),
+                           r);
 }
 
 
 
 void
 nsUpdateProcessor::StartStagedUpdate()
 {
   MOZ_ASSERT(!NS_IsMainThread(), "main thread");
--- 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_NewThread(getter_AddRefs(thread), runnable);
+  NS_NewNamedThread("LSP Annotate", getter_AddRefs(thread), runnable);
 }
 
 } // namespace crashreporter
 } // namespace mozilla
--- a/widget/windows/nsSound.cpp
+++ b/widget/windows/nsSound.cpp
@@ -236,17 +236,19 @@ 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_NewThread(getter_AddRefs(mPlayerThread), player);
+    nsresult rv =
+      NS_NewNamedThread("PlaySystemSound", 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))
@@ -294,12 +296,13 @@ 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_NewThread(getter_AddRefs(mPlayerThread), player);
+  nsresult rv =
+    NS_NewNamedThread("PlayEventSound", getter_AddRefs(mPlayerThread), player);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
--- 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_NewThread(getter_AddRefs(thread), receiver);
+    rv = NS_NewNamedThread("TestPipe", 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,17 +220,18 @@ 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_NewThread(getter_AddRefs(thread), receiver);
+    rv = NS_NewNamedThread("TestShortWrites", 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;
@@ -325,24 +326,25 @@ 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_NewThread(getter_AddRefs(thread), pump);
+    rv = NS_NewNamedThread("ChainedPipePump", getter_AddRefs(thread), pump);
     if (NS_FAILED(rv)) return;
 
     RefPtr<nsReceiver> receiver = new nsReceiver(in2);
     if (receiver == nullptr) return;
 
     nsCOMPtr<nsIThread> receiverThread;
-    rv = NS_NewThread(getter_AddRefs(receiverThread), receiver);
+    rv = NS_NewNamedThread("ChainedPipeRecv", 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_NewThread(getter_AddRefs(newThread), runnable);
+  rv = NS_NewNamedThread("RacingServMan", 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_NewThread(getter_AddRefs(runner), event);
+    rv = NS_NewNamedThread("TestThreadsMain", 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,17 +107,18 @@ 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_NewThread(getter_AddRefs(t), new nsStressRunner(k));
+            nsresult rv = NS_NewNamedThread("StressRunner", 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]);    
         }
@@ -164,17 +165,18 @@ public:
         mWasRun = true;
 
         nsCOMPtr<nsIThread> t;
         nsresult rv;
 
         {
           mozilla::MonitorAutoLock lock(*gBeginAsyncShutdownMonitor);
 
-          rv = NS_NewThread(getter_AddRefs(t), new AsyncShutdownPreparer());
+          rv = NS_NewNamedThread("AsyncShutdownPr", getter_AddRefs(t),
+                                 new AsyncShutdownPreparer());
           EXPECT_TRUE(NS_SUCCEEDED(rv));
 
           lock.Wait();
         }
 
         rv = t->AsyncShutdown();
         EXPECT_TRUE(NS_SUCCEEDED(rv));
 
@@ -216,17 +218,18 @@ TEST(Threads, AsyncShutdown)
   gBeginAsyncShutdownMonitor = new mozilla::Monitor("gBeginAsyncShutdown");
 
   nsCOMPtr<nsIThread> t;
   nsresult rv;
 
   {
     mozilla::MonitorAutoLock lock(*gAsyncShutdownReadyMonitor);
 
-    rv = NS_NewThread(getter_AddRefs(t), new AsyncShutdownWaiter());
+    rv = NS_NewNamedThread("AsyncShutdownWt", 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_NewThread(getter_AddRefs(newThread));
+    nsresult rv = NS_NewNamedThread("AutoTestThread", getter_AddRefs(newThread));
     if (NS_FAILED(rv))
       return;
 
     newThread.swap(mThread);
   }
 
   ~AutoTestThread() {
     mThread->Shutdown();
--- a/xpcom/threads/LazyIdleThread.cpp
+++ b/xpcom/threads/LazyIdleThread.cpp
@@ -164,17 +164,17 @@ LazyIdleThread::EnsureThread()
   }
 
   nsCOMPtr<nsIRunnable> runnable =
     NewRunnableMethod(this, &LazyIdleThread::InitThread);
   if (NS_WARN_IF(!runnable)) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  rv = NS_NewThread(getter_AddRefs(mThread), runnable);
+  rv = NS_NewNamedThread("Lazy Idle", getter_AddRefs(mThread), runnable);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
 void
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -318,17 +318,18 @@ 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_NewThread(getter_AddRefs(mThread), this);
+    nsresult rv =
+      NS_NewNamedThread("Timer Thread", 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);