Bug 1075572 - Join the alloc task when finishing the GC. r=bhackett, a=sledru
authorTerrence Cole <terrence@mozilla.com>
Mon, 26 Jan 2015 13:29:00 -0800
changeset 249483 8145e28863d104f8d30cd2dfdd72e75dc5ea8517
parent 249482 df4bef8efefd8c7582497a30dbc2a4bd28e49902
child 249484 974507ff8760bf898f593af71b47403305fa075a
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett, sledru
bugs1075572
milestone37.0a2
Bug 1075572 - Join the alloc task when finishing the GC. r=bhackett, a=sledru
js/src/jsgc.cpp
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1294,20 +1294,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) {
@@ -3029,20 +3031,21 @@ GCRuntime::refillFreeListFromMainThread(
         }
 
         AutoMaybeStartBackgroundAllocation maybeStartBGAlloc;
         void *thing = allocator->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 = allocator->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);