Back out bug 429592 because of Linux opt jsreftest failure
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 04 Nov 2011 15:18:58 -0700
changeset 81151 a61d75d70c1329e9c92dce1bfe14435416f351cd
parent 81150 24129599cb519262eb30da6143083029c195fb32
child 81152 ffdc872d545090ffac49cda1d2db34724dafbc21
push id434
push userclegnitto@mozilla.com
push dateWed, 21 Dec 2011 12:10:54 +0000
treeherdermozilla-beta@bddb6ed8dd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs429592
milestone10.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
Back out bug 429592 because of Linux opt jsreftest failure
modules/libpref/src/init/all.js
startupcache/test/TestStartupCache.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
widget/src/windows/nsAppShell.cpp
xpcom/build/nsXPComInit.cpp
xpcom/threads/HangMonitor.cpp
xpcom/threads/HangMonitor.h
xpcom/threads/Makefile.in
xpcom/threads/nsThread.cpp
xpcom/threads/nsThread.h
xpcom/threads/nsThreadManager.cpp
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1465,24 +1465,16 @@ pref("gestures.enable_single_finger_inpu
 //pref("editor.encode_entity",                 "html");
 
 pref("editor.resizing.preserve_ratio",       true);
 pref("editor.positioning.offset",            0);
 
 pref("dom.max_chrome_script_run_time", 20);
 pref("dom.max_script_run_time", 10);
 
-// Hang monitor timeout after which we kill the browser, in seconds
-// (0 is disabled)
-#ifndef DEBUG
-pref("hangmonitor.timeout", 30);
-#else
-pref("hangmonitor.timeout", 0);
-#endif
-
 #ifndef DEBUG
 // How long a plugin is allowed to process a synchronous IPC message
 // before we consider it "hung".
 pref("dom.ipc.plugins.timeoutSecs", 45);
 // How long a plugin process will wait for a response from the parent
 // to a synchronous request before terminating itself. After this
 // point the child assumes the parent is hung.
 pref("dom.ipc.plugins.parentTimeoutSecs", 15);
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -46,18 +46,16 @@
 #include "nsISupports.h"
 #include "nsIStartupCache.h"
 #include "nsIStringStream.h"
 #include "nsIStorageStream.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIURI.h"
 #include "nsStringAPI.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
 
 namespace mozilla {
 namespace scache {
 
 NS_IMPORT nsresult
 NewObjectInputStreamFromBuffer(char* buffer, PRUint32 len, 
                                nsIObjectInputStream** stream);
 
@@ -88,17 +86,16 @@ nsresult
 WaitForStartupTimer() {
   nsresult rv;
   nsCOMPtr<nsIStartupCache> sc 
     = do_GetService("@mozilla.org/startupcache/cache;1");
   PR_Sleep(10 * PR_TicksPerSecond());
   
   bool complete;
   while (true) {
-    
     NS_ProcessPendingEvents(nsnull);
     rv = sc->StartupWriteComplete(&complete);
     if (NS_FAILED(rv) || complete)
       break;
     PR_Sleep(1 * PR_TicksPerSecond());
   }
   return rv;
 }
@@ -317,19 +314,16 @@ TestEarlyShutdown() {
 }
 
 
 int main(int argc, char** argv)
 {
   int rv = 0;
   nsresult rv2;
   ScopedXPCOM xpcom("Startup Cache");
-
-  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-  prefs->SetIntPref("hangmonitor.timeout", 0);
   
   if (NS_FAILED(TestStartupWriteRead()))
     rv = 1;
   if (NS_FAILED(TestWriteInvalidateRead()))
     rv = 1;
   if (NS_FAILED(TestWriteObject()))
     rv = 1;
   if (NS_FAILED(TestEarlyShutdown()))
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -201,17 +201,16 @@ static const char kTotalVirtualMemoryPar
 static const int kTotalVirtualMemoryParameterLen =
   sizeof(kTotalVirtualMemoryParameter)-1;
 
 static const char kAvailableVirtualMemoryParameter[] = "AvailableVirtualMemory=";
 static const int kAvailableVirtualMemoryParameterLen =
   sizeof(kAvailableVirtualMemoryParameter)-1;
 
 // this holds additional data sent via the API
-static Mutex* crashReporterAPILock;
 static AnnotationTable* crashReporterAPIData_Hash;
 static nsCString* crashReporterAPIData = nsnull;
 static nsCString* notesField = nsnull;
 
 // OOP crash reporting
 static CrashGenerationServer* crashServer; // chrome process has this
 
 #  if defined(XP_WIN) || defined(XP_MACOSX)
@@ -614,19 +613,16 @@ nsresult SetExceptionHandler(nsILocalFil
   // this environment variable prevents us from launching
   // the crash reporter client
   doReport = ShouldReport();
 
   // allocate our strings
   crashReporterAPIData = new nsCString();
   NS_ENSURE_TRUE(crashReporterAPIData, NS_ERROR_OUT_OF_MEMORY);
 
-  NS_ASSERTION(!crashReporterAPILock, "Shouldn't have a lock yet");
-  crashReporterAPILock = new Mutex("crashReporterAPILock");
-
   crashReporterAPIData_Hash =
     new nsDataHashtable<nsCStringHashKey,nsCString>();
   NS_ENSURE_TRUE(crashReporterAPIData_Hash, NS_ERROR_OUT_OF_MEMORY);
 
   rv = crashReporterAPIData_Hash->Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   notesField = new nsCString();
@@ -1037,27 +1033,30 @@ nsresult SetupExtraData(nsILocalFile* aA
 static void OOPDeinit();
 
 nsresult UnsetExceptionHandler()
 {
   delete gExceptionHandler;
 
   // do this here in the unlikely case that we succeeded in allocating
   // our strings but failed to allocate gExceptionHandler.
-  delete crashReporterAPIData_Hash;
-  crashReporterAPIData_Hash = nsnull;
-
-  delete crashReporterAPILock;
-  crashReporterAPILock = nsnull;
+  if (crashReporterAPIData_Hash) {
+    delete crashReporterAPIData_Hash;
+    crashReporterAPIData_Hash = nsnull;
+  }
 
-  delete crashReporterAPIData;
-  crashReporterAPIData = nsnull;
+  if (crashReporterAPIData) {
+    delete crashReporterAPIData;
+    crashReporterAPIData = nsnull;
+  }
 
-  delete notesField;
-  notesField = nsnull;
+  if (notesField) {
+    delete notesField;
+    notesField = nsnull;
+  }
 
   if (crashReporterPath) {
     NS_Free(crashReporterPath);
     crashReporterPath = nsnull;
   }
 
 #ifdef XP_MACOSX
   posix_spawnattr_destroy(&spawnattr);
@@ -1176,32 +1175,26 @@ nsresult AnnotateCrashReport(const nsACS
     return NS_ERROR_NOT_INITIALIZED;
 
   nsCString escapedData;
   nsresult rv = EscapeAnnotation(key, data, escapedData);
   if (NS_FAILED(rv))
     return rv;
 
   if (XRE_GetProcessType() != GeckoProcessType_Default) {
-    if (!NS_IsMainThread()) {
-      NS_ERROR("Cannot call AnnotateCrashReport in child processes from non-main thread.");
-      return NS_ERROR_FAILURE;
-    }
     PCrashReporterChild* reporter = CrashReporterChild::GetCrashReporter();
     if (!reporter) {
       EnqueueDelayedNote(new DelayedNote(key, data));
       return NS_OK;
     }
     if (!reporter->SendAnnotateCrashReport(nsCString(key), escapedData))
       return NS_ERROR_FAILURE;
     return NS_OK;
   }
 
-  MutexAutoLock lock(*crashReporterAPILock);
-
   rv = crashReporterAPIData_Hash->Put(key, escapedData);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // now rebuild the file contents
   crashReporterAPIData->Truncate(0);
   crashReporterAPIData_Hash->EnumerateRead(EnumerateEntries,
                                            crashReporterAPIData);
 
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -59,22 +59,17 @@
 namespace CrashReporter {
 nsresult SetExceptionHandler(nsILocalFile* aXREDirectory, bool force=false);
 nsresult UnsetExceptionHandler();
 bool     GetEnabled();
 bool     GetServerURL(nsACString& aServerURL);
 nsresult SetServerURL(const nsACString& aServerURL);
 bool     GetMinidumpPath(nsAString& aPath);
 nsresult SetMinidumpPath(const nsAString& aPath);
-
-
-// AnnotateCrashReport may be called from any thread in a chrome process,
-// but may only be called from the main thread in a content process.
 nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
-
 nsresult AppendAppNotesToCrashReport(const nsACString& data);
 nsresult SetRestartArgs(int argc, char** argv);
 nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
                         const nsACString& aBuildID);
 
 // Registers an additional memory region to be included in the minidump
 nsresult RegisterAppMemory(void* ptr, size_t length);
 nsresult UnregisterAppMemory(void* ptr);
--- a/widget/src/windows/nsAppShell.cpp
+++ b/widget/src/windows/nsAppShell.cpp
@@ -41,17 +41,16 @@
 #include "mozilla/ipc/RPCChannel.h"
 #include "nsAppShell.h"
 #include "nsToolkit.h"
 #include "nsThreadUtils.h"
 #include "WinTaskbar.h"
 #include "nsString.h"
 #include "nsIMM32Handler.h"
 #include "mozilla/widget/AudioSession.h"
-#include "mozilla/HangMonitor.h"
 
 // For skidmark code
 #include <windows.h> 
 #include <tlhelp32.h> 
 
 const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
 const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated";
 
@@ -334,23 +333,21 @@ nsAppShell::ProcessNextNativeEvent(bool 
     // Give priority to keyboard and mouse messages.
     if (PeekUIMessage(&msg) ||
         ::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
       gotMessage = true;
       if (msg.message == WM_QUIT) {
         ::PostQuitMessage(msg.wParam);
         Exit();
       } else {
-        mozilla::HangMonitor::NotifyActivity();
         ::TranslateMessage(&msg);
         ::DispatchMessageW(&msg);
       }
     } else if (mayWait) {
       // Block and wait for any posted application message
-      mozilla::HangMonitor::Suspend();
       ::WaitMessage();
     }
   } while (!gotMessage && mayWait);
 
   // See DoProcessNextNativeEvent, mEventloopNestingLevel will be
   // one when a modal loop unwinds.
   if (mNativeCallbackPending && mEventloopNestingLevel == 1)
     DoProcessMoreGeckoEvents();
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -134,17 +134,16 @@ extern nsresult nsStringInputStreamConst
 
 #include "nsSystemInfo.h"
 #include "nsMemoryReporterManager.h"
 
 #include <locale.h>
 #include "mozilla/Services.h"
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/Omnijar.h"
-#include "mozilla/HangMonitor.h"
 
 #include "nsChromeRegistry.h"
 #include "nsChromeProtocolHandler.h"
 
 #include "mozilla/scache/StartupCache.h"
 
 #include "base/at_exit.h"
 #include "base/command_line.h"
@@ -526,18 +525,16 @@ NS_InitXPCOM2(nsIServiceManager* *result
                                   nsnull,
                                   NS_XPCOM_STARTUP_OBSERVER_ID);
 #ifdef XP_WIN
     ScheduleMediaCacheRemover();
 #endif
 
     mozilla::MapsMemoryReporter::Init();
 
-    mozilla::HangMonitor::Startup();
-
     return NS_OK;
 }
 
 
 //
 // NS_ShutdownXPCOM()
 //
 // The shutdown sequence for xpcom would be
@@ -564,19 +561,16 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
     return mozilla::ShutdownXPCOM(servMgr);
 }
 
 namespace mozilla {
 
 nsresult
 ShutdownXPCOM(nsIServiceManager* servMgr)
 {
-    // Make sure the hang monitor is enabled for shutdown.
-    HangMonitor::NotifyActivity();
-
     NS_ENSURE_STATE(NS_IsMainThread());
 
     nsresult rv;
     nsCOMPtr<nsISimpleEnumerator> moduleLoaders;
 
     // Notify observers of xpcom shutting down
     {
         // Block it so that the COMPtr will get deleted before we hit
@@ -624,18 +618,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
 
         // Shutdown all remaining threads.  This method does not return until
         // all threads created using the thread manager (with the exception of
         // the main thread) have exited.
         nsThreadManager::get()->Shutdown();
 
         NS_ProcessPendingEvents(thread);
 
-        HangMonitor::NotifyActivity();
-
         // We save the "xpcom-shutdown-loaders" observers to notify after
         // the observerservice is gone.
         if (observerService) {
             observerService->
                 EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                    getter_AddRefs(moduleLoaders));
 
             observerService->Shutdown();
@@ -735,18 +727,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
         CommandLine::Terminate();
         sCommandLineWasInitialized = false;
     }
     if (sExitManager) {
         delete sExitManager;
         sExitManager = nsnull;
     }
 
-    Omnijar::CleanUp();
-
-    HangMonitor::Shutdown();
+    mozilla::Omnijar::CleanUp();
 
     NS_LogTerm();
 
     return NS_OK;
 }
 
 } // namespace mozilla
deleted file mode 100644
--- a/xpcom/threads/HangMonitor.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Firefox.
- *
- * The Initial Developer of the Original Code is
- * the Mozilla Foundation <http://www.mozilla.org>.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "mozilla/HangMonitor.h"
-#include "mozilla/Monitor.h"
-#include "mozilla/Preferences.h"
-#include "nsXULAppAPI.h"
-#include "nsThreadUtils.h"
-
-#ifdef MOZ_CRASHREPORTER
-#include "nsExceptionHandler.h"
-#endif
-
-#ifdef XP_WIN
-#include <windows.h>
-#endif
-
-namespace mozilla { namespace HangMonitor {
-
-/**
- * A flag which may be set from within a debugger to disable the hang
- * monitor.
- */
-volatile bool gDebugDisableHangMonitor = false;
-
-const char kHangMonitorPrefName[] = "hangmonitor.timeout";
-
-// Monitor protects gShutdown and gTimeout, but not gTimestamp which rely on
-// being atomically set by the processor; synchronization doesn't really matter
-// in this use case.
-Monitor* gMonitor;
-
-// The timeout preference, in seconds.
-PRInt32 gTimeout;
-
-PRThread* gThread;
-
-// Set when shutdown begins to signal the thread to exit immediately.
-bool gShutdown;
-
-// The timestamp of the last event notification, or PR_INTERVAL_NO_WAIT if
-// we're currently not processing events.
-volatile PRIntervalTime gTimestamp;
-
-// PrefChangedFunc
-int
-PrefChanged(const char*, void*)
-{
-  PRInt32 newval = Preferences::GetInt(kHangMonitorPrefName);
-  MonitorAutoLock lock(*gMonitor);
-  if (newval != gTimeout) {
-    gTimeout = newval;
-    lock.Notify();
-  }
-
-  return 0;
-}
-
-void
-Crash()
-{
-  if (gDebugDisableHangMonitor) {
-    return;
-  }
-
-#ifdef XP_WIN
-  if (::IsDebuggerPresent()) {
-    return;
-  }
-#endif
-
-#ifdef MOZ_CRASHREPORTER
-  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Hang"),
-                                     NS_LITERAL_CSTRING("1"));
-#endif
-
-  NS_RUNTIMEABORT("HangMonitor triggered");
-}
-
-void
-ThreadMain(void*)
-{
-  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;
-  int waitCount = 0;
-
-  while (true) {
-    if (gShutdown) {
-      return; // Exit the thread
-    }
-
-    // avoid rereading the volatile value in this loop
-    PRIntervalTime timestamp = gTimestamp;
-
-    PRIntervalTime now = PR_IntervalNow();
-
-    if (timestamp != PR_INTERVAL_NO_WAIT &&
-        now < timestamp) {
-      // 32-bit overflow, reset for another waiting period
-      timestamp = 1; // lowest legal PRInterval value
-    }
-
-    if (timestamp != PR_INTERVAL_NO_WAIT &&
-        timestamp == lastTimestamp &&
-        gTimeout > 0) {
-      ++waitCount;
-      if (waitCount == 2) {
-        PRInt32 delay =
-          PRInt32(PR_IntervalToSeconds(now - timestamp));
-        if (delay > gTimeout) {
-          MonitorAutoUnlock unlock(*gMonitor);
-          Crash();
-        }
-      }
-    }
-    else {
-      lastTimestamp = timestamp;
-      waitCount = 0;
-    }
-
-    PRIntervalTime timeout;
-    if (gTimeout <= 0) {
-      timeout = PR_INTERVAL_NO_TIMEOUT;
-    }
-    else {
-      timeout = PR_MillisecondsToInterval(gTimeout * 500);
-    }
-    lock.Wait(timeout);
-  }
-}
-
-void
-Startup()
-{
-  // The hang detector only runs in chrome processes. If you change this,
-  // you must also deal with the threadsafety of AnnotateCrashReport in
-  // non-chrome processes!
-  if (GeckoProcessType_Default != XRE_GetProcessType())
-    return;
-
-  NS_ASSERTION(!gMonitor, "Hang monitor already initialized");
-  gMonitor = new Monitor("HangMonitor");
-
-  Preferences::RegisterCallback(PrefChanged, kHangMonitorPrefName, NULL);
-  PrefChanged(NULL, NULL);
-
-  // Don't actually start measuring hangs until we hit the main event loop.
-  // This potentially misses a small class of really early startup hangs,
-  // but avoids dealing with some xpcshell tests and other situations which
-  // start XPCOM but don't ever start the event loop.
-  Suspend();
-
-  gThread = PR_CreateThread(PR_USER_THREAD,
-                            ThreadMain,
-                            NULL, PR_PRIORITY_LOW, PR_GLOBAL_THREAD,
-                            PR_JOINABLE_THREAD, 0);
-}
-
-void
-Shutdown()
-{
-  if (GeckoProcessType_Default != XRE_GetProcessType())
-    return;
-
-  NS_ASSERTION(gMonitor, "Hang monitor not started");
-
-  { // Scope the lock we're going to delete later
-    MonitorAutoLock lock(*gMonitor);
-    gShutdown = true;
-    lock.Notify();
-  }
-
-  // thread creation could theoretically fail
-  if (gThread) {
-    PR_JoinThread(gThread);
-    gThread = NULL;
-  }
-
-  delete gMonitor;
-  gMonitor = NULL;
-}
-
-void
-NotifyActivity()
-{
-  NS_ASSERTION(NS_IsMainThread(), "HangMonitor::Notify called from off the main thread.");
-
-  // This is not a locked activity because PRTimeStamp is a 32-bit quantity
-  // which can be read/written atomically, and we don't want to pay locking
-  // penalties here.
-  gTimestamp = PR_IntervalNow();
-}
-
-void
-Suspend()
-{
-  NS_ASSERTION(NS_IsMainThread(), "HangMonitor::Suspend called from off the main thread.");
-
-  // Because gTimestamp changes this resets the wait count.
-  gTimestamp = PR_INTERVAL_NO_WAIT;
-}
-
-} } // namespace mozilla::HangMonitor
deleted file mode 100644
--- a/xpcom/threads/HangMonitor.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Firefox.
- *
- * The Initial Developer of the Original Code is
- * the Mozilla Foundation <http://www.mozilla.org>.
- * Portions created by the Initial Developer are Copyright (C) 2011
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef mozilla_HangMonitor_h
-#define mozilla_HangMonitor_h
-
-namespace mozilla { namespace HangMonitor {
-
-/**
- * Start monitoring hangs. Should be called by the XPCOM startup process only.
- */
-void Startup();
-
-/**
- * Stop monitoring hangs and join the thread.
- */
-void Shutdown();
-
-/**
- * Notify the hang monitor of new activity which should reset its internal
- * timer.
- */
-void NotifyActivity();
-
-/**
- * Notify the hang monitor that the browser is now idle and no detection should
- * be done.
- */
-void Suspend();
-
-} } // namespace mozilla::HangMonitor
-
-#endif // mozilla_HangMonitor_h
--- a/xpcom/threads/Makefile.in
+++ b/xpcom/threads/Makefile.in
@@ -42,42 +42,35 @@ VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= xpcom
 XPIDL_MODULE	= xpcom_threads
 LIBRARY_NAME	= xpcomthreads_s
 GRE_MODULE	= 1
 MOZILLA_INTERNAL_API = 1
-LIBXUL_LIBRARY = 1
 
-EXPORTS_NAMESPACES = mozilla
 
 CPPSRCS		= \
 		nsEventQueue.cpp \
 		nsEnvironment.cpp \
 		nsThread.cpp \
 		nsThreadManager.cpp \
 		nsThreadPool.cpp \
 		nsProcessCommon.cpp \
 		nsTimerImpl.cpp \
 		TimerThread.cpp \
-		HangMonitor.cpp \
 		$(NULL)
 
 EXPORTS		= \
 		nsProcess.h \
 		nsEventQueue.h \
 		nsThreadUtilsInternal.h \
 		$(NULL)
 
-EXPORTS_mozilla = \
-  HangMonitor.h \
-  $(NULL)
-
 XPIDLSRCS	= \
 		nsIEventTarget.idl \
 		nsIThread.idl \
 		nsIThreadInternal.idl \
 		nsIThreadManager.idl \
 		nsIThreadPool.idl \
 		nsITimer.idl \
 		nsIRunnable.idl \
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -40,17 +40,16 @@
 #include "nsThread.h"
 #include "nsThreadManager.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIProgrammingLanguage.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "prlog.h"
 #include "nsThreadUtilsInternal.h"
-#include "mozilla/HangMonitor.h"
 
 #define HAVE_UALARM _BSD_SOURCE || (_XOPEN_SOURCE >= 500 ||                 \
                       _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&           \
                       !(_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
 
 #if defined(XP_UNIX) && !defined(ANDROID) && !defined(DEBUG) && HAVE_UALARM \
   && defined(_GNU_SOURCE)
 # define MOZ_CANARY
@@ -302,27 +301,39 @@ nsThread::ThreadFunc(void *arg)
   // Release any observer of the thread here.
   self->SetObserver(nsnull);
 
   NS_RELEASE(self);
 }
 
 //-----------------------------------------------------------------------------
 
-nsThread::nsThread(MainThreadFlag aMainThread, PRUint32 aStackSize)
+nsThread::nsThread()
+  : mLock("nsThread.mLock")
+  , mEvents(&mEventsRoot)
+  , mPriority(PRIORITY_NORMAL)
+  , mThread(nsnull)
+  , mRunningEvent(0)
+  , mStackSize(0)
+  , mShutdownContext(nsnull)
+  , mShutdownRequired(false)
+  , mEventsAreDoomed(false)
+{
+}
+
+nsThread::nsThread(PRUint32 aStackSize)
   : mLock("nsThread.mLock")
   , mEvents(&mEventsRoot)
   , mPriority(PRIORITY_NORMAL)
   , mThread(nsnull)
   , mRunningEvent(0)
   , mStackSize(aStackSize)
   , mShutdownContext(nsnull)
   , mShutdownRequired(false)
   , mEventsAreDoomed(false)
-  , mIsMainThread(aMainThread)
 {
 }
 
 nsThread::~nsThread()
 {
 }
 
 nsresult
@@ -569,19 +580,16 @@ void canary_alarm_handler (int signum)
 
 NS_IMETHODIMP
 nsThread::ProcessNextEvent(bool mayWait, bool *result)
 {
   LOG(("THRD(%p) ProcessNextEvent [%u %u]\n", this, mayWait, mRunningEvent));
 
   NS_ENSURE_STATE(PR_GetCurrentThread() == mThread);
 
-  if (MAIN_THREAD == mIsMainThread && mayWait && !ShuttingDown())
-    HangMonitor::Suspend();
-
   bool notifyGlobalObserver = (sGlobalObserver != nsnull);
   if (notifyGlobalObserver) 
     sGlobalObserver->OnProcessNextEvent(this, mayWait && !ShuttingDown(),
                                         mRunningEvent);
 
   nsCOMPtr<nsIThreadObserver> obs = mObserver;
   if (obs)
     obs->OnProcessNextEvent(this, mayWait && !ShuttingDown(), mRunningEvent);
@@ -602,31 +610,29 @@ nsThread::ProcessNextEvent(bool mayWait,
     // also do work.
 
     // If we are shutting down, then do not wait for new events.
     nsCOMPtr<nsIRunnable> event;
     mEvents->GetEvent(mayWait && !ShuttingDown(), getter_AddRefs(event));
 
 #ifdef NS_FUNCTION_TIMER
     char message[1024] = {'\0'};
-    if (MAIN_THREAD == mIsMainThread) {
+    if (NS_IsMainThread()) {
         mozilla::FunctionTimer::ft_snprintf(message, sizeof(message), 
                                             "@ Main Thread Event %p", (void*)event.get());
     }
     // If message is empty, it means that we're not on the main thread, and
     // FunctionTimer won't time this function.
     NS_TIME_FUNCTION_MIN_FMT(5.0, message);
 #endif
 
     *result = (event.get() != nsnull);
 
     if (event) {
       LOG(("THRD(%p) running [%p]\n", this, event.get()));
-      if (MAIN_THREAD == mIsMainThread)
-        HangMonitor::NotifyActivity();
       event->Run();
     } else if (mayWait) {
       NS_ASSERTION(ShuttingDown(),
                    "This should only happen when shutting down");
       rv = NS_ERROR_UNEXPECTED;
     }
   }
 
--- a/xpcom/threads/nsThread.h
+++ b/xpcom/threads/nsThread.h
@@ -52,22 +52,18 @@ class nsThread : public nsIThreadInterna
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIEVENTTARGET
   NS_DECL_NSITHREAD
   NS_DECL_NSITHREADINTERNAL
   NS_DECL_NSISUPPORTSPRIORITY
 
-  enum MainThreadFlag {
-    MAIN_THREAD,
-    NOT_MAIN_THREAD
-  };
-
-  nsThread(MainThreadFlag aMainThread, PRUint32 aStackSize);
+  nsThread();
+  nsThread(PRUint32 aStackSize);
 
   // 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.
@@ -146,17 +142,16 @@ private:
   PRUint32  mStackSize;
 
   struct nsThreadShutdownContext *mShutdownContext;
 
   bool mShutdownRequired;
   bool mShutdownPending;
   // Set to true when events posted to this thread will never run.
   bool mEventsAreDoomed;
-  MainThreadFlag mIsMainThread;
 };
 
 //-----------------------------------------------------------------------------
 
 class nsThreadSyncDispatch : public nsRunnable {
 public:
   nsThreadSyncDispatch(nsIThread *origin, nsIRunnable *task)
     : mOrigin(origin), mSyncTask(task), mResult(NS_ERROR_NOT_INITIALIZED) {
--- a/xpcom/threads/nsThreadManager.cpp
+++ b/xpcom/threads/nsThreadManager.cpp
@@ -93,17 +93,17 @@ nsThreadManager::Init()
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (PR_NewThreadPrivateIndex(&mCurThreadIndex, ReleaseObject) == PR_FAILURE)
     return NS_ERROR_FAILURE;
 
   mLock = new Mutex("nsThreadManager.mLock");
 
   // Setup "main" thread
-  mMainThread = new nsThread(nsThread::MAIN_THREAD, 0);
+  mMainThread = new nsThread();
   if (!mMainThread)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = mMainThread->InitCurrentThread();
   if (NS_FAILED(rv)) {
     mMainThread = nsnull;
     return rv;
   }
@@ -219,32 +219,32 @@ nsThreadManager::GetCurrentThread()
   if (data)
     return static_cast<nsThread *>(data);
 
   if (!mInitialized) {
     return nsnull;
   }
 
   // OK, that's fine.  We'll dynamically create one :-)
-  nsRefPtr<nsThread> thread = new nsThread(nsThread::NOT_MAIN_THREAD, 0);
+  nsRefPtr<nsThread> thread = new nsThread();
   if (!thread || NS_FAILED(thread->InitCurrentThread()))
     return nsnull;
 
   return thread.get();  // reference held in TLS
 }
 
 NS_IMETHODIMP
 nsThreadManager::NewThread(PRUint32 creationFlags,
                            PRUint32 stackSize,
                            nsIThread **result)
 {
   // No new threads during Shutdown
   NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
 
-  nsThread *thr = new nsThread(nsThread::NOT_MAIN_THREAD, stackSize);
+  nsThread *thr = new nsThread(stackSize);
   if (!thr)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(thr);
 
   nsresult rv = thr->Init();
   if (NS_FAILED(rv)) {
     NS_RELEASE(thr);
     return rv;