Bug 1163103 - stop using NS_GetSpecialDirectory off the main thread within the cycle collector (via nsDumpUtils.cpp), r=mccr8
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 21 Aug 2019 17:23:03 +0000
changeset 489288 52cd8205384f569871a5c7be88a46b909b1fbf18
parent 489287 174bc4782db4d116644fcef2f9bfc5c8bbcbe8d7
child 489289 a8646f9a5ab1293561f85ebf1d4f5655e87b06d1
push id93239
push usergijskruitbosch@gmail.com
push dateWed, 21 Aug 2019 20:33:30 +0000
treeherderautoland@52cd8205384f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1163103
milestone70.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 1163103 - stop using NS_GetSpecialDirectory off the main thread within the cycle collector (via nsDumpUtils.cpp), r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D42856
xpcom/base/moz.build
xpcom/base/nsDumpUtils.cpp
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -128,20 +128,24 @@ EXPORTS.mozilla += [
     'SizeOfState.h',
     'StaticLocalPtr.h',
     'StaticMonitor.h',
     'StaticMutex.h',
     'StaticPtr.h',
     'TupleCycleCollection.h',
 ]
 
+SOURCES += [
 # nsDebugImpl isn't unified because we disable PGO so that NS_ABORT_OOM isn't
 # optimized away oddly.
-SOURCES += [
     'nsDebugImpl.cpp',
+# nsDumpUtils.cpp includes SpecialSystemDirectory.h which includes
+# nsLocalFileMac.h which upsets other files in this dir that have a different
+# idea about what `TextRange` means.
+    'nsDumpUtils.cpp',
 ]
 SOURCES['nsDebugImpl.cpp'].no_pgo = True
 
 UNIFIED_SOURCES += [
     'AvailableMemoryTracker.cpp',
     'ClearOnShutdown.cpp',
     'CycleCollectedJSContext.cpp',
     'CycleCollectedJSRuntime.cpp',
@@ -159,17 +163,16 @@ UNIFIED_SOURCES += [
     'nsClassInfoImpl.cpp',
     'nsCOMPtr.cpp',
     'nsConsoleMessage.cpp',
     'nsConsoleService.cpp',
     'nsCRTGlue.cpp',
     'nsCycleCollectionParticipant.cpp',
     'nsCycleCollector.cpp',
     'nsCycleCollectorTraceJSHelpers.cpp',
-    'nsDumpUtils.cpp',
     'nsErrorService.cpp',
     'nsGZFileWriter.cpp',
     'nsID.cpp',
     'nsIInterfaceRequestorUtils.cpp',
     'nsINIParser.cpp',
     'nsInterfaceRequestorAgg.cpp',
     'nsISupportsImpl.cpp',
     'nsMemory.cpp',
--- a/xpcom/base/nsDumpUtils.cpp
+++ b/xpcom/base/nsDumpUtils.cpp
@@ -8,16 +8,17 @@
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "prenv.h"
 #include <errno.h>
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Unused.h"
+#include "SpecialSystemDirectory.h"
 
 #ifdef XP_UNIX  // {
 #  include "mozilla/Preferences.h"
 #  include <fcntl.h>
 #  include <unistd.h>
 #  include <sys/types.h>
 #  include <sys/stat.h>
 
@@ -412,17 +413,22 @@ nsresult nsDumpUtils::OpenTempFile(const
     char* env = PR_GetEnv("DOWNLOADS_DIRECTORY");
     if (env) {
       NS_NewNativeLocalFile(nsCString(env), /* followLinks = */ true, aFile);
     }
   }
 #endif
   nsresult rv;
   if (!*aFile) {
-    rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
+    if (NS_IsMainThread()) {
+      // This allows tests to override, but isn't safe off-mainthread.
+      rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, aFile);
+    } else {
+      rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, aFile);
+    }
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
 #ifdef ANDROID
   // /data/local/tmp is a true tmp directory; anyone can create a file there,
   // but only the user which created the file can remove it.  We want non-root