Files
palemoon27/browser/modules/ProcessHangMonitor.jsm
roytam1 573e7dd316 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1220564 - Remove legacy generator comprehensions. (r=Waldo) (762c83b25f)
- Bug 1220564 - Update and remove obsolete jit-tests. (r=Waldo) (cd56eda223)
- Bug 1220564 - Update and remove obsolete JS reftests. (r=Waldo) (3a36a4f4e5)
- Bug 1139736 - Part 1: map settings "network.debugging.enabled" to preference. r=fabrice (594fc01429)
- Bug 1210740 - Expose tracking protection setting to Gaia, r=fabrice (38daca12a0)
- Bug 1163956 - Modify updatePath to fixed char array. r=gsvelto (56fec01263)
- Bug 1229620 - Replace #ifdefs in b2g/ code by AppConstants r=timdream (7cc5dce39d)
- Bug 1214515 - PersistentDataBlock b2g component implementation. r=gerard-majax (eadc3d53ca)
- Bug 1220564 - Update chrome code uses of genexprs and legacy comprehensions. (r=billm) (0dea4b39fd)
- Bug 1234738 - Emit ALIASEDVAR ops or block-scoped lexicals right below global level. (r=jorendorff) (7c8eb66a00)
- Bug 1221144 - Part 1: Make static scope objects a separate class hierarchy from the runtime ScopeObjects. r=shu. (1c74551384)
- Bug 1237564 - Fix minor bug with a lexical declaration shadowing a non-configurable global. r=shu (fcb3040151)
- Bug 1237501. Actually create a baseline IC for a JSNative accessor property get that's unshadowed on a DOM proxy. We apparently failed to ever do this. r=jandem (e2e4222197)
- Bug 1234663: SharedStubs: Use correct fallbackstubspace to keep stubs# , r=jandm (591fbcd885)
- Bug 1234414 - Consider the initial values at block entry to be within block note bounds. (r=jorendorff) (321a016320)
- Bug 1214059: Baseline: Enable switch to debug mode at function entry, r=jandem (b803a7206d)
- Bug 1233179 - Allow bytecode emitter to access module environment before module declarations are instantiated r=shu (e6d23fc2af)
- Bug 1220564 - Remove legacy array comprehensions. (r=Waldo) (73973ac52e)
- Bug 1228976 - Remove array comprehensions from Places .r=mak (10274eaaef)
- Bug 1239753 - FirefoxProfileMigrator is broken after generator expression removal. r=gijs (da1fbf8ca7)
- Bug 1229519: Fix toolkit/components/thumbnails to pass eslint checks. r=rhelmer (2a710ab167)
- Bug 1041537 - Prevent ContentSearch from leaking the browser if it's still processing a message while the test suite shuts down r=adw (b62ad37cdd)
- Bug 1204361 - New Tab Page doesn't honor my "x" clicks on Suggested Tiles; instead of removing the tile, it swaps in a very similar one. [r=emtwo] (3260d90a44)
- Bug 1119442 - Update hang ui, remove drop down options and replace with simpler 'just fix it' button interface. r=mconley (29046ca45c)
- Bug 1233470 - make browser/modules eslintable, r=Mossop (aeb556ba66)
- Bug 1236875 - Fix BytecodeEmitter::atBodyLevel() for modules r=efaust (2fca7e49f2)
- Bug 1221144 - Part 2: Rename static scope classes away from "ScopeObject". r=shu. (dc2f110ef2)
- Bug 1221144 - Part 3: Rename variables, arguments, and fields that point to static scopes away from names that indicate objects, like "scopeObj" and "blockObj". r=shu. (33d1504d55)
- Bug 1221144 - Part 4: Rename a few functions about scopes away from names that indicate objects, like js::CloneNestedScopeObject. r=shu. (9551101431)
- Bug 1221144 - Part 5: Delete class js::BlockObject. r=shu. (5b4746c5a5)
- Bug 1221144 - Part 6: Introduce StaticModuleScope. Pretty silly so far. Bindings are still stored in the script. r=shu. (b90c20e255)
- Bug 1221144 - Part 7: Introduce StaticFunctionScope, same story. r=shu. (eb39a2359b)
- Bug 1221144 - Part 8: Change C++ type of static scopes everywhere from JSObject* to StaticScope*. r=shu. (f1edf54510)
- Bug 1221144 - Part 9: A few more JSObject* -> StaticScope* changes. r=shu. (000d52709b)
- Bug 1221144 - Part 10: Delete an obsolete comment. r=shu. (f0655f736b)
- Bug 1221144 - Part 12: Remove StaticScopeIter<>::IsStaticScope. r=shu. (9653f2c544)
- Bug 1221144 - Part 13: Change DumpStaticScopeChain to include a function scope when available, on the theory that more information is better. r=shu. (7dd24064c8)
- Bug 1221144 - Part 14: Handlify scope arguments to methods around FunctionBox creation. r=shu. (902020bf08)
- Fix busted test checked in with bug 1221144. r=red. (9d8ff7f3be)
- Bug 1235590 - Allow redeclaring block-scoped functions and warn about deprecation for now. (r=jorendorff) (1e8a6ca2bb)
- Bug 1245321 - Merge the object and regexp lists in script data. r=jorendorff. (4f429f9d7b)
- Bug 1230633 - User is unable to enable full devtools/developer mode r=me (a9ee457fec)
- backout Bug 1221144 for perf regression (0c24810d37)
- Bug 1207490 - Part 11: Remove use of expression closure from browser/modules/DirectoryLinksProvider.jsm. r=Gijs (f7f844130a)
- Bug 1240245 - Disable data collection for new-tab page r=jaws (a7a40f394b)
- Bug 526620 - Intelligently invalidate other tabs' previews on resize, flushing their layout when necessary. r=jimm (30ce73281d)
- Bug 1122356 - Remove use of expression closures from WindowsPreviewPerTab.jsm. r=dao (bb3fde452e)
- Bug 1207490 - Part 15: Remove use of expression closure from browser/modules/WindowsPreviewPerTab.jsm. r=Gijs (3904885596)
- Bug 1233925 - Treat functions with rest more like functions with lazy arguments. r=nbp (7e6ec266e1)
- Bug 1243397 - Ensure enough ballast space in LiveRange::FallibleNew. r=h4writer (d36353ed01)
- Bug 1229636 - Remove new tab first time use message. r=gijs (57a1df93cf)
- Bug 1245154 - Ensure enough ballast space in LiveBundle::FallibleNew. r=h4writer (46863982c0)
- Bug 1245176 - Ensure enough ballast space in BacktrackingAllocator::reifyAllocations. r=h4writer (289d71a6cb)
- Bug 1231024 - Fix printing of live bundle information in regalloc spew, r=jonco. (fb4449119f)
- Bug 1244215 part 1 - Store frame header size in the frame descriptor. r=nbp (e666793f3c)
- Bug 1234425 - Skip accessor IC frames in GetPcScript. r=h4writer (5981b361ad)
- Bug 1244215 part 2 - Get rid of unwound frames and clean up a lot of code in this area. r=nbp (96de454424)
- Bug 1244215 part 3 - Remove lazy link frames, they're no longer necessary. r=nbp (32637085a0)
- Bug 1225041 - Implement ES6 Annex B.3.5. (r=jorendorff) (718e230725)
- Bug 1224310 - Suggested tiles requires two blocks to stop showing in newtab [r=marcosc] (53aed2c8a8)
- Bug 912337 - Update docs on Debugger.DebuggeeWouldRun. (r=jimb) (f4a88f0f93)
- Bug 1236316 - Suppress GC in ActivationEntryMonitor constructors; should fix a ton of dt oranges. r=fitzgen (122a436137)
- Bug 1238575 - Fix shell evalInWorker() to wait for thread if it exitsearly r=terrence (dd0ef6414a)
- Bug 1243706 - Release PerformanceStats/PerformanceWatcher;r=Felipe (1a36dce39e)
- Bug 912337 - Tests. (r=jimb) (463a89f8fc)
- Bug 912337 - Update existing tests. (r=jimb) (bf57c020a9)
- Bug 912337 - Make a pref to toggle whether DebuggeeWouldRun is a warning or an error. (r=jimb) (3fd12fe0c3)
- Bug 912337 - Make DebuggeeWouldRun report filename and lineno. (r=me) (56ace0f5e4)
- Bug 1232685 - Prevent forcing illegal return values in derived class constructors. (r=shu, a=kwierso) (f15c51b1fd)
- Bug 1243754 - IonMonkey: Use 'delete' to destroy the ion script instead of 'free', r=jandem (74df94e3a2)
2023-09-04 16:37:44 +08:00

432 lines
13 KiB
JavaScript

/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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/. */
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
this.EXPORTED_SYMBOLS = ["ProcessHangMonitor"];
Cu.import("resource://gre/modules/Services.jsm");
/**
* This JSM is responsible for observing content process hang reports
* and asking the user what to do about them. See nsIHangReport for
* the platform interface.
*/
var ProcessHangMonitor = {
/**
* If a hang hasn't been reported for more than 10 seconds, assume the
* content process has gotten unstuck (and hide the hang notification).
*/
get HANG_EXPIRATION_TIME() {
try {
return Services.prefs.getIntPref("browser.hangNotification.expiration");
} catch (ex) {
return 10000;
}
},
/**
* This timeout is the wait period applied after a user selects "Wait" in
* an existing notification.
*/
get WAIT_EXPIRATION_TIME() {
try {
return Services.prefs.getIntPref("browser.hangNotification.waitPeriod");
} catch (ex) {
return 10000;
}
},
/**
* Collection of hang reports that haven't expired or been dismissed
* by the user. The keys are nsIHangReports and values keys are
* timers. Each time the hang is reported, the timer is refreshed so
* it expires after HANG_EXPIRATION_TIME.
*/
_activeReports: new Map(),
/**
* Collection of hang reports that have been suppressed for a
* short period of time.
*/
_pausedReports: new Map(),
/**
* Initialize hang reporting. Called once in the parent process.
*/
init: function() {
Services.obs.addObserver(this, "process-hang-report", false);
Services.obs.addObserver(this, "xpcom-shutdown", false);
Services.ww.registerNotification(this);
},
/**
* Terminate JavaScript associated with the hang being reported for
* the selected browser in |win|.
*/
terminateScript: function(win) {
this.handleUserInput(win, report => report.terminateScript());
},
/**
* Start devtools debugger for JavaScript associated with the hang
* being reported for the selected browser in |win|.
*/
debugScript: function(win) {
this.handleUserInput(win, report => {
function callback() {
report.endStartingDebugger();
}
report.beginStartingDebugger();
let svc = Cc["@mozilla.org/dom/slow-script-debug;1"].getService(Ci.nsISlowScriptDebug);
let handler = svc.remoteActivationHandler;
handler.handleSlowScriptDebug(report.scriptBrowser, callback);
});
},
/**
* Terminate the plugin process associated with a hang being reported
* for the selected browser in |win|. Will attempt to generate a combined
* crash report for all processes.
*/
terminatePlugin: function(win) {
this.handleUserInput(win, report => report.terminatePlugin());
},
/**
* Dismiss the browser notification and invoke an appropriate action based on
* the hang type.
*/
stopIt: function (win) {
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
if (!report) {
return;
}
switch (report.hangType) {
case report.SLOW_SCRIPT:
this.terminateScript(win);
break;
case report.PLUGIN_HANG:
this.terminatePlugin(win);
break;
}
},
/**
* Dismiss the notification, clear the report from the active list and set up
* a new timer to track a wait period during which we won't notify.
*/
waitLonger: function(win) {
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
if (!report) {
return;
}
// Remove the report from the active list and cancel its timer.
this.removeActiveReport(report);
// NOTE, we didn't call userCanceled on nsIHangReport here. This insures
// we don't repeatedly generate and cache crash report data for this hang
// in the process hang reporter. It already has one report for the browser
// process we want it hold onto.
// Create a new wait timer with notify callback
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(() => {
for (let [stashedReport, otherTimer] of this._pausedReports) {
if (otherTimer === timer) {
this.removePausedReport(stashedReport);
// Create a new notification display timeout timer
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(this, this.HANG_EXPIRATION_TIME, timer.TYPE_ONE_SHOT);
// Store the timer in the active reports map. If we receive a new
// observer notification for this hang, we'll redisplay the browser
// notification in reportHang below. If we do not receive a new
// observer, timer will take care fo cleaning up resources associated
// with this hang. The observer for active hangs fires about once
// a second.
this._activeReports.set(report, timer);
break;
}
}
}, this.WAIT_EXPIRATION_TIME, timer.TYPE_ONE_SHOT);
this._pausedReports.set(report, timer);
// remove the browser notification associated with this hang
this.updateWindows();
},
/**
* If there is a hang report associated with the selected browser in
* |win|, invoke |func| on that report and stop notifying the user
* about it.
*/
handleUserInput: function(win, func) {
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
if (!report) {
return null;
}
this.removeActiveReport(report);
return func(report);
},
observe: function(subject, topic, data) {
switch (topic) {
case "xpcom-shutdown":
Services.obs.removeObserver(this, "xpcom-shutdown");
Services.obs.removeObserver(this, "process-hang-report");
Services.ww.unregisterNotification(this);
break;
case "process-hang-report":
this.reportHang(subject.QueryInterface(Ci.nsIHangReport));
break;
case "domwindowopened":
// Install event listeners on the new window in case one of
// its tabs is already hung.
let win = subject.QueryInterface(Ci.nsIDOMWindow);
let listener = (ev) => {
win.removeEventListener("load", listener, true);
this.updateWindows();
};
win.addEventListener("load", listener, true);
break;
}
},
/**
* Find a active hang report for the given <browser> element.
*/
findActiveReport: function(browser) {
let frameLoader = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
for (let [report, timer] of this._activeReports) {
if (report.isReportForBrowser(frameLoader)) {
return report;
}
}
return null;
},
/**
* Find a paused hang report for the given <browser> element.
*/
findPausedReport: function(browser) {
let frameLoader = browser.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader;
for (let [report, timer] of this._pausedReports) {
if (report.isReportForBrowser(frameLoader)) {
return report;
}
}
return null;
},
/**
* Remove an active hang report from the active list and cancel the timer
* associated with it.
*/
removeActiveReport: function(report) {
let timer = this._activeReports.get(report);
if (timer) {
timer.cancel();
}
this._activeReports.delete(report);
this.updateWindows();
},
/**
* Remove a paused hang report from the paused list and cancel the timer
* associated with it.
*/
removePausedReport: function(report) {
let timer = this._pausedReports.get(report);
if (timer) {
timer.cancel();
}
this._pausedReports.delete(report);
},
/**
* Iterate over all XUL windows and ensure that the proper hang
* reports are shown for each one. Also install event handlers in
* each window to watch for events that would cause a different hang
* report to be displayed.
*/
updateWindows: function() {
let e = Services.wm.getEnumerator("navigator:browser");
while (e.hasMoreElements()) {
let win = e.getNext();
this.updateWindow(win);
// Only listen for these events if there are active hang reports.
if (this._activeReports.size) {
this.trackWindow(win);
} else {
this.untrackWindow(win);
}
}
},
/**
* If there is a hang report for the current tab in |win|, display it.
*/
updateWindow: function(win) {
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
if (report) {
this.showNotification(win, report);
} else {
this.hideNotification(win);
}
},
/**
* Show the notification for a hang.
*/
showNotification: function(win, report) {
let nb = win.document.getElementById("high-priority-global-notificationbox");
let notification = nb.getNotificationWithValue("process-hang");
if (notification) {
return;
}
let bundle = win.gNavigatorBundle;
let brandBundle = win.document.getElementById("bundle_brand");
let buttons = [{
label: bundle.getString("processHang.button_stop.label"),
accessKey: bundle.getString("processHang.button_stop.accessKey"),
callback: function() {
ProcessHangMonitor.stopIt(win);
}
},
{
label: bundle.getString("processHang.button_wait.label"),
accessKey: bundle.getString("processHang.button_wait.accessKey"),
callback: function() {
ProcessHangMonitor.waitLonger(win);
}
}];
#ifdef MOZ_DEV_EDITION
if (report.hangType == report.SLOW_SCRIPT) {
buttons.push({
label: bundle.getString("processHang.button_debug.label"),
accessKey: bundle.getString("processHang.button_debug.accessKey"),
callback: function() {
ProcessHangMonitor.debugScript(win);
}
});
}
#endif
nb.appendNotification(bundle.getString("processHang.label"),
"process-hang",
"chrome://browser/content/aboutRobots-icon.png",
nb.PRIORITY_WARNING_HIGH, buttons);
},
/**
* Ensure that no hang notifications are visible in |win|.
*/
hideNotification: function(win) {
let nb = win.document.getElementById("high-priority-global-notificationbox");
let notification = nb.getNotificationWithValue("process-hang");
if (notification) {
nb.removeNotification(notification);
}
},
/**
* Install event handlers on |win| to watch for events that would
* cause a different hang report to be displayed.
*/
trackWindow: function(win) {
win.gBrowser.tabContainer.addEventListener("TabSelect", this, true);
win.gBrowser.tabContainer.addEventListener("TabRemotenessChange", this, true);
},
untrackWindow: function(win) {
win.gBrowser.tabContainer.removeEventListener("TabSelect", this, true);
win.gBrowser.tabContainer.removeEventListener("TabRemotenessChange", this, true);
},
handleEvent: function(event) {
let win = event.target.ownerDocument.defaultView;
// If a new tab is selected or if a tab changes remoteness, then
// we may need to show or hide a hang notification.
if (event.type == "TabSelect" || event.type == "TabRemotenessChange") {
this.updateWindow(win);
}
},
/**
* Handle a potentially new hang report. If it hasn't been seen
* before, show a notification for it in all open XUL windows.
*/
reportHang: function(report) {
// If this hang was already reported reset the timer for it.
if (this._activeReports.has(report)) {
let timer = this._activeReports.get(report);
timer.cancel();
timer.initWithCallback(this, this.HANG_EXPIRATION_TIME, timer.TYPE_ONE_SHOT);
// if this report is in active but doesn't have a notification associated
// with it, display a notification.
this.updateWindows();
return;
}
// If this hang was already reported and paused by the user ignore it.
if (this._pausedReports.has(report)) {
return;
}
// On e10s this counts slow-script/hanged-plugin notice only once.
// This code is not reached on non-e10s.
if (report.hangType == report.SLOW_SCRIPT) {
// On non-e10s, SLOW_SCRIPT_NOTICE_COUNT is probed at nsGlobalWindow.cpp
Services.telemetry.getHistogramById("SLOW_SCRIPT_NOTICE_COUNT").add();
} else if (report.hangType == report.PLUGIN_HANG) {
// On non-e10s we have sufficient plugin telemetry probes,
// so PLUGIN_HANG_NOTICE_COUNT is only probed on e10s.
Services.telemetry.getHistogramById("PLUGIN_HANG_NOTICE_COUNT").add();
}
// Otherwise create a new timer and display the report.
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(this, this.HANG_EXPIRATION_TIME, timer.TYPE_ONE_SHOT);
this._activeReports.set(report, timer);
this.updateWindows();
},
/**
* Callback for when HANG_EXPIRATION_TIME has elapsed.
*/
notify: function(timer) {
for (let [otherReport, otherTimer] of this._activeReports) {
if (otherTimer === timer) {
this.removeActiveReport(otherReport);
otherReport.userCanceled();
break;
}
}
},
};