2015-01-17 05:34:47 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-01-17 05:34:47 +03: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-23 02:36:45 +03:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2016-10-19 21:33:13 +03:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2016-07-23 02:36:45 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
2017-03-01 01:22:02 +03:00
|
|
|
#include "mozilla/ipc/TaskFactory.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/plugins/PluginBridge.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-07-28 11:55:16 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-10-10 13:43:09 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2018-03-22 05:43:17 +03:00
|
|
|
#include "nsFrameLoader.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "nsIHangReport.h"
|
|
|
|
#include "nsITabParent.h"
|
2018-03-22 05:43:17 +03:00
|
|
|
#include "nsQueryObject.h"
|
2015-01-17 05:34:47 +03:00
|
|
|
#include "nsPluginHost.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
|
2015-01-23 02:53:49 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// For IsDebuggerPresent()
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2017-01-05 23:54:52 +03:00
|
|
|
using namespace mozilla::ipc;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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,
|
2018-07-16 06:45:32 +03:00
|
|
|
public BackgroundHangAnnotator {
|
2015-01-17 05:34:47 +03:00
|
|
|
public:
|
|
|
|
explicit HangMonitorChild(ProcessHangMonitor* aMonitor);
|
2016-11-15 14:09:07 +03:00
|
|
|
~HangMonitorChild() override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
void Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
typedef ProcessHangMonitor::SlowScriptAction SlowScriptAction;
|
|
|
|
SlowScriptAction NotifySlowScript(nsITabChild* aTabChild,
|
2017-08-18 06:17:51 +03:00
|
|
|
const char* aFileName,
|
|
|
|
const nsString& aAddonId);
|
2015-01-17 05:34:47 +03:00
|
|
|
void NotifySlowScriptAsync(TabId aTabId, const nsCString& aFileName,
|
2017-08-18 06:17:51 +03:00
|
|
|
const nsString& aAddonId);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
bool IsDebuggerStartupComplete();
|
|
|
|
|
|
|
|
void NotifyPluginHang(uint32_t aPluginId);
|
2016-06-12 01:25:25 +03:00
|
|
|
void NotifyPluginHangAsync(uint32_t aPluginId);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
void ClearHang();
|
2016-04-02 02:54:25 +03:00
|
|
|
void ClearHangAsync();
|
2018-07-30 16:24:50 +03:00
|
|
|
void ClearPaintWhileInterruptingJS(const LayersObserverEpoch& aEpoch);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
// MaybeStartPaintWhileInterruptingJS will notify the background hang monitor
|
|
|
|
// of activity if this is the first time calling it since
|
|
|
|
// ClearPaintWhileInterruptingJS. It should be callable from any thread, but
|
2018-03-18 21:44:19 +03:00
|
|
|
// you must be holding mMonitor if using it off the main thread, since it
|
2018-05-15 09:45:00 +03:00
|
|
|
// could race with ClearPaintWhileInterruptingJS.
|
|
|
|
void MaybeStartPaintWhileInterruptingJS();
|
2018-03-18 21:44:19 +03:00
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
mozilla::ipc::IPCResult RecvTerminateScript(
|
|
|
|
const bool& aTerminateGlobal) override;
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvBeginStartingDebugger() override;
|
|
|
|
mozilla::ipc::IPCResult RecvEndStartingDebugger() override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvPaintWhileInterruptingJS(
|
|
|
|
const TabId& aTabId, const bool& aForceRepaint,
|
2018-07-30 16:24:50 +03:00
|
|
|
const LayersObserverEpoch& aEpoch) override;
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
void InterruptCallback();
|
2015-01-17 05:34:47 +03:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
static HangMonitorChild* Get() { return sInstance; }
|
|
|
|
|
2017-05-20 06:36:10 +03:00
|
|
|
void Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 22:15:35 +03:00
|
|
|
mHangMonitor->Dispatch(std::move(aRunnable));
|
2017-05-20 06:36:10 +03:00
|
|
|
}
|
|
|
|
bool IsOnThread() { return mHangMonitor->IsOnThread(); }
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2018-07-16 06:45:32 +03:00
|
|
|
void AnnotateHang(BackgroundHangAnnotations& aAnnotations) override;
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
private:
|
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2018-07-21 17:29:53 +03:00
|
|
|
// Ordering of this atomic is not preserved while recording/replaying, as it
|
|
|
|
// may be accessed during the JS interrupt callback.
|
|
|
|
static Atomic<HangMonitorChild*, SequentiallyConsistent,
|
|
|
|
recordreplay::Behavior::DontPreserve>
|
|
|
|
sInstance;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 05:34:47 +03:00
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// Main thread-only.
|
|
|
|
bool mSentReport;
|
|
|
|
|
|
|
|
// These fields must be accessed with mMonitor held.
|
|
|
|
bool mTerminateScript;
|
2017-04-17 00:01:16 +03:00
|
|
|
bool mTerminateGlobal;
|
2015-01-17 05:34:47 +03:00
|
|
|
bool mStartDebugger;
|
|
|
|
bool mFinishedStartingDebugger;
|
2018-05-15 09:45:00 +03:00
|
|
|
bool mPaintWhileInterruptingJS;
|
|
|
|
bool mPaintWhileInterruptingJSForce;
|
|
|
|
TabId mPaintWhileInterruptingJSTab;
|
2018-07-30 16:24:50 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR LayersObserverEpoch mPaintWhileInterruptingJSEpoch;
|
2016-07-23 02:36:45 +03:00
|
|
|
JSContext* mContext;
|
2015-01-17 05:34:47 +03:00
|
|
|
bool mShutdownDone;
|
|
|
|
|
|
|
|
// This field is only accessed on the hang thread.
|
|
|
|
bool mIPCOpen;
|
2018-03-18 21:44:19 +03:00
|
|
|
|
|
|
|
// Allows us to ensure we NotifyActivity only once, allowing
|
|
|
|
// either thread to do so.
|
2018-07-16 06:45:32 +03:00
|
|
|
Atomic<bool> mPaintWhileInterruptingJSActive;
|
2015-01-17 05:34:47 +03:00
|
|
|
};
|
|
|
|
|
2018-07-21 17:29:53 +03:00
|
|
|
Atomic<HangMonitorChild*, SequentiallyConsistent,
|
|
|
|
recordreplay::Behavior::DontPreserve>
|
|
|
|
HangMonitorChild::sInstance;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
/* Parent process objects */
|
|
|
|
|
|
|
|
class HangMonitorParent;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class HangMonitoredProcess final : public nsIHangReport {
|
2015-01-17 05:34:47 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
HangMonitoredProcess(HangMonitorParent* aActor, ContentParent* aContentParent)
|
|
|
|
: mActor(aActor), mContentParent(aContentParent) {}
|
|
|
|
|
2018-04-27 06:36:10 +03:00
|
|
|
NS_DECL_NSIHANGREPORT
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2015-06-18 23:10:46 +03:00
|
|
|
// Called when a content process shuts down.
|
2015-06-11 20:25:45 +03:00
|
|
|
void Clear() {
|
|
|
|
mContentParent = nullptr;
|
|
|
|
mActor = nullptr;
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-07-05 14:39:37 +03: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 15:25:08 +03:00
|
|
|
*
|
|
|
|
* @param aHangData The hang information
|
2016-07-05 14:39:37 +03:00
|
|
|
* @param aDumpId The ID of a minidump taken when the hang occurred
|
2016-06-24 15:25:08 +03:00
|
|
|
*/
|
2016-07-05 14:39:37 +03:00
|
|
|
void SetHangData(const HangData& aHangData, const nsAString& aDumpId) {
|
|
|
|
mHangData = aHangData;
|
|
|
|
mDumpId = aDumpId;
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-04-02 02:54:25 +03:00
|
|
|
void ClearHang() {
|
|
|
|
mHangData = HangData();
|
2016-06-24 15:25:08 +03:00
|
|
|
mDumpId.Truncate();
|
2016-04-02 02:54:25 +03:00
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
private:
|
2016-11-14 12:40:37 +03:00
|
|
|
~HangMonitoredProcess() = default;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
// Everything here is main thread-only.
|
|
|
|
HangMonitorParent* mActor;
|
|
|
|
ContentParent* mContentParent;
|
|
|
|
HangData mHangData;
|
2016-06-24 15:25:08 +03:00
|
|
|
nsAutoString mDumpId;
|
2015-01-17 05:34:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class HangMonitorParent : public PProcessHangMonitorParent,
|
2017-07-28 11:55:16 +03:00
|
|
|
public SupportsWeakPtr<HangMonitorParent> {
|
2015-01-17 05:34:47 +03:00
|
|
|
public:
|
|
|
|
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
|
2016-11-15 14:09:07 +03:00
|
|
|
~HangMonitorParent() override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-07-28 11:55:16 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HangMonitorParent)
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvHangEvidence(const HangData& aHangData) override;
|
|
|
|
mozilla::ipc::IPCResult RecvClearHang() override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
void SetProcess(HangMonitoredProcess* aProcess) { mProcess = aProcess; }
|
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
void PaintWhileInterruptingJS(dom::TabParent* aTabParent, bool aForceRepaint,
|
2018-07-30 16:24:50 +03:00
|
|
|
const LayersObserverEpoch& aEpoch);
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
void TerminateScript(bool aTerminateGlobal);
|
2015-01-17 05:34:47 +03:00
|
|
|
void BeginStartingDebugger();
|
|
|
|
void EndStartingDebugger();
|
2015-06-11 20:25:45 +03:00
|
|
|
void CleanupPluginHang(uint32_t aPluginId, bool aRemoveFiles);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-07-05 14:39:37 +03: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);
|
|
|
|
|
2017-05-20 06:36:10 +03:00
|
|
|
void Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 22:15:35 +03:00
|
|
|
mHangMonitor->Dispatch(std::move(aRunnable));
|
2017-05-20 06:36:10 +03:00
|
|
|
}
|
|
|
|
bool IsOnThread() { return mHangMonitor->IsOnThread(); }
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-07-05 14:39:37 +03:00
|
|
|
private:
|
|
|
|
bool TakeBrowserMinidump(const PluginHangData& aPhd, nsString& aCrashId);
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2017-03-06 23:55:36 +03:00
|
|
|
void SendHangNotification(const HangData& aHangData,
|
|
|
|
const nsString& aBrowserDumpId, bool aTakeMinidump);
|
|
|
|
|
|
|
|
void ClearHangNotification();
|
|
|
|
|
2018-07-30 16:24:50 +03:00
|
|
|
void PaintWhileInterruptingJSOnThread(TabId aTabId, bool aForceRepaint,
|
|
|
|
const LayersObserverEpoch& aEpoch);
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
void ShutdownOnThread();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
const RefPtr<ProcessHangMonitor> mHangMonitor;
|
2015-01-17 05:34:47 +03: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 08:24:48 +03:00
|
|
|
RefPtr<HangMonitoredProcess> mProcess;
|
2015-01-17 05:34:47 +03:00
|
|
|
bool mShutdownDone;
|
2015-06-11 20:25:45 +03:00
|
|
|
// Map from plugin ID to crash dump ID. Protected by
|
|
|
|
// mBrowserCrashDumpHashLock.
|
|
|
|
nsDataHashtable<nsUint32HashKey, nsString> mBrowserCrashDumpIds;
|
|
|
|
Mutex mBrowserCrashDumpHashLock;
|
2017-03-01 01:22:02 +03:00
|
|
|
mozilla::ipc::TaskFactory<HangMonitorParent> mMainThreadTaskFactory;
|
2017-03-01 23:36:51 +03:00
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
static bool sShouldPaintWhileInterruptingJS;
|
2015-01-17 05:34:47 +03:00
|
|
|
};
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
bool HangMonitorParent::sShouldPaintWhileInterruptingJS = true;
|
2017-03-01 23:36:51 +03:00
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/* HangMonitorChild implementation */
|
|
|
|
|
|
|
|
HangMonitorChild::HangMonitorChild(ProcessHangMonitor* aMonitor)
|
2018-04-13 16:01:28 +03:00
|
|
|
: mHangMonitor(aMonitor),
|
2018-07-21 17:29:53 +03:00
|
|
|
// Ordering of this atomic is not preserved while recording/replaying, as
|
|
|
|
// it may be accessed during the JS interrupt callback.
|
|
|
|
mMonitor("HangMonitorChild lock", recordreplay::Behavior::DontPreserve),
|
2018-04-13 16:01:28 +03:00
|
|
|
mSentReport(false),
|
|
|
|
mTerminateScript(false),
|
|
|
|
mTerminateGlobal(false),
|
|
|
|
mStartDebugger(false),
|
|
|
|
mFinishedStartingDebugger(false),
|
2018-05-15 09:45:00 +03:00
|
|
|
mPaintWhileInterruptingJS(false),
|
|
|
|
mPaintWhileInterruptingJSForce(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mShutdownDone(false),
|
2018-07-16 06:45:32 +03:00
|
|
|
mIPCOpen(true),
|
|
|
|
mPaintWhileInterruptingJSActive(false) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2016-07-23 02:36:45 +03:00
|
|
|
mContext = danger::GetJSContext();
|
2018-07-16 06:45:32 +03:00
|
|
|
|
|
|
|
BackgroundHangMonitor::RegisterAnnotator(*this);
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::~HangMonitorChild() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
void HangMonitorChild::InterruptCallback() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
bool paintWhileInterruptingJS;
|
|
|
|
bool paintWhileInterruptingJSForce;
|
|
|
|
TabId paintWhileInterruptingJSTab;
|
2018-07-30 16:24:50 +03:00
|
|
|
LayersObserverEpoch paintWhileInterruptingJSEpoch;
|
2016-07-23 02:36:45 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2018-05-15 09:45:00 +03:00
|
|
|
paintWhileInterruptingJS = mPaintWhileInterruptingJS;
|
|
|
|
paintWhileInterruptingJSForce = mPaintWhileInterruptingJSForce;
|
|
|
|
paintWhileInterruptingJSTab = mPaintWhileInterruptingJSTab;
|
|
|
|
paintWhileInterruptingJSEpoch = mPaintWhileInterruptingJSEpoch;
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
mPaintWhileInterruptingJS = false;
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
|
2018-07-23 17:57:42 +03:00
|
|
|
// Don't paint from the interrupt callback when recording or replaying, as
|
|
|
|
// the interrupt callback is triggered non-deterministically.
|
|
|
|
if (paintWhileInterruptingJS && !recordreplay::IsRecordingOrReplaying()) {
|
2018-05-15 09:45:00 +03:00
|
|
|
RefPtr<TabChild> tabChild =
|
|
|
|
TabChild::FindTabChild(paintWhileInterruptingJSTab);
|
2016-07-23 02:36:45 +03:00
|
|
|
if (tabChild) {
|
2017-01-12 03:04:40 +03:00
|
|
|
js::AutoAssertNoContentJS nojs(mContext);
|
2018-05-15 09:45:00 +03:00
|
|
|
tabChild->PaintWhileInterruptingJS(paintWhileInterruptingJSEpoch,
|
|
|
|
paintWhileInterruptingJSForce);
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 06:45:32 +03:00
|
|
|
void HangMonitorChild::AnnotateHang(BackgroundHangAnnotations& aAnnotations) {
|
2018-09-18 20:06:30 +03:00
|
|
|
if (mPaintWhileInterruptingJSActive) {
|
2018-07-16 06:45:32 +03:00
|
|
|
aAnnotations.AddAnnotation(NS_LITERAL_STRING("PaintWhileInterruptingJS"),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
void HangMonitorChild::Shutdown() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-01-07 20:02:59 +03:00
|
|
|
BackgroundHangMonitor::UnregisterAnnotator(*this);
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ShutdownOnThread() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mShutdownDone = true;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
mIPCOpen = false;
|
|
|
|
|
|
|
|
// We use a task here to ensure that IPDL is finished with this
|
|
|
|
// HangMonitorChild before it gets deleted on the main thread.
|
2017-06-12 22:34:10 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorChild::ShutdownOnThread",
|
|
|
|
this,
|
|
|
|
&HangMonitorChild::ShutdownOnThread));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvTerminateScript(
|
|
|
|
const bool& aTerminateGlobal) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2017-04-17 00:01:16 +03:00
|
|
|
if (aTerminateGlobal) {
|
|
|
|
mTerminateGlobal = true;
|
|
|
|
} else {
|
|
|
|
mTerminateScript = true;
|
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvBeginStartingDebugger() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mStartDebugger = true;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvEndStartingDebugger() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mFinishedStartingDebugger = true;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
mozilla::ipc::IPCResult HangMonitorChild::RecvPaintWhileInterruptingJS(
|
|
|
|
const TabId& aTabId, const bool& aForceRepaint,
|
2018-07-30 16:24:50 +03:00
|
|
|
const LayersObserverEpoch& aEpoch) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-07-23 02:36:45 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2018-05-15 09:45:00 +03:00
|
|
|
MaybeStartPaintWhileInterruptingJS();
|
|
|
|
mPaintWhileInterruptingJS = true;
|
|
|
|
mPaintWhileInterruptingJSForce = aForceRepaint;
|
|
|
|
mPaintWhileInterruptingJSTab = aTabId;
|
2018-07-30 16:24:50 +03:00
|
|
|
mPaintWhileInterruptingJSEpoch = aEpoch;
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_RequestInterruptCallback(mContext);
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
void HangMonitorChild::MaybeStartPaintWhileInterruptingJS() {
|
2018-07-16 06:45:32 +03:00
|
|
|
mPaintWhileInterruptingJSActive = true;
|
2018-03-18 21:44:19 +03:00
|
|
|
}
|
|
|
|
|
2018-07-30 16:24:50 +03:00
|
|
|
void HangMonitorChild::ClearPaintWhileInterruptingJS(
|
|
|
|
const LayersObserverEpoch& aEpoch) {
|
2016-10-21 21:56:46 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
2018-07-16 06:45:32 +03:00
|
|
|
mPaintWhileInterruptingJSActive = false;
|
2016-10-21 21:56:46 +03:00
|
|
|
}
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
void HangMonitorChild::Bind(Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!sInstance);
|
|
|
|
sInstance = this;
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
DebugOnly<bool> ok = aEndpoint.Bind(this);
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::NotifySlowScriptAsync(TabId aTabId,
|
2017-08-18 06:17:51 +03:00
|
|
|
const nsCString& aFileName,
|
|
|
|
const nsString& aAddonId) {
|
2015-01-17 05:34:47 +03:00
|
|
|
if (mIPCOpen) {
|
2017-08-18 06:17:51 +03:00
|
|
|
Unused << SendHangEvidence(SlowScriptData(aTabId, aFileName, aAddonId));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorChild::SlowScriptAction HangMonitorChild::NotifySlowScript(
|
2017-08-18 06:17:51 +03:00
|
|
|
nsITabChild* aTabChild, const char* aFileName, const nsString& aAddonId) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mSentReport = true;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mTerminateScript) {
|
|
|
|
mTerminateScript = false;
|
|
|
|
return SlowScriptAction::Terminate;
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
if (mTerminateGlobal) {
|
|
|
|
mTerminateGlobal = false;
|
|
|
|
return SlowScriptAction::TerminateGlobal;
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
if (mStartDebugger) {
|
|
|
|
mStartDebugger = false;
|
|
|
|
return SlowScriptAction::StartDebugger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TabId id;
|
|
|
|
if (aTabChild) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TabChild> tabChild = static_cast<TabChild*>(aTabChild);
|
2015-01-17 05:34:47 +03:00
|
|
|
id = tabChild->GetTabId();
|
|
|
|
}
|
|
|
|
nsAutoCString filename(aFileName);
|
|
|
|
|
2017-08-18 06:17:51 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<TabId, nsCString, nsString>(
|
2017-06-12 22:34:10 +03:00
|
|
|
"HangMonitorChild::NotifySlowScriptAsync", this,
|
|
|
|
&HangMonitorChild::NotifySlowScriptAsync, id, filename, aAddonId));
|
2015-01-17 05:34:47 +03: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 20:25:45 +03:00
|
|
|
// main thread in the child
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mSentReport = true;
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
// bounce to background thread
|
2017-06-12 22:34:10 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<uint32_t>(
|
|
|
|
"HangMonitorChild::NotifyPluginHangAsync", this,
|
|
|
|
&HangMonitorChild::NotifyPluginHangAsync, aPluginId));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-06-12 01:25:25 +03:00
|
|
|
void HangMonitorChild::NotifyPluginHangAsync(uint32_t aPluginId) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
// bounce back to parent on background thread
|
2015-01-17 05:34:47 +03:00
|
|
|
if (mIPCOpen) {
|
2016-03-03 10:24:36 +03:00
|
|
|
Unused << SendHangEvidence(
|
2016-06-12 01:25:25 +03:00
|
|
|
PluginHangData(aPluginId, base::GetCurrentProcId()));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorChild::ClearHang() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mSentReport) {
|
2016-04-02 02:54:25 +03:00
|
|
|
// bounce to background thread
|
2017-06-12 22:34:10 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorChild::ClearHangAsync",
|
|
|
|
this,
|
|
|
|
&HangMonitorChild::ClearHangAsync));
|
2016-04-02 02:54:25 +03:00
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mSentReport = false;
|
|
|
|
mTerminateScript = false;
|
2017-04-17 00:01:16 +03:00
|
|
|
mTerminateGlobal = false;
|
2015-01-17 05:34:47 +03:00
|
|
|
mStartDebugger = false;
|
|
|
|
mFinishedStartingDebugger = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 02:54:25 +03:00
|
|
|
void HangMonitorChild::ClearHangAsync() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-04-02 02:54:25 +03:00
|
|
|
|
|
|
|
// bounce back to parent on background thread
|
|
|
|
if (mIPCOpen) {
|
|
|
|
Unused << SendClearHang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/* HangMonitorParent implementation */
|
|
|
|
|
|
|
|
HangMonitorParent::HangMonitorParent(ProcessHangMonitor* aMonitor)
|
|
|
|
: mHangMonitor(aMonitor),
|
|
|
|
mIPCOpen(true),
|
|
|
|
mMonitor("HangMonitorParent lock"),
|
2015-06-11 20:25:45 +03:00
|
|
|
mShutdownDone(false),
|
2017-03-01 01:22:02 +03:00
|
|
|
mBrowserCrashDumpHashLock("mBrowserCrashDumpIds lock"),
|
|
|
|
mMainThreadTaskFactory(this) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
mReportHangs =
|
|
|
|
mozilla::Preferences::GetBool("dom.ipc.reportProcessHangs", false);
|
2017-03-01 23:36:51 +03:00
|
|
|
|
|
|
|
static bool sInited = false;
|
|
|
|
if (!sInited) {
|
|
|
|
sInited = true;
|
2018-05-15 09:45:00 +03:00
|
|
|
Preferences::AddBoolVarCache(&sShouldPaintWhileInterruptingJS,
|
2017-03-01 23:36:51 +03:00
|
|
|
"browser.tabs.remote.force-paint", true);
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HangMonitorParent::~HangMonitorParent() {
|
2015-06-18 23:10:46 +03:00
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
2015-11-02 07:18:41 +03:00
|
|
|
|
|
|
|
for (auto iter = mBrowserCrashDumpIds.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsString crashId = iter.UserData();
|
|
|
|
if (!crashId.IsEmpty()) {
|
|
|
|
CrashReporter::DeleteMinidumpFilesForID(crashId);
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::Shutdown() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mProcess) {
|
|
|
|
mProcess->Clear();
|
|
|
|
mProcess = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod("HangMonitorParent::ShutdownOnThread",
|
|
|
|
this,
|
2017-05-20 06:36:10 +03:00
|
|
|
&HangMonitorParent::ShutdownOnThread));
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
while (!mShutdownDone) {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::ShutdownOnThread() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
void HangMonitorParent::PaintWhileInterruptingJS(
|
|
|
|
dom::TabParent* aTab, bool aForceRepaint,
|
2018-07-30 16:24:50 +03:00
|
|
|
const LayersObserverEpoch& aEpoch) {
|
2016-07-23 02:36:45 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2018-05-15 09:45:00 +03:00
|
|
|
if (sShouldPaintWhileInterruptingJS) {
|
2017-03-01 23:36:51 +03:00
|
|
|
TabId id = aTab->GetTabId();
|
2018-07-30 16:24:50 +03:00
|
|
|
Dispatch(NewNonOwningRunnableMethod<TabId, bool, LayersObserverEpoch>(
|
2018-05-15 09:45:00 +03:00
|
|
|
"HangMonitorParent::PaintWhileInterruptingJSOnThread", this,
|
|
|
|
&HangMonitorParent::PaintWhileInterruptingJSOnThread, id, aForceRepaint,
|
2018-07-30 16:24:50 +03:00
|
|
|
aEpoch));
|
2017-03-01 23:36:51 +03:00
|
|
|
}
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 09:45:00 +03:00
|
|
|
void HangMonitorParent::PaintWhileInterruptingJSOnThread(
|
2018-07-30 16:24:50 +03:00
|
|
|
TabId aTabId, bool aForceRepaint, const LayersObserverEpoch& aEpoch) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-07-23 02:36:45 +03:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2018-07-30 16:24:50 +03:00
|
|
|
Unused << SendPaintWhileInterruptingJS(aTabId, aForceRepaint, aEpoch);
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
void HangMonitorParent::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
mIPCOpen = false;
|
|
|
|
}
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
void HangMonitorParent::Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
DebugOnly<bool> ok = aEndpoint.Bind(this);
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
2017-03-06 23:55:36 +03:00
|
|
|
void HangMonitorParent::SendHangNotification(const HangData& aHangData,
|
|
|
|
const nsString& aBrowserDumpId,
|
|
|
|
bool aTakeMinidump) {
|
|
|
|
// chrome process, main thread
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
nsString dumpId;
|
2017-03-06 23:55:36 +03:00
|
|
|
if ((aHangData.type() == HangData::TPluginHangData) && aTakeMinidump) {
|
|
|
|
// We've been handed a partial minidump; complete it with plugin and
|
|
|
|
// content process dumps.
|
|
|
|
const PluginHangData& phd = aHangData.get_PluginHangData();
|
2017-06-22 13:52:58 +03:00
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
plugins::TakeFullMinidump(phd.pluginId(), phd.contentProcessId(),
|
|
|
|
aBrowserDumpId, dumpId);
|
|
|
|
UpdateMinidump(phd.pluginId(), dumpId);
|
2017-03-06 23:55:36 +03:00
|
|
|
} else {
|
|
|
|
// We already have a full minidump; go ahead and use it.
|
2018-09-17 23:51:45 +03:00
|
|
|
dumpId = aBrowserDumpId;
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
mProcess->SetHangData(aHangData, dumpId);
|
2017-03-06 23:55:36 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
2018-09-17 23:51:45 +03:00
|
|
|
observerService->NotifyObservers(mProcess, "process-hang-report", nullptr);
|
2017-03-06 23:55:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::ClearHangNotification() {
|
|
|
|
// chrome process, main thread
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
mProcess->ClearHang();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
observerService->NotifyObservers(mProcess, "clear-hang-report", nullptr);
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-07-05 14:39:37 +03: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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
mozilla::ipc::IPCResult HangMonitorParent::RecvHangEvidence(
|
|
|
|
const HangData& aHangData) {
|
2015-06-11 20:25:45 +03:00
|
|
|
// chrome process, background thread
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
if (!mReportHangs) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2015-01-23 02:53:49 +03: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()) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-23 02:53:49 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
// Before we wake up the browser main thread we want to take a
|
|
|
|
// browser minidump.
|
|
|
|
nsAutoString crashId;
|
2016-07-05 14:39:37 +03:00
|
|
|
bool takeMinidump = false;
|
2015-06-11 20:25:45 +03:00
|
|
|
if (aHangData.type() == HangData::TPluginHangData) {
|
2016-07-05 14:39:37 +03:00
|
|
|
takeMinidump = TakeBrowserMinidump(aHangData.get_PluginHangData(), crashId);
|
2015-06-11 20:25:45 +03:00
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2017-03-06 23:55:36 +03:00
|
|
|
NS_DispatchToMainThread(mMainThreadTaskFactory.NewRunnableMethod(
|
|
|
|
&HangMonitorParent::SendHangNotification, aHangData, crashId,
|
|
|
|
takeMinidump));
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 02:54:25 +03:00
|
|
|
mozilla::ipc::IPCResult HangMonitorParent::RecvClearHang() {
|
|
|
|
// chrome process, background thread
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2016-04-02 02:54:25 +03:00
|
|
|
|
|
|
|
if (!mReportHangs) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-04-02 02:54:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mHangMonitor->InitiateCPOWTimeout();
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2017-03-06 23:55:36 +03:00
|
|
|
NS_DispatchToMainThread(mMainThreadTaskFactory.NewRunnableMethod(
|
|
|
|
&HangMonitorParent::ClearHangNotification));
|
2016-04-02 02:54:25 +03:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2016-04-02 02:54:25 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
void HangMonitorParent::TerminateScript(bool aTerminateGlobal) {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2017-04-17 00:01:16 +03:00
|
|
|
Unused << SendTerminateScript(aTerminateGlobal);
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::BeginStartingDebugger() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendBeginStartingDebugger();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HangMonitorParent::EndStartingDebugger() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << SendEndStartingDebugger();
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
void HangMonitorParent::CleanupPluginHang(uint32_t aPluginId,
|
|
|
|
bool aRemoveFiles) {
|
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
|
|
|
nsAutoString crashId;
|
|
|
|
if (!mBrowserCrashDumpIds.Get(aPluginId, &crashId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBrowserCrashDumpIds.Remove(aPluginId);
|
2017-10-10 13:43:09 +03:00
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
if (aRemoveFiles && !crashId.IsEmpty()) {
|
|
|
|
CrashReporter::DeleteMinidumpFilesForID(crashId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 14:39:37 +03:00
|
|
|
void HangMonitorParent::UpdateMinidump(uint32_t aPluginId,
|
|
|
|
const nsString& aDumpId) {
|
|
|
|
if (aDumpId.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock lock(mBrowserCrashDumpHashLock);
|
|
|
|
mBrowserCrashDumpIds.Put(aPluginId, aDumpId);
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03: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 05:39:16 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected HangData type");
|
2015-01-17 05:34:47 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-06-01 05:39:16 +03:00
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-27 06:36:10 +03:00
|
|
|
HangMonitoredProcess::GetScriptBrowser(Element** aBrowser) {
|
2015-01-17 05:34:47 +03:00
|
|
|
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-06 00:47:32 +03:00
|
|
|
TabParent* tp = TabParent::GetFrom(tabs[i]);
|
2015-01-17 05:34:47 +03:00
|
|
|
if (tp->GetTabId() == tabId) {
|
2018-04-27 06:36:10 +03:00
|
|
|
RefPtr<Element> node = tp->GetOwnerElement();
|
2015-01-17 05:34:47 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-18 06:17:51 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::GetAddonId(nsAString& aAddonId) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aAddonId = mHangData.get_SlowScriptData().addonId();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
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 08:24:48 +03:00
|
|
|
RefPtr<nsPluginHost> host = nsPluginHost::GetInst();
|
2015-01-17 05:34:47 +03:00
|
|
|
nsPluginTag* tag = host->PluginWithId(id);
|
|
|
|
if (!tag) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:30:05 +03:00
|
|
|
aPluginName = tag->Name();
|
2015-01-17 05:34:47 +03: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;
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod<bool>(
|
2017-04-17 00:01:16 +03:00
|
|
|
"HangMonitorParent::TerminateScript", mActor,
|
|
|
|
&HangMonitorParent::TerminateScript, false));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::TerminateGlobal() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TSlowScriptData) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod<bool>(
|
|
|
|
"HangMonitorParent::TerminateScript", mActor,
|
|
|
|
&HangMonitorParent::TerminateScript, true));
|
2015-01-17 05:34:47 +03: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;
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod(
|
|
|
|
"HangMonitorParent::BeginStartingDebugger", mActor,
|
|
|
|
&HangMonitorParent::BeginStartingDebugger));
|
2015-01-17 05:34:47 +03: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;
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
ProcessHangMonitor::Get()->Dispatch(NewNonOwningRunnableMethod(
|
|
|
|
"HangMonitorParent::EndStartingDebugger", mActor,
|
|
|
|
&HangMonitorParent::EndStartingDebugger));
|
2015-01-17 05:34:47 +03: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 15:25:08 +03:00
|
|
|
// Use the multi-process crash report generated earlier.
|
2015-01-17 05:34:47 +03:00
|
|
|
uint32_t id = mHangData.get_PluginHangData().pluginId();
|
2016-03-03 10:24:36 +03:00
|
|
|
base::ProcessId contentPid =
|
|
|
|
mHangData.get_PluginHangData().contentProcessId();
|
2018-09-17 23:51:45 +03:00
|
|
|
plugins::TerminatePlugin(id, contentPid, NS_LITERAL_CSTRING("HangMonitor"),
|
|
|
|
mDumpId);
|
2015-06-11 20:25:45 +03:00
|
|
|
|
2018-09-17 23:51:45 +03:00
|
|
|
if (mActor) {
|
|
|
|
mActor->CleanupPluginHang(id, false);
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-04-07 01:32:25 +03:00
|
|
|
HangMonitoredProcess::IsReportForBrowser(nsFrameLoader* aFrameLoader,
|
|
|
|
bool* aResult) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!mActor) {
|
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:32:25 +03:00
|
|
|
NS_ENSURE_STATE(aFrameLoader);
|
2018-03-22 05:43:17 +03:00
|
|
|
|
2018-04-07 01:32:25 +03:00
|
|
|
TabParent* tp = TabParent::GetFrom(aFrameLoader);
|
2015-02-06 00:47:32 +03:00
|
|
|
if (!tp) {
|
2015-01-17 05:34:47 +03:00
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-06 00:47:32 +03:00
|
|
|
*aResult = mContentParent == tp->Manager();
|
2015-01-17 05:34:47 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:25:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HangMonitoredProcess::UserCanceled() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
if (mHangData.type() != HangData::TPluginHangData) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-18 23:10:46 +03:00
|
|
|
if (mActor) {
|
|
|
|
uint32_t id = mHangData.get_PluginHangData().pluginId();
|
|
|
|
mActor->CleanupPluginHang(id, true);
|
|
|
|
}
|
2015-06-11 20:25:45 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
static bool InterruptCallback(JSContext* cx) {
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->InterruptCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
ProcessHangMonitor* ProcessHangMonitor::sInstance;
|
|
|
|
|
|
|
|
ProcessHangMonitor::ProcessHangMonitor() : mCPOWTimeout(false) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-01-17 05:34:47 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
|
|
|
}
|
|
|
|
|
2017-05-20 06:36:10 +03:00
|
|
|
if (NS_FAILED(NS_NewNamedThread("ProcessHangMon", getter_AddRefs(mThread)))) {
|
2015-01-17 05:34:47 +03:00
|
|
|
mThread = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessHangMonitor::~ProcessHangMonitor() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MOZ_ASSERT(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
|
|
|
|
2017-05-20 06:36:10 +03:00
|
|
|
mThread->Shutdown();
|
|
|
|
mThread = nullptr;
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
2017-08-18 06:17:51 +03:00
|
|
|
nsITabChild* aTabChild, const char* aFileName, const nsString& aAddonId) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
2017-08-18 06:17:51 +03:00
|
|
|
return HangMonitorChild::Get()->NotifySlowScript(aTabChild, aFileName,
|
|
|
|
aAddonId);
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2017-05-20 06:36:10 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsOnThread());
|
2015-01-17 05:34:47 +03:00
|
|
|
mCPOWTimeout = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessHangMonitor::NotifyPluginHang(uint32_t aPluginId) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
return HangMonitorChild::Get()->NotifyPluginHang(aPluginId);
|
|
|
|
}
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
static PProcessHangMonitorParent* CreateHangMonitorParent(
|
|
|
|
ContentParent* aContentParent,
|
|
|
|
Endpoint<PProcessHangMonitorParent>&& aEndpoint) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* parent = new HangMonitorParent(monitor);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* process = new HangMonitoredProcess(parent, aContentParent);
|
2015-01-17 05:34:47 +03:00
|
|
|
parent->SetProcess(process);
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
monitor->Dispatch(
|
|
|
|
NewNonOwningRunnableMethod<Endpoint<PProcessHangMonitorParent>&&>(
|
|
|
|
"HangMonitorParent::Bind", parent, &HangMonitorParent::Bind,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(aEndpoint)));
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
void mozilla::CreateHangMonitorChild(
|
|
|
|
Endpoint<PProcessHangMonitorChild>&& aEndpoint) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
JSContext* cx = danger::GetJSContext();
|
|
|
|
JS_AddInterruptCallback(cx, InterruptCallback);
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate();
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* child = new HangMonitorChild(monitor);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
monitor->Dispatch(
|
|
|
|
NewNonOwningRunnableMethod<Endpoint<PProcessHangMonitorChild>&&>(
|
|
|
|
"HangMonitorChild::Bind", child, &HangMonitorChild::Bind,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(aEndpoint)));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:36:10 +03:00
|
|
|
void ProcessHangMonitor::Dispatch(already_AddRefed<nsIRunnable> aRunnable) {
|
2018-05-30 22:15:35 +03:00
|
|
|
mThread->Dispatch(std::move(aRunnable), nsIEventTarget::NS_DISPATCH_NORMAL);
|
2017-05-20 06:36:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProcessHangMonitor::IsOnThread() {
|
|
|
|
bool on;
|
|
|
|
return NS_SUCCEEDED(mThread->IsOnCurrentThread(&on)) && on;
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
PProcessHangMonitorParent* ProcessHangMonitor::AddProcess(
|
2015-01-17 05:34:47 +03:00
|
|
|
ContentParent* aContentParent) {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-01-05 23:54:52 +03:00
|
|
|
if (!mozilla::Preferences::GetBool("dom.ipc.processHangMonitor", false)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Endpoint<PProcessHangMonitorParent> parent;
|
|
|
|
Endpoint<PProcessHangMonitorChild> child;
|
|
|
|
nsresult rv;
|
|
|
|
rv = PProcessHangMonitor::CreateEndpoints(
|
|
|
|
base::GetCurrentProcId(), aContentParent->OtherPid(), &parent, &child);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(false, "PProcessHangMonitor::CreateEndpoints failed");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
if (!aContentParent->SendInitProcessHangMonitor(std::move(child))) {
|
2017-01-05 23:54:52 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return nullptr;
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
2017-01-05 23:54:52 +03:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
return CreateHangMonitorParent(aContentParent, std::move(parent));
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::RemoveProcess(PProcessHangMonitorParent* aParent) {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
|
|
|
parent->Shutdown();
|
|
|
|
delete parent;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::ClearHang() {
|
2015-01-17 05:34:47 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
|
|
|
child->ClearHang();
|
|
|
|
}
|
|
|
|
}
|
2016-07-23 02:36:45 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::PaintWhileInterruptingJS(
|
2018-05-15 09:45:00 +03:00
|
|
|
PProcessHangMonitorParent* aParent, dom::TabParent* aTabParent,
|
2018-07-30 16:24:50 +03:00
|
|
|
bool aForceRepaint, const layers::LayersObserverEpoch& aEpoch) {
|
2016-07-23 02:36:45 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
auto parent = static_cast<HangMonitorParent*>(aParent);
|
2018-07-30 16:24:50 +03:00
|
|
|
parent->PaintWhileInterruptingJS(aTabParent, aForceRepaint, aEpoch);
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
2016-10-21 21:56:46 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::ClearPaintWhileInterruptingJS(
|
2018-07-30 16:24:50 +03:00
|
|
|
const layers::LayersObserverEpoch& aEpoch) {
|
2016-10-21 21:56:46 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
2018-07-30 16:24:50 +03:00
|
|
|
child->ClearPaintWhileInterruptingJS(aEpoch);
|
2016-10-21 21:56:46 +03:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 21:44:19 +03:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
void ProcessHangMonitor::MaybeStartPaintWhileInterruptingJS() {
|
2018-03-18 21:44:19 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
if (HangMonitorChild* child = HangMonitorChild::Get()) {
|
2018-05-15 09:45:00 +03:00
|
|
|
child->MaybeStartPaintWhileInterruptingJS();
|
2018-03-18 21:44:19 +03:00
|
|
|
}
|
|
|
|
}
|