2015-01-17 02:34:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-01-17 02:34:47 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/ProcessHangMonitor.h"
|
|
|
|
#include "mozilla/ProcessHangMonitorIPC.h"
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "js/GCAPI.h"
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2016-10-19 18:33:13 +00:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2016-07-22 23:36:45 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/plugins/PluginBridge.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
#include "nsIFrameLoader.h"
|
|
|
|
#include "nsIHangReport.h"
|
|
|
|
#include "nsITabParent.h"
|
|
|
|
#include "nsPluginHost.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2015-06-11 17:25:45 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
|
2015-01-22 23:53:49 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// For IsDebuggerPresent()
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic architecture:
|
|
|
|
*
|
|
|
|
* Each process has its own ProcessHangMonitor singleton. This singleton exists
|
|
|
|
* as long as there is at least one content process in the system. Each content
|
|
|
|
* process has a HangMonitorChild and the chrome process has one
|
|
|
|
* HangMonitorParent per process. Each process (including the chrome process)
|
|
|
|
* runs a hang monitoring thread. The PHangMonitor actors are bound to this
|
|
|
|
* thread so that they never block on the main thread.
|
|
|
|
*
|
|
|
|
* When the content process detects a hang, it posts a task to its hang thread,
|
|
|
|
* which sends an IPC message to the hang thread in the parent. The parent
|
|
|
|
* cancels any ongoing CPOW requests and then posts a runnable to the main
|
|
|
|
* thread that notifies Firefox frontend code of the hang. The frontend code is
|
|
|
|
* passed an nsIHangReport, which can be used to terminate the hang.
|
|
|
|
*
|
|
|
|
* If the user chooses to terminate a script, a task is posted to the chrome
|
|
|
|
* process's hang monitoring thread, which sends an IPC message to the hang
|
|
|
|
* thread in the content process. That thread sets a flag to indicate that JS
|
|
|
|
* execution should be terminated the next time it hits the interrupt
|
|
|
|
* callback. A similar scheme is used for debugging slow scripts. If a content
|
|
|
|
* process or plug-in needs to be terminated, the chrome process does so
|
|
|
|
* directly, without messaging the content process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Child process objects */
|
|
|
|
|
|
|
|
class HangMonitorChild
|
|
|
|
: public PProcessHangMonitorChild
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit HangMonitorChild(ProcessHangMonitor* aMonitor);
|
|
|
|
virtual ~HangMonitorChild();
|
|
|
|
|
2015-04-01 08:40:35 +00:00
|
|
|
void Open(Transport* aTransport, ProcessId aOtherPid,
|
2015-01-17 02:34:47 +00:00
|
|
|
MessageLoop* aIOLoop);
|
|
|
|
|
|
|
|
typedef ProcessHangMonitor::SlowScriptAction SlowScriptAction;
|
|
|
|
SlowScriptAction NotifySlowScript(nsITabChild* aTabChild,
|
|
|
|
const char* aFileName,
|
|
|
|
unsigned aLineNo);
|
|
|
|
void NotifySlowScriptAsync(TabId aTabId,
|
|
|
|
const nsCString& aFileName,
|
|
|
|
unsigned aLineNo);
|
|
|
|
|
|
|
|
bool IsDebuggerStartupComplete();
|
|
|
|
|
|
|
|
void NotifyPluginHang(uint32_t aPluginId);
|
2016-06-11 22:25:25 +00:00
|
|
|
void NotifyPluginHangAsync(uint32_t aPluginId);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
void ClearHang();
|
2016-04-01 23:54:25 +00:00
|
|
|
void ClearHangAsync();
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool RecvTerminateScript() override;
|
|
|
|
virtual bool RecvBeginStartingDebugger() override;
|
|
|
|
virtual bool RecvEndStartingDebugger() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
virtual bool RecvForcePaint(const TabId& aTabId, const uint64_t& aLayerObserverEpoch) override;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
void InterruptCallback();
|
2015-01-17 02:34:47 +00:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
static HangMonitorChild* Get() { return sInstance; }
|
|
|
|
|
|
|
|
MessageLoop* MonitorLoop() { return mHangMonitor->MonitorLoop(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2015-09-11 23:24:53 +00:00
|
|
|
static Atomic<HangMonitorChild*> sInstance;
|
2016-10-19 18:33:13 +00:00
|
|
|
UniquePtr<BackgroundHangMonitor> mForcePaintMonitor;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 02:34:47 +00:00
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// Main thread-only.
|
|
|
|
bool mSentReport;
|
|
|
|
|
|
|
|
// These fields must be accessed with mMonitor held.
|
|
|
|
bool mTerminateScript;
|
|
|
|
bool mStartDebugger;
|
|
|
|
bool mFinishedStartingDebugger;
|
2016-10-18 00:59:55 +00:00
|
|
|
bool mForcePaint;
|
2016-07-22 23:36:45 +00:00
|
|
|
TabId mForcePaintTab;
|
2016-09-20 09:13:40 +00:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR uint64_t mForcePaintEpoch;
|
2016-07-22 23:36:45 +00:00
|
|
|
JSContext* mContext;
|
2015-01-17 02:34:47 +00:00
|
|
|
bool mShutdownDone;
|
|
|
|
|
|
|
|
// This field is only accessed on the hang thread.
|
|
|
|
bool mIPCOpen;
|
|
|
|
};
|
|
|
|
|
2015-09-11 23:24:53 +00:00
|
|
|
Atomic<HangMonitorChild*> HangMonitorChild::sInstance;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
/* Parent process objects */
|
|
|
|
|
|
|
|
class HangMonitorParent;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class HangMonitoredProcess final
|
2015-01-17 02:34:47 +00:00
|
|
|
: public nsIHangReport
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
HangMonitoredProcess(HangMonitorParent* aActor,
|
|
|
|
ContentParent* aContentParent)
|
|
|
|
: mActor(aActor), mContentParent(aContentParent) {}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD GetHangType(uint32_t* aHangType) override;
|
|
|
|
NS_IMETHOD GetScriptBrowser(nsIDOMElement** aBrowser) override;
|
|
|
|
NS_IMETHOD GetScriptFileName(nsACString& aFileName) override;
|
|
|
|
NS_IMETHOD GetScriptLineNo(uint32_t* aLineNo) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD GetPluginName(nsACString& aPluginName) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD TerminateScript() override;
|
|
|
|
NS_IMETHOD BeginStartingDebugger() override;
|
|
|
|
NS_IMETHOD EndStartingDebugger() override;
|
|
|
|
NS_IMETHOD TerminatePlugin() override;
|
2015-06-11 17:25:45 +00:00
|
|
|
NS_IMETHOD UserCanceled() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD IsReportForBrowser(nsIFrameLoader* aFrameLoader, bool* aResult) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-06-18 20:10:46 +00:00
|
|
|
// Called when a content process shuts down.
|
2015-06-11 17:25:45 +00:00
|
|
|
void Clear() {
|
|
|
|
mContentParent = nullptr;
|
|
|
|
mActor = nullptr;
|
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
/**
|
|
|
|
* Sets the information associated with this hang: this includes the ID of
|
|
|
|
* the plugin which caused the hang as well as the content PID. The ID of
|
|
|
|
* a minidump taken during the hang can also be provided.
|
2016-06-24 12:25:08 +00:00
|
|
|
*
|
|
|
|
* @param aHangData The hang information
|
2016-07-05 11:39:37 +00:00
|
|
|
* @param aDumpId The ID of a minidump taken when the hang occurred
|
2016-06-24 12:25:08 +00:00
|
|
|
*/
|
2016-07-05 11:39:37 +00:00
|
|
|
void SetHangData(const HangData& aHangData, const nsAString& aDumpId) {
|
|
|
|
mHangData = aHangData;
|
|
|
|
mDumpId = aDumpId;
|
2015-06-11 17:25:45 +00:00
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-04-01 23:54:25 +00:00
|
|
|
void ClearHang() {
|
|
|
|
mHangData = HangData();
|
2016-06-24 12:25:08 +00:00
|
|
|
mDumpId.Truncate();
|
2016-04-01 23:54:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
private:
|
|
|
|
~HangMonitoredProcess() {}
|
|
|
|
|
|
|
|
// Everything here is main thread-only.
|
|
|
|
HangMonitorParent* mActor;
|
|
|
|
ContentParent* mContentParent;
|
|
|
|
HangData mHangData;
|
2016-06-24 12:25:08 +00:00
|
|
|
nsAutoString mDumpId;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HangMonitorParent
|
|
|
|
: public PProcessHangMonitorParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
|
|
|
|
virtual ~HangMonitorParent();
|
|
|
|
|
2015-04-01 08:40:35 +00:00
|
|
|
void Open(Transport* aTransport, ProcessId aPid, MessageLoop* aIOLoop);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool RecvHangEvidence(const HangData& aHangData) override;
|
2016-04-01 23:54:25 +00:00
|
|
|
virtual bool RecvClearHang() override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
void SetProcess(HangMonitoredProcess* aProcess) { mProcess = aProcess; }
|
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
void ForcePaint(dom::TabParent* aTabParent, uint64_t aLayerObserverEpoch);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void TerminateScript();
|
|
|
|
void BeginStartingDebugger();
|
|
|
|
void EndStartingDebugger();
|
2015-06-11 17:25:45 +00:00
|
|
|
void CleanupPluginHang(uint32_t aPluginId, bool aRemoveFiles);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
/**
|
|
|
|
* Update the dump for the specified plugin. This method is thread-safe and
|
|
|
|
* is used to replace a browser minidump with a full minidump. If aDumpId is
|
|
|
|
* empty this is a no-op.
|
|
|
|
*/
|
|
|
|
void UpdateMinidump(uint32_t aPluginId, const nsString& aDumpId);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
MessageLoop* MonitorLoop() { return mHangMonitor->MonitorLoop(); }
|
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
private:
|
|
|
|
bool TakeBrowserMinidump(const PluginHangData& aPhd, nsString& aCrashId);
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
void ForcePaintOnThread(TabId aTabId, uint64_t aLayerObserverEpoch);
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
// This field is read-only after construction.
|
|
|
|
bool mReportHangs;
|
|
|
|
|
|
|
|
// This field is only accessed on the hang thread.
|
|
|
|
bool mIPCOpen;
|
|
|
|
|
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// Must be accessed with mMonitor held.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HangMonitoredProcess> mProcess;
|
2015-01-17 02:34:47 +00:00
|
|
|
bool mShutdownDone;
|
2015-06-11 17:25:45 +00:00
|
|
|
// Map from plugin ID to crash dump ID. Protected by mBrowserCrashDumpHashLock.
|
|
|
|
nsDataHashtable<nsUint32HashKey, nsString> mBrowserCrashDumpIds;
|
|
|
|
Mutex mBrowserCrashDumpHashLock;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/* HangMonitorChild implementation */
|
|
|
|
|
|
|
|
HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
|
|
|
|
: mHangMonitor(aMonitor),
|
|
|
|
mMonitor("HangMonitorChild lock"),
|
|
|
|
mSentReport(false),
|
|
|
|
mTerminateScript(false),
|
|
|
|
mStartDebugger(false),
|
|
|
|
mFinishedStartingDebugger(false),
|
2016-10-18 00:59:55 +00:00
|
|
|
mForcePaint(false),
|
2015-01-17 02:34:47 +00:00
|
|
|
mShutdownDone(false),
|
|
|
|
mIPCOpen(true)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2016-07-22 23:36:45 +00:00
|
|
|
mContext = danger::GetJSContext();
|
2016-10-19 18:33:13 +00:00
|
|
|
mForcePaintMonitor =
|
|
|
|
MakeUnique<mozilla::BackgroundHangMonitor>("Gecko_Child_ForcePaint",
|
|
|
|
128, /* ms timeout for microhangs */
|
|
|
|
8192 /* ms timeout for permahangs */,
|
|
|
|
BackgroundHangMonitor::THREAD_PRIVATE);
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::~HangMonitorChild()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
2016-10-19 18:33:13 +00:00
|
|
|
mForcePaintMonitor = nullptr;
|
2015-01-17 02:34:47 +00:00
|
|
|
sInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
void
|
|
|
|
HangMonitorChild::InterruptCallback()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-10-18 00:59:55 +00:00
|
|
|
bool forcePaint;
|
2016-07-22 23:36:45 +00:00
|
|
|
TabId forcePaintTab;
|
|
|
|
uint64_t forcePaintEpoch;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-10-18 00:59:55 +00:00
|
|
|
forcePaint = mForcePaint;
|
2016-07-22 23:36:45 +00:00
|
|
|
forcePaintTab = mForcePaintTab;
|
|
|
|
forcePaintEpoch = mForcePaintEpoch;
|
|
|
|
|
2016-10-18 00:59:55 +00:00
|
|
|
mForcePaint = false;
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 00:59:55 +00:00
|
|
|
if (forcePaint) {
|
2016-07-22 23:36:45 +00:00
|
|
|
RefPtr<TabChild> tabChild = TabChild::FindTabChild(forcePaintTab);
|
|
|
|
if (tabChild) {
|
2016-10-07 00:20:58 +00:00
|
|
|
JS::AutoAssertOnGC nogc(mContext);
|
2016-10-05 23:29:13 +00:00
|
|
|
JS::AutoAssertOnBarrier nobarrier(mContext);
|
2016-07-22 23:36:45 +00:00
|
|
|
tabChild->ForcePaint(forcePaintEpoch);
|
2016-10-19 18:33:13 +00:00
|
|
|
mForcePaintMonitor->NotifyWait();
|
2016-07-22 23:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void
|
|
|
|
HangMonitorChild::Shutdown()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorChild::ShutdownOnThread()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mShutdownDone = true;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
mIPCOpen = false;
|
|
|
|
|
|
|
|
// We use a task here to ensure that IPDL is finished with this
|
|
|
|
// HangMonitorChild before it gets deleted on the main thread.
|
2016-05-05 08:45:00 +00:00
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, &HangMonitorChild::ShutdownOnThread));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangMonitorChild::RecvTerminateScript()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mTerminateScript = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangMonitorChild::RecvBeginStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mStartDebugger = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangMonitorChild::RecvEndStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mFinishedStartingDebugger = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
bool
|
|
|
|
HangMonitorChild::RecvForcePaint(const TabId& aTabId, const uint64_t& aLayerObserverEpoch)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
2016-10-19 18:33:13 +00:00
|
|
|
mForcePaintMonitor->NotifyActivity();
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-10-18 00:59:55 +00:00
|
|
|
mForcePaint = true;
|
2016-07-22 23:36:45 +00:00
|
|
|
mForcePaintTab = aTabId;
|
|
|
|
mForcePaintEpoch = aLayerObserverEpoch;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_RequestInterruptCallback(mContext);
|
2016-10-07 00:20:58 +00:00
|
|
|
JS::RequestGCInterruptCallback(mContext);
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void
|
2015-04-01 08:40:35 +00:00
|
|
|
HangMonitorChild::Open(Transport* aTransport, ProcessId aPid,
|
2015-01-17 02:34:47 +00:00
|
|
|
MessageLoop* aIOLoop)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
MOZ_ASSERT(!sInstance);
|
|
|
|
sInstance = this;
|
|
|
|
|
2015-04-01 08:40:35 +00:00
|
|
|
DebugOnly<bool> ok = PProcessHangMonitorChild::Open(aTransport, aPid, aIOLoop);
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorChild::NotifySlowScriptAsync(TabId aTabId,
|
|
|
|
const nsCString& aFileName,
|
|
|
|
unsigned aLineNo)
|
|
|
|
{
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendHangEvidence(SlowScriptData(aTabId, aFileName, aLineNo));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::SlowScriptAction
|
|
|
|
HangMonitorChild::NotifySlowScript(nsITabChild* aTabChild,
|
|
|
|
const char* aFileName,
|
|
|
|
unsigned aLineNo)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mSentReport = true;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mTerminateScript) {
|
|
|
|
mTerminateScript = false;
|
|
|
|
return SlowScriptAction::Terminate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStartDebugger) {
|
|
|
|
mStartDebugger = false;
|
|
|
|
return SlowScriptAction::StartDebugger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId id;
|
|
|
|
if (aTabChild) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TabChild> tabChild = static_cast<TabChild*>(aTabChild);
|
2015-01-17 02:34:47 +00:00
|
|
|
id = tabChild->GetTabId();
|
|
|
|
}
|
|
|
|
nsAutoCString filename(aFileName);
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod
|
|
|
|
<TabId, nsCString, unsigned>(this,
|
|
|
|
&HangMonitorChild::NotifySlowScriptAsync,
|
|
|
|
id, filename, aLineNo));
|
2015-01-17 02:34:47 +00:00
|
|
|
return SlowScriptAction::Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangMonitorChild::IsDebuggerStartupComplete()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mFinishedStartingDebugger) {
|
|
|
|
mFinishedStartingDebugger = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorChild::NotifyPluginHang(uint32_t aPluginId)
|
|
|
|
{
|
2015-06-11 17:25:45 +00:00
|
|
|
// main thread in the child
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mSentReport = true;
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
// bounce to background thread
|
2016-06-11 22:25:25 +00:00
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod<uint32_t>(this,
|
|
|
|
&HangMonitorChild::NotifyPluginHangAsync,
|
|
|
|
aPluginId));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-11 22:25:25 +00:00
|
|
|
HangMonitorChild::NotifyPluginHangAsync(uint32_t aPluginId)
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
// bounce back to parent on background thread
|
2015-01-17 02:34:47 +00:00
|
|
|
if (mIPCOpen) {
|
2016-03-03 07:24:36 +00:00
|
|
|
Unused << SendHangEvidence(PluginHangData(aPluginId,
|
2016-06-11 22:25:25 +00:00
|
|
|
base::GetCurrentProcId()));
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorChild::ClearHang()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mSentReport) {
|
2016-04-01 23:54:25 +00:00
|
|
|
// bounce to background thread
|
2016-05-05 08:45:00 +00:00
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, &HangMonitorChild::ClearHangAsync));
|
2016-04-01 23:54:25 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mSentReport = false;
|
|
|
|
mTerminateScript = false;
|
|
|
|
mStartDebugger = false;
|
|
|
|
mFinishedStartingDebugger = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 23:54:25 +00:00
|
|
|
void
|
|
|
|
HangMonitorChild::ClearHangAsync()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
// bounce back to parent on background thread
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Unused << SendClearHang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
/* HangMonitorParent implementation */
|
|
|
|
|
|
|
|
HangMonitorParent::HangMonitorParent(ProcessHangMonitor* aMonitor)
|
|
|
|
: mHangMonitor(aMonitor),
|
|
|
|
mIPCOpen(true),
|
|
|
|
mMonitor("HangMonitorParent lock"),
|
2015-06-11 17:25:45 +00:00
|
|
|
mShutdownDone(false),
|
|
|
|
mBrowserCrashDumpHashLock("mBrowserCrashDumpIds lock")
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
mReportHangs = mozilla::Preferences::GetBool("dom.ipc.reportProcessHangs", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorParent::~HangMonitorParent()
|
|
|
|
{
|
2015-11-02 04:18:41 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2015-06-18 20:10:46 +00:00
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
2015-11-02 04:18:41 +00:00
|
|
|
|
|
|
|
for (auto iter = mBrowserCrashDumpIds.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsString crashId = iter.UserData();
|
|
|
|
if (!crashId.IsEmpty()) {
|
|
|
|
CrashReporter::DeleteMinidumpFilesForID(crashId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorParent::Shutdown()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mProcess) {
|
|
|
|
mProcess->Clear();
|
|
|
|
mProcess = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this,
|
|
|
|
&HangMonitorParent::ShutdownOnThread));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorParent::ShutdownOnThread()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
// mIPCOpen is only written from this thread, so need need to take the lock
|
|
|
|
// here. We'd be shooting ourselves in the foot, because ActorDestroy takes
|
|
|
|
// it.
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mShutdownDone = true;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
void
|
|
|
|
HangMonitorParent::ForcePaint(dom::TabParent* aTab, uint64_t aLayerObserverEpoch)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
TabId id = aTab->GetTabId();
|
|
|
|
MonitorLoop()->PostTask(NewNonOwningRunnableMethod<TabId, uint64_t>(
|
|
|
|
this, &HangMonitorParent::ForcePaintOnThread, id, aLayerObserverEpoch));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorParent::ForcePaintOnThread(TabId aTabId, uint64_t aLayerObserverEpoch)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Unused << SendForcePaint(aTabId, aLayerObserverEpoch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void
|
|
|
|
HangMonitorParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
mIPCOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-01 08:40:35 +00:00
|
|
|
HangMonitorParent::Open(Transport* aTransport, ProcessId aPid,
|
2015-01-17 02:34:47 +00:00
|
|
|
MessageLoop* aIOLoop)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
2015-04-01 08:40:35 +00:00
|
|
|
DebugOnly<bool> ok = PProcessHangMonitorParent::Open(aTransport, aPid, aIOLoop);
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class HangObserverNotifier final : public Runnable
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-06-11 17:25:45 +00:00
|
|
|
HangObserverNotifier(HangMonitoredProcess* aProcess,
|
2016-07-05 11:39:37 +00:00
|
|
|
HangMonitorParent *aParent,
|
2015-06-11 17:25:45 +00:00
|
|
|
const HangData& aHangData,
|
2016-07-05 11:39:37 +00:00
|
|
|
const nsString& aBrowserDumpId,
|
|
|
|
bool aTakeMinidump)
|
2015-01-17 02:34:47 +00:00
|
|
|
: mProcess(aProcess),
|
2016-07-05 11:39:37 +00:00
|
|
|
mParent(aParent),
|
2015-06-11 17:25:45 +00:00
|
|
|
mHangData(aHangData),
|
2016-07-05 11:39:37 +00:00
|
|
|
mBrowserDumpId(aBrowserDumpId),
|
|
|
|
mTakeMinidump(aTakeMinidump)
|
2015-01-17 02:34:47 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2016-08-08 02:18:10 +00:00
|
|
|
Run() override
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
2015-06-11 17:25:45 +00:00
|
|
|
// chrome process, main thread
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2016-06-24 12:25:08 +00:00
|
|
|
|
|
|
|
nsString dumpId;
|
2016-07-05 11:39:37 +00:00
|
|
|
if ((mHangData.type() == HangData::TPluginHangData) && mTakeMinidump) {
|
|
|
|
// We've been handed a partial minidump; complete it with plugin and
|
|
|
|
// content process dumps.
|
2016-06-24 12:25:08 +00:00
|
|
|
const PluginHangData& phd = mHangData.get_PluginHangData();
|
|
|
|
plugins::TakeFullMinidump(phd.pluginId(), phd.contentProcessId(),
|
|
|
|
mBrowserDumpId, dumpId);
|
2016-07-05 11:39:37 +00:00
|
|
|
mParent->UpdateMinidump(phd.pluginId(), dumpId);
|
|
|
|
} else {
|
|
|
|
// We already have a full minidump; go ahead and use it.
|
|
|
|
dumpId = mBrowserDumpId;
|
2016-06-24 12:25:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
mProcess->SetHangData(mHangData, dumpId);
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
observerService->NotifyObservers(mProcess, "process-hang-report", nullptr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HangMonitoredProcess> mProcess;
|
2016-07-05 11:39:37 +00:00
|
|
|
HangMonitorParent* mParent;
|
2015-01-17 02:34:47 +00:00
|
|
|
HangData mHangData;
|
2015-06-11 17:25:45 +00:00
|
|
|
nsAutoString mBrowserDumpId;
|
2016-07-05 11:39:37 +00:00
|
|
|
bool mTakeMinidump;
|
2015-01-17 02:34:47 +00:00
|
|
|
};
|
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
// Take a minidump of the browser process if one wasn't already taken for the
|
|
|
|
// plugin that caused the hang. Return false if a dump was already available or
|
|
|
|
// true if new one has been taken.
|
|
|
|
bool
|
|
|
|
HangMonitorParent::TakeBrowserMinidump(const PluginHangData& aPhd,
|
|
|
|
nsString& aCrashId)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
|
|
|
if (!mBrowserCrashDumpIds.Get(aPhd.pluginId(), &aCrashId)) {
|
|
|
|
nsCOMPtr<nsIFile> browserDump;
|
|
|
|
if (CrashReporter::TakeMinidump(getter_AddRefs(browserDump), true)) {
|
|
|
|
if (!CrashReporter::GetIDFromMinidump(browserDump, aCrashId)
|
|
|
|
|| aCrashId.IsEmpty()) {
|
|
|
|
browserDump->Remove(false);
|
|
|
|
NS_WARNING("Failed to generate timely browser stack, "
|
|
|
|
"this is bad for plugin hang analysis!");
|
|
|
|
} else {
|
|
|
|
mBrowserCrashDumpIds.Put(aPhd.pluginId(), aCrashId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_CRASHREPORTER
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
bool
|
|
|
|
HangMonitorParent::RecvHangEvidence(const HangData& aHangData)
|
|
|
|
{
|
2015-06-11 17:25:45 +00:00
|
|
|
// chrome process, background thread
|
2015-01-17 02:34:47 +00:00
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (!mReportHangs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-22 23:53:49 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Don't report hangs if we're debugging the process. You can comment this
|
|
|
|
// line out for testing purposes.
|
|
|
|
if (IsDebuggerPresent()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
// Before we wake up the browser main thread we want to take a
|
|
|
|
// browser minidump.
|
|
|
|
nsAutoString crashId;
|
2016-07-05 11:39:37 +00:00
|
|
|
bool takeMinidump = false;
|
2015-06-11 17:25:45 +00:00
|
|
|
if (aHangData.type() == HangData::TPluginHangData) {
|
2016-07-05 11:39:37 +00:00
|
|
|
takeMinidump = TakeBrowserMinidump(aHangData.get_PluginHangData(), crashId);
|
2015-06-11 17:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
nsCOMPtr<nsIRunnable> notifier =
|
2016-07-05 11:39:37 +00:00
|
|
|
new HangObserverNotifier(mProcess, this, aHangData, crashId, takeMinidump);
|
2015-01-17 02:34:47 +00:00
|
|
|
NS_DispatchToMainThread(notifier);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class ClearHangNotifier final : public Runnable
|
2016-04-01 23:54:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ClearHangNotifier(HangMonitoredProcess* aProcess)
|
|
|
|
: mProcess(aProcess)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2016-08-08 02:18:10 +00:00
|
|
|
Run() override
|
2016-04-01 23:54:25 +00:00
|
|
|
{
|
|
|
|
// chrome process, main thread
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
mProcess->ClearHang();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
observerService->NotifyObservers(mProcess, "clear-hang-report", nullptr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<HangMonitoredProcess> mProcess;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
HangMonitorParent::RecvClearHang()
|
|
|
|
{
|
|
|
|
// chrome process, background thread
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (!mReportHangs) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> notifier =
|
|
|
|
new ClearHangNotifier(mProcess);
|
|
|
|
NS_DispatchToMainThread(notifier);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
void
|
|
|
|
HangMonitorParent::TerminateScript()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendTerminateScript();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorParent::BeginStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendBeginStartingDebugger();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HangMonitorParent::EndStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << SendEndStartingDebugger();
|
2015-01-17 02:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
void
|
|
|
|
HangMonitorParent::CleanupPluginHang(uint32_t aPluginId, bool aRemoveFiles)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
|
|
|
nsAutoString crashId;
|
|
|
|
if (!mBrowserCrashDumpIds.Get(aPluginId, &crashId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBrowserCrashDumpIds.Remove(aPluginId);
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
if (aRemoveFiles && !crashId.IsEmpty()) {
|
|
|
|
CrashReporter::DeleteMinidumpFilesForID(crashId);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-05 11:39:37 +00:00
|
|
|
void
|
|
|
|
HangMonitorParent::UpdateMinidump(uint32_t aPluginId, const nsString& aDumpId)
|
|
|
|
{
|
|
|
|
if (aDumpId.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
|
|
|
mBrowserCrashDumpIds.Put(aPluginId, aDumpId);
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
/* HangMonitoredProcess implementation */
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(HangMonitoredProcess, nsIHangReport)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetHangType(uint32_t* aHangType)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
switch (mHangData.type()) {
|
|
|
|
case HangData::TSlowScriptData:
|
|
|
|
*aHangType = SLOW_SCRIPT;
|
|
|
|
break;
|
|
|
|
case HangData::TPluginHangData:
|
|
|
|
*aHangType = PLUGIN_HANG;
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-01 02:39:16 +00:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected HangData type");
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-06-01 02:39:16 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetScriptBrowser(nsIDOMElement** aBrowser)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId tabId = mHangData.get_SlowScriptData().tabId();
|
|
|
|
if (!mContentParent) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<PBrowserParent*> tabs;
|
|
|
|
mContentParent->ManagedPBrowserParent(tabs);
|
|
|
|
for (size_t i = 0; i < tabs.Length(); i++) {
|
2015-02-05 21:47:32 +00:00
|
|
|
TabParent* tp = TabParent::GetFrom(tabs[i]);
|
2015-01-17 02:34:47 +00:00
|
|
|
if (tp->GetTabId() == tabId) {
|
|
|
|
nsCOMPtr<nsIDOMElement> node = do_QueryInterface(tp->GetOwnerElement());
|
|
|
|
node.forget(aBrowser);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBrowser = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetScriptFileName(nsACString& aFileName)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aFileName = mHangData.get_SlowScriptData().filename();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetScriptLineNo(uint32_t* aLineNo)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLineNo = mHangData.get_SlowScriptData().lineno();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetPluginName(nsACString& aPluginName)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TPluginHangData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t id = mHangData.get_PluginHangData().pluginId();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
2015-01-17 02:34:47 +00:00
|
|
|
nsPluginTag* tag = host->PluginWithId(id);
|
|
|
|
if (!tag) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2015-05-20 13:30:05 +00:00
|
|
|
aPluginName = tag->Name();
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::TerminateScript()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor,
|
|
|
|
&HangMonitorParent::TerminateScript));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::BeginStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor,
|
|
|
|
&HangMonitorParent::BeginStartingDebugger));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::EndStartingDebugger()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor,
|
|
|
|
&HangMonitorParent::EndStartingDebugger));
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::TerminatePlugin()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TPluginHangData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:25:08 +00:00
|
|
|
// Use the multi-process crash report generated earlier.
|
2015-01-17 02:34:47 +00:00
|
|
|
uint32_t id = mHangData.get_PluginHangData().pluginId();
|
2016-03-03 07:24:36 +00:00
|
|
|
base::ProcessId contentPid = mHangData.get_PluginHangData().contentProcessId();
|
|
|
|
plugins::TerminatePlugin(id, contentPid, NS_LITERAL_CSTRING("HangMonitor"),
|
2016-06-24 12:25:08 +00:00
|
|
|
mDumpId);
|
2015-06-11 17:25:45 +00:00
|
|
|
|
2015-06-18 20:10:46 +00:00
|
|
|
if (mActor) {
|
|
|
|
mActor->CleanupPluginHang(id, false);
|
|
|
|
}
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::IsReportForBrowser(nsIFrameLoader* aFrameLoader, bool* aResult)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-05 21:47:32 +00:00
|
|
|
TabParent* tp = TabParent::GetFrom(aFrameLoader);
|
|
|
|
if (!tp) {
|
2015-01-17 02:34:47 +00:00
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-05 21:47:32 +00:00
|
|
|
*aResult = mContentParent == tp->Manager();
|
2015-01-17 02:34:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:25:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::UserCanceled()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TPluginHangData) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-18 20:10:46 +00:00
|
|
|
if (mActor) {
|
|
|
|
uint32_t id = mHangData.get_PluginHangData().pluginId();
|
|
|
|
mActor->CleanupPluginHang(id, true);
|
|
|
|
}
|
2015-06-11 17:25:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
static bool
|
|
|
|
InterruptCallback(JSContext* cx)
|
|
|
|
{
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->InterruptCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
ProcessHangMonitor* ProcessHangMonitor::sInstance;
|
|
|
|
|
|
|
|
ProcessHangMonitor::ProcessHangMonitor()
|
|
|
|
: mCPOWTimeout(false)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(ProcessHangMonitor);
|
|
|
|
|
2015-07-04 01:29:00 +00:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-01-17 02:34:47 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
mThread = new base::Thread("ProcessHangMonitor");
|
|
|
|
if (!mThread->Start()) {
|
|
|
|
delete mThread;
|
|
|
|
mThread = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::~ProcessHangMonitor()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(ProcessHangMonitor);
|
|
|
|
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
|
|
|
|
|
|
|
delete mThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor*
|
|
|
|
ProcessHangMonitor::GetOrCreate()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (!sInstance) {
|
|
|
|
sInstance = new ProcessHangMonitor();
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(ProcessHangMonitor, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ProcessHangMonitor::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->Shutdown();
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "xpcom-shutdown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::SlowScriptAction
|
|
|
|
ProcessHangMonitor::NotifySlowScript(nsITabChild* aTabChild,
|
|
|
|
const char* aFileName,
|
|
|
|
unsigned aLineNo)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
return HangMonitorChild::Get()->NotifySlowScript(aTabChild, aFileName, aLineNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessHangMonitor::IsDebuggerStartupComplete()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
return HangMonitorChild::Get()->IsDebuggerStartupComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessHangMonitor::ShouldTimeOutCPOWs()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mCPOWTimeout) {
|
|
|
|
mCPOWTimeout = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessHangMonitor::InitiateCPOWTimeout()
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(MessageLoop::current() == MonitorLoop());
|
|
|
|
mCPOWTimeout = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProcessHangMonitor::NotifyPluginHang(uint32_t aPluginId)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
return HangMonitorChild::Get()->NotifyPluginHang(aPluginId);
|
|
|
|
}
|
|
|
|
|
|
|
|
PProcessHangMonitorParent*
|
|
|
|
mozilla::CreateHangMonitorParent(ContentParent* aContentParent,
|
|
|
|
mozilla::ipc::Transport* aTransport,
|
2015-04-01 08:40:35 +00:00
|
|
|
base::ProcessId aOtherPid)
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
|
|
|
HangMonitorParent* parent = new HangMonitorParent(monitor);
|
|
|
|
|
|
|
|
HangMonitoredProcess* process = new HangMonitoredProcess(parent, aContentParent);
|
|
|
|
parent->SetProcess(process);
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
monitor->MonitorLoop()->PostTask(NewNonOwningRunnableMethod
|
|
|
|
<mozilla::ipc::Transport*,
|
|
|
|
base::ProcessId,
|
|
|
|
MessageLoop*>(parent,
|
|
|
|
&HangMonitorParent::Open,
|
|
|
|
aTransport, aOtherPid,
|
|
|
|
XRE_GetIOMessageLoop()));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
PProcessHangMonitorChild*
|
|
|
|
mozilla::CreateHangMonitorChild(mozilla::ipc::Transport* aTransport,
|
2015-04-01 08:40:35 +00:00
|
|
|
base::ProcessId aOtherPid)
|
2015-01-17 02:34:47 +00:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-07-22 23:36:45 +00:00
|
|
|
JSContext* cx = danger::GetJSContext();
|
|
|
|
JS_AddInterruptCallback(cx, InterruptCallback);
|
2016-10-07 00:20:58 +00:00
|
|
|
JS::AddGCInterruptCallback(cx, InterruptCallback);
|
2016-07-22 23:36:45 +00:00
|
|
|
|
2015-01-17 02:34:47 +00:00
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
|
|
|
HangMonitorChild* child = new HangMonitorChild(monitor);
|
|
|
|
|
2016-05-05 08:45:00 +00:00
|
|
|
monitor->MonitorLoop()->PostTask(NewNonOwningRunnableMethod
|
|
|
|
<mozilla::ipc::Transport*,
|
|
|
|
base::ProcessId,
|
|
|
|
MessageLoop*>(child,
|
|
|
|
&HangMonitorChild::Open,
|
|
|
|
aTransport, aOtherPid,
|
|
|
|
XRE_GetIOMessageLoop()));
|
2015-01-17 02:34:47 +00:00
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageLoop*
|
|
|
|
ProcessHangMonitor::MonitorLoop()
|
|
|
|
{
|
|
|
|
return mThread->message_loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ProcessHangMonitor::AddProcess(ContentParent* aContentParent)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mozilla::Preferences::GetBool("dom.ipc.processHangMonitor", false)) {
|
|
|
|
DebugOnly<bool> opened = PProcessHangMonitor::Open(aContentParent);
|
|
|
|
MOZ_ASSERT(opened);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ProcessHangMonitor::RemoveProcess(PProcessHangMonitorParent* aParent)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
|
|
|
parent->Shutdown();
|
|
|
|
delete parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ProcessHangMonitor::ClearHang()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->ClearHang();
|
|
|
|
}
|
|
|
|
}
|
2016-07-22 23:36:45 +00:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ProcessHangMonitor::ForcePaint(PProcessHangMonitorParent* aParent,
|
|
|
|
dom::TabParent* aTabParent,
|
|
|
|
uint64_t aLayerObserverEpoch)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
|
|
|
parent->ForcePaint(aTabParent, aLayerObserverEpoch);
|
|
|
|
}
|