Bug 1480244: Part 3c - Fix GC test with bad assumptions. r=aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 03 Aug 2018 14:11:38 -0700
changeset 828431 93aa6a890d1a30dd044ad3d3c1acf69c82fcd9ce
parent 828430 2e65b3701fe59a10270663fd612b95cd6473522b
child 828432 be076323bc70bf5d80261efe1504b4ae54497f98
push id118679
push usermaglione.k@gmail.com
push dateFri, 10 Aug 2018 21:19:41 +0000
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) {
-      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();
       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.`);