Avoid excessive GCs after CC (bug 637206, patch/r=smaug/gal).

--HG--
extra : rebase_source : 722c9e033fcb7a839b0464199a996729cf7f1ca8
This commit is contained in:
Andreas Gal 2011-02-28 14:44:22 -08:00
Родитель f39d3297e9
Коммит c55a88ef83
1 изменённых файлов: 13 добавлений и 6 удалений

Просмотреть файл

@ -159,6 +159,7 @@ static bool sGCHasRun;
static PRUint32 sPendingLoadCount;
static PRBool sLoadingInProgress;
static PRUint32 sCCollectedWaitingForGC;
static PRBool sPostGCEventsToConsole;
nsScriptNameSpaceManager *gNameSpaceManager;
@ -3287,19 +3288,21 @@ nsJSContext::CycleCollectNow(nsICycleCollectorListener *aListener)
PRUint32 suspected = nsCycleCollector_suspectedCount();
PRUint32 collected = nsCycleCollector_collect(aListener);
sCCollectedWaitingForGC += collected;
// If we collected cycles, poke the GC since more objects might be unreachable now.
if (collected > 0) {
// If we collected a substantial amount of cycles, poke the GC since more objects
// might be unreachable now.
if (sCCollectedWaitingForGC > 250) {
PokeGC();
}
if (sPostGCEventsToConsole) {
PRTime now = PR_Now();
NS_NAMED_LITERAL_STRING(kFmt,
"CC timestamp: %lld, collected: %lu, suspected: %lu, duration: %llu ms.");
"CC timestamp: %lld, collected: %lu (%lu waiting for GC), suspected: %lu, duration: %llu ms.");
nsString msg;
msg.Adopt(nsTextFormatter::smprintf(kFmt.get(), now,
collected, suspected,
collected, sCCollectedWaitingForGC, suspected,
(now - start) / PR_USEC_PER_MSEC));
nsCOMPtr<nsIConsoleService> cs =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
@ -3449,9 +3452,11 @@ DOMGCCallback(JSContext *cx, JSGCStatus status)
start = PR_Now();
} else if (status == JSGC_END) {
PRTime now = PR_Now();
NS_NAMED_LITERAL_STRING(kFmt, "GC timestamp: %lld, duration: %llu ms.");
NS_NAMED_LITERAL_STRING(kFmt, "GC mode: %s, timestamp: %lld, duration: %llu ms.");
nsString msg;
msg.Adopt(nsTextFormatter::smprintf(kFmt.get(), now,
msg.Adopt(nsTextFormatter::smprintf(kFmt.get(),
cx->runtime->gcTriggerCompartment ? "compartment" : "full",
now,
(now - start) / PR_USEC_PER_MSEC));
nsCOMPtr<nsIConsoleService> cs = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (cs) {
@ -3461,6 +3466,7 @@ DOMGCCallback(JSContext *cx, JSGCStatus status)
}
if (status == JSGC_END) {
sCCollectedWaitingForGC = 0;
if (sGCTimer) {
// If we were waiting for a GC to happen, kill the timer.
nsJSContext::KillGCTimer();
@ -3595,6 +3601,7 @@ nsJSRuntime::Startup()
sGCHasRun = false;
sPendingLoadCount = 0;
sLoadingInProgress = PR_FALSE;
sCCollectedWaitingForGC = 0;
sPostGCEventsToConsole = PR_FALSE;
gNameSpaceManager = nsnull;
sRuntimeService = nsnull;