Bug 1480244: Part 3c - Fix GC test with bad assumptions. r=aswan
This failure starts showing up after these changes by chance. Some aspect of
the environment or other causes a map() call to be baseline-optimized, which
causes its IC stubs to hold its function environemnt alive, which causes it to
hold the context we're checking alive.
Forcing a shrinking GC makes the IC stub go away sooner, and therefore allows
the test to pass.
MozReview-Commit-ID: LXp5mgMZeB1
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js
@@ -28,17 +28,21 @@ async function reloadTopContext(contentP
async function assertContextReleased(contentPage, description) {
await contentPage.spawn(description, async assertionDescription => {
// Force GC, see https://searchfox.org/mozilla-central/rev/b0275bc977ad7fda615ef34b822bba938f2b16fd/testing/talos/talos/tests/devtools/addon/content/damp.js#84-98
// and https://searchfox.org/mozilla-central/rev/33c21c060b7f3a52477a73d06ebcb2bf313c4431/xpcom/base/nsMemoryReporterManager.cpp#2574-2585,2591-2594
let gcCount = 0;
while (gcCount < 30 && this.contextWeakRef.get() !== null) {
++gcCount;
- Cu.forceGC();
+ // The JS engine will sometimes hold IC stubs for function
+ // environments alive across multiple CCs, which can keep
+ // closed-over JS objects alive. A shrinking GC will throw those
+ // stubs away, and therefore side-step the problem.
+ Cu.forceShrinkingGC();
Cu.forceCC();
Cu.forceGC();
await new Promise(resolve => this.content.setTimeout(resolve, 0));
}
// The above loop needs to be repeated at most 3 times according to MinimizeMemoryUsage:
// https://searchfox.org/mozilla-central/rev/6f86cc3479f80ace97f62634e2c82a483d1ede40/xpcom/base/nsMemoryReporterManager.cpp#2644-2647
Assert.lessOrEqual(gcCount, 3, `Context should have been GCd within a few GC attempts.`);