From 0cf27b90080cab66a1a2e0025893bafc601d3ed7 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Mon, 23 Feb 2015 11:15:43 -0800 Subject: [PATCH] Bug 1135141 - Make LAST_DITCH GC more robust; r=jonco --- js/src/gc/GCRuntime.h | 2 +- js/src/jsgc.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/src/gc/GCRuntime.h b/js/src/gc/GCRuntime.h index 24ba7507f01..e43ae38805c 100644 --- a/js/src/gc/GCRuntime.h +++ b/js/src/gc/GCRuntime.h @@ -921,7 +921,7 @@ class GCRuntime void protectRelocatedArenas(ArenaHeader *relocatedList); void unprotectRelocatedArenas(ArenaHeader *relocatedList); #endif - void finishCollection(); + void finishCollection(JS::gcreason::Reason reason); void computeNonIncrementalMarkingForValidation(); void validateIncrementalMarking(); diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index baab0d7e3bf..f4faaa2abc1 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -5546,7 +5546,7 @@ GCRuntime::compactPhase(bool lastGC, JS::gcreason::Reason reason) } void -GCRuntime::finishCollection() +GCRuntime::finishCollection(JS::gcreason::Reason reason) { MOZ_ASSERT(marker.isDrained()); marker.stop(); @@ -5566,6 +5566,13 @@ GCRuntime::finishCollection() } lastGCTime = currentTime; + + // If this is an OOM GC reason, wait on the background sweeping thread + // before returning to ensure that we free as much as possible. + if (reason == JS::gcreason::LAST_DITCH || reason == JS::gcreason::MEM_PRESSURE) { + gcstats::AutoPhase ap(stats, gcstats::PHASE_WAIT_BACKGROUND_THREAD); + rt->gc.waitBackgroundSweepOrAllocEnd(); + } } /* Start a new heap session. */ @@ -5933,7 +5940,7 @@ GCRuntime::incrementalCollectSlice(SliceBudget &budget, JS::gcreason::Reason rea if (isCompacting && compactPhase(lastGC, reason) == NotFinished) break; - finishCollection(); + finishCollection(reason); incrementalState = NO_INCREMENTAL; break;