Bug 1305836, part 1 - Remove CCAnalyzer leak checker. r=jgriffin
This leak checker may be triggering a shutdown leak on Windows,
doesn't work with e10s, and should not be needed now that ttaubert
fixed the ++DOMWINDOW leak detector to work.
The additional GCs and CCs this patch adds used to be run as part of
cc-analyzer.js, and are needed to avoid window leaks in tests.
MozReview-Commit-ID: IzZI6h2SCr2
--- a/testing/mochitest/browser-test-overlay.xul
+++ b/testing/mochitest/browser-test-overlay.xul
@@ -4,10 +4,9 @@
- 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/. -->
<overlay id="browserTestOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"/>
<script type="application/javascript" src="chrome://mochikit/content/mochitest-e10s-utils.js"/>
<script type="application/javascript" src="chrome://mochikit/content/browser-test.js"/>
- <script type="application/javascript" src="chrome://mochikit/content/cc-analyzer.js"/>
</overlay>
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -627,39 +627,29 @@ Tester.prototype = {
}
}
// Schedule GC and CC runs before finishing in order to detect
// DOM windows leaked by our tests or the tested code. Note that we
// use a shrinking GC so that the JS engine will discard JIT code and
// JIT caches more aggressively.
- let checkForLeakedGlobalWindows = aCallback => {
+ let shutdownCleanup = aCallback => {
Cu.schedulePreciseShrinkingGC(() => {
- let analyzer = new CCAnalyzer();
- analyzer.run(() => {
- let results = [];
- for (let obj of analyzer.find("nsGlobalWindow ")) {
- let m = obj.name.match(/^nsGlobalWindow #(\d+)/);
- if (m && m[1] in this.openedWindows)
- results.push({ name: obj.name, url: m[1] });
- }
- aCallback(results);
- });
+ // Run the GC and CC a few times to make sure that as much
+ // as possible is freed.
+ let numCycles = 3;
+ for (i = 0; i < numCycles; i++) {
+ Cu.forceGC();
+ Cu.forceCC();
+ }
+ aCallback();
});
};
- let reportLeaks = aResults => {
- for (let result of aResults) {
- let test = this.openedWindows[result.url];
- let msg = "leaked until shutdown [" + result.name +
- " " + (this.openedURLs[result.url] || "NULL") + "]";
- test.addResult(new testResult(false, msg, "", false));
- }
- };
let {AsyncShutdown} =
Cu.import("resource://gre/modules/AsyncShutdown.jsm", {});
let barrier = new AsyncShutdown.Barrier(
"ShutdownLeaks: Wait for cleanup to be finished before checking for leaks");
Services.obs.notifyObservers({wrappedJSObject: barrier},
"shutdown-leaks-before-check", null);
@@ -669,27 +659,19 @@ Tester.prototype = {
barrier.wait().then(() => {
// Simulate memory pressure so that we're forced to free more resources
// and thus get rid of more false leaks like already terminated workers.
Services.obs.notifyObservers(null, "memory-pressure", "heap-minimize");
Services.ppmm.broadcastAsyncMessage("browser-test:collect-request");
- checkForLeakedGlobalWindows(aResults => {
- if (aResults.length == 0) {
- this.finish();
- return;
- }
- // After the first check, if there are reported leaked windows, sleep
- // for a while, to allow off-main-thread work to complete and free up
- // main-thread objects. Then check again.
+ shutdownCleanup(() => {
setTimeout(() => {
- checkForLeakedGlobalWindows(aResults => {
- reportLeaks(aResults);
+ shutdownCleanup(() => {
this.finish();
});
}, 1000);
});
});
return;
}
deleted file mode 100644
--- a/testing/mochitest/cc-analyzer.js
+++ /dev/null
@@ -1,127 +0,0 @@
-/* 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/. */
-
-function CCAnalyzer() {
-}
-
-CCAnalyzer.prototype = {
- clear: function () {
- this.callback = null;
- this.processingCount = 0;
- this.graph = {};
- this.roots = [];
- this.garbage = [];
- this.edges = [];
- this.listener = null;
- },
-
- run: function (aCallback) {
- this.clear();
- this.callback = aCallback;
-
- this.listener = Cc["@mozilla.org/cycle-collector-logger;1"].
- createInstance(Ci.nsICycleCollectorListener);
-
- this.listener.disableLog = true;
- this.listener.wantAfterProcessing = true;
-
- this.runCC(3);
- },
-
- runCC: function (aCounter) {
- let utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIDOMWindowUtils);
-
- if (aCounter > 1) {
- utils.garbageCollect();
- setTimeout(this.runCC.bind(this, aCounter - 1), 0);
- } else {
- utils.garbageCollect(this.listener);
- this.processLog();
- }
- },
-
- processLog: function () {
- // Process entire heap step by step in 5K chunks
- for (let i = 0; i < 5000; i++) {
- if (!this.listener.processNext(this)) {
- this.callback();
- this.clear();
- return;
- }
- }
-
- // Next chunk on timeout.
- setTimeout(this.processLog.bind(this), 0);
- },
-
- noteRefCountedObject: function (aAddress, aRefCount, aObjectDescription) {
- let o = this.ensureObject(aAddress);
- o.address = aAddress;
- o.refcount = aRefCount;
- o.name = aObjectDescription;
- },
-
- noteGCedObject: function (aAddress, aMarked, aObjectDescription) {
- let o = this.ensureObject(aAddress);
- o.address = aAddress;
- o.gcmarked = aMarked;
- o.name = aObjectDescription;
- },
-
- noteEdge: function (aFromAddress, aToAddress, aEdgeName) {
- let fromObject = this.ensureObject(aFromAddress);
- let toObject = this.ensureObject(aToAddress);
- fromObject.edges.push({name: aEdgeName, to: toObject});
- toObject.owners.push({name: aEdgeName, from: fromObject});
-
- this.edges.push({
- name: aEdgeName,
- from: fromObject,
- to: toObject
- });
- },
-
- describeRoot: function (aAddress, aKnownEdges) {
- let o = this.ensureObject(aAddress);
- o.root = true;
- o.knownEdges = aKnownEdges;
- this.roots.push(o);
- },
-
- describeGarbage: function (aAddress) {
- let o = this.ensureObject(aAddress);
- o.garbage = true;
- this.garbage.push(o);
- },
-
- ensureObject: function (aAddress) {
- if (!this.graph[aAddress])
- this.graph[aAddress] = new CCObject();
-
- return this.graph[aAddress];
- },
-
- find: function (aText) {
- let result = [];
- for (let address in this.graph) {
- let o = this.graph[address];
- if (!o.garbage && o.name.indexOf(aText) >= 0)
- result.push(o);
- }
- return result;
- }
-};
-
-function CCObject() {
- this.name = "";
- this.address = null;
- this.refcount = 0;
- this.gcmarked = false;
- this.root = false;
- this.garbage = false;
- this.knownEdges = 0;
- this.edges = [];
- this.owners = [];
-}
--- a/testing/mochitest/jar.mn
+++ b/testing/mochitest/jar.mn
@@ -2,17 +2,16 @@ mochikit.jar:
% content mochikit %content/
content/browser-harness.xul (browser-harness.xul)
content/browser-test.js (browser-test.js)
content/browser-test-overlay.xul (browser-test-overlay.xul)
content/jetpack-package-harness.js (jetpack-package-harness.js)
content/jetpack-package-overlay.xul (jetpack-package-overlay.xul)
content/jetpack-addon-harness.js (jetpack-addon-harness.js)
content/jetpack-addon-overlay.xul (jetpack-addon-overlay.xul)
- content/cc-analyzer.js (cc-analyzer.js)
content/chrome-harness.js (chrome-harness.js)
content/mochitest-e10s-utils.js (mochitest-e10s-utils.js)
content/shutdown-leaks-collector.js (shutdown-leaks-collector.js)
content/ShutdownLeaksCollector.jsm (ShutdownLeaksCollector.jsm)
content/document-observer-script.js (document-observer-script.js)
content/harness.xul (harness.xul)
content/redirect.html (redirect.html)
content/server.js (server.js)
--- a/testing/mochitest/moz.build
+++ b/testing/mochitest/moz.build
@@ -40,17 +40,16 @@ TEST_HARNESS_FILES.testing.mochitest +=
'/build/valgrind/cross-architecture.sup',
'/build/valgrind/i386-redhat-linux-gnu.sup',
'/build/valgrind/x86_64-redhat-linux-gnu.sup',
'/netwerk/test/httpserver/httpd.js',
'bisection.py',
'browser-harness.xul',
'browser-test-overlay.xul',
'browser-test.js',
- 'cc-analyzer.js',
'chrome-harness.js',
'chunkifyTests.js',
'gen_template.pl',
'harness.xul',
'jetpack-addon-harness.js',
'jetpack-addon-overlay.xul',
'jetpack-package-harness.js',
'jetpack-package-overlay.xul',