Bug 1075572 - Join the alloc task when finishing the GC; r=bhackett
authorTerrence Cole <terrence@mozilla.com>
Mon, 26 Jan 2015 13:29:00 -0800
changeset 239735 9076fc40dad403b5d6203749af9404ac2bff6899
parent 239634 13dd7bfcb9b1864327c8b5c2b69c739ef92befa0
child 239736 6bda775985ab60184bba66966bffd177e9810b08
push id506
push usermleibovic@mozilla.com
push dateThu, 29 Jan 2015 12:40:10 +0000
reviewersbhackett
bugs1075572
milestone38.0a1
Bug 1075572 - Join the alloc task when finishing the GC; r=bhackett
js/src/jsgc.cpp
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1282,20 +1282,22 @@ GCRuntime::init(uint32_t maxbytes, uint3
 
     return true;
 }
 
 void
 GCRuntime::finish()
 {
     /*
-     * Wait until the background finalization stops and the helper thread
-     * shuts down before we forcefully release any remaining GC memory.
+     * Wait until the background finalization and allocation stops and the
+     * helper thread shuts down before we forcefully release any remaining GC
+     * memory.
      */
     helperState.finish();
+    allocTask.cancel(GCParallelTask::CancelAndWait);
 
 #ifdef JS_GC_ZEAL
     /* Free memory associated with GC verification. */
     finishVerifier();
 #endif
 
     /* Delete all remaining zones. */
     if (rt->gcInitialized) {
@@ -2952,20 +2954,21 @@ GCRuntime::refillFreeListFromMainThread(
         }
 
         AutoMaybeStartBackgroundAllocation maybeStartBGAlloc;
         void *thing = arenas->allocateFromArena(zone, thingKind, maybeStartBGAlloc);
         if (MOZ_LIKELY(thing))
             return thing;
 
         // Even if allocateFromArena failed due to OOM, a background
-        // finalization task may be running (freeing more memory); wait for it
-        // to finish, then try to allocate again in case it freed up the memory
-        // we need.
-        rt->gc.waitBackgroundSweepEnd();
+        // finalization or allocation task may be running freeing more memory
+        // or adding more available memory to our free pool; wait for them to
+        // finish, then try to allocate again in case they made more memory
+        // available.
+        rt->gc.waitBackgroundSweepOrAllocEnd();
 
         thing = arenas->allocateFromArena(zone, thingKind, maybeStartBGAlloc);
         if (MOZ_LIKELY(thing))
             return thing;
 
         // Retry after a last-ditch GC, unless we've already tried that.
         outOfMemory = true;
     } while (!ranGC);