Bug 699279 - Run GC_SHRINK collection cycle when under memory pressure; r=mrbkap

GC_SHRINK is a fairly new type of GC that does more aggressive cleanups than a
normal GC.  This patch makes the browser run the GC in this mode when under
memory pressure, or when the user pushes the Minimize Memory Usage button when
on the about:memory page.

--HG--
extra : rebase_source : abdd11ee5fa5eb0e3d58122d3d72e98328d47668
This commit is contained in:
Terrence Cole 2011-11-09 18:14:11 -08:00
Родитель 65233c5237
Коммит b08432d55e
8 изменённых файлов: 24 добавлений и 12 удалений

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

@ -194,7 +194,7 @@ nsMemoryPressureObserver::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData) const PRUnichar* aData)
{ {
if (sGCOnMemoryPressure) { if (sGCOnMemoryPressure) {
nsJSContext::GarbageCollectNow(); nsJSContext::GarbageCollectNow(true);
nsJSContext::CycleCollectNow(); nsJSContext::CycleCollectNow();
} }
return NS_OK; return NS_OK;
@ -3187,7 +3187,7 @@ nsJSContext::ScriptExecuted()
//static //static
void void
nsJSContext::GarbageCollectNow() nsJSContext::GarbageCollectNow(bool shrinkingGC)
{ {
NS_TIME_FUNCTION_MIN(1.0); NS_TIME_FUNCTION_MIN(1.0);
@ -3203,7 +3203,7 @@ nsJSContext::GarbageCollectNow()
sLoadingInProgress = false; sLoadingInProgress = false;
if (nsContentUtils::XPConnect()) { if (nsContentUtils::XPConnect()) {
nsContentUtils::XPConnect()->GarbageCollect(); nsContentUtils::XPConnect()->GarbageCollect(shrinkingGC);
} }
} }

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

@ -182,7 +182,7 @@ public:
static void LoadStart(); static void LoadStart();
static void LoadEnd(); static void LoadEnd();
static void GarbageCollectNow(); static void GarbageCollectNow(bool shrinkingGC = false);
static void CycleCollectNow(nsICycleCollectorListener *aListener = nsnull); static void CycleCollectNow(nsICycleCollectorListener *aListener = nsnull);
static void PokeGC(); static void PokeGC();

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

@ -132,6 +132,12 @@ JS_ObjectCountDynamicSlots(JSObject *obj)
return obj->numDynamicSlots(obj->numSlots()); return obj->numDynamicSlots(obj->numSlots());
return 0; return 0;
} }
JS_PUBLIC_API(void)
JS_ShrinkingGC(JSContext *cx)
{
js_GC(cx, NULL, GC_SHRINK, gcstats::PUBLIC_API);
}
JS_FRIEND_API(JSPrincipals *) JS_FRIEND_API(JSPrincipals *)
JS_GetCompartmentPrincipals(JSCompartment *compartment) JS_GetCompartmentPrincipals(JSCompartment *compartment)

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

@ -70,6 +70,9 @@ JS_NewObjectWithUniqueType(JSContext *cx, JSClass *clasp, JSObject *proto, JSObj
extern JS_FRIEND_API(uint32) extern JS_FRIEND_API(uint32)
JS_ObjectCountDynamicSlots(JSObject *obj); JS_ObjectCountDynamicSlots(JSObject *obj);
extern JS_FRIEND_API(void)
JS_ShrinkingGC(JSContext *cx);
extern JS_FRIEND_API(size_t) extern JS_FRIEND_API(size_t)
JS_GetE4XObjectsCreated(JSContext *cx); JS_GetE4XObjectsCreated(JSContext *cx);

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

@ -392,7 +392,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%} %}
[uuid(29b63029-0868-4344-b0ca-d93256ee7c78)] [uuid(07661008-5505-4784-a612-89f7dc2144da)]
interface nsIXPConnect : nsISupports interface nsIXPConnect : nsISupports
{ {
%{ C++ %{ C++
@ -735,7 +735,7 @@ interface nsIXPConnect : nsISupports
/** /**
* Trigger a JS garbage collection. * Trigger a JS garbage collection.
*/ */
void GarbageCollect(); void GarbageCollect(in boolean shrinkingGC);
/** /**
* Define quick stubs on the given object, @a proto. * Define quick stubs on the given object, @a proto.

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

@ -343,7 +343,7 @@ nsXPConnect::NeedCollect()
} }
void void
nsXPConnect::Collect() nsXPConnect::Collect(bool shrinkingGC)
{ {
// We're dividing JS objects into 2 categories: // We're dividing JS objects into 2 categories:
// //
@ -406,15 +406,18 @@ nsXPConnect::Collect()
JS_ASSERT(!threadData.conservativeGC.requestThreshold); JS_ASSERT(!threadData.conservativeGC.requestThreshold);
if (threadData.requestDepth == 1) if (threadData.requestDepth == 1)
threadData.conservativeGC.requestThreshold = 1; threadData.conservativeGC.requestThreshold = 1;
JS_GC(cx); if (shrinkingGC)
JS_ShrinkingGC(cx);
else
JS_GC(cx);
if (threadData.requestDepth == 1) if (threadData.requestDepth == 1)
threadData.conservativeGC.requestThreshold = 0; threadData.conservativeGC.requestThreshold = 0;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXPConnect::GarbageCollect() nsXPConnect::GarbageCollect(bool shrinkingGC)
{ {
Collect(); Collect(shrinkingGC);
return NS_OK; return NS_OK;
} }

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

@ -566,7 +566,7 @@ public:
virtual nsresult FinishCycleCollection(); virtual nsresult FinishCycleCollection();
virtual nsCycleCollectionParticipant *ToParticipant(void *p); virtual nsCycleCollectionParticipant *ToParticipant(void *p);
virtual bool NeedCollect(); virtual bool NeedCollect();
virtual void Collect(); virtual void Collect(bool shrinkingGC=false);
#ifdef DEBUG_CC #ifdef DEBUG_CC
virtual void PrintAllReferencesTo(void *p); virtual void PrintAllReferencesTo(void *p);
#endif #endif

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

@ -92,7 +92,7 @@ struct nsCycleCollectionJSRuntime : public nsCycleCollectionLanguageRuntime
/** /**
* Runs the JavaScript GC. * Runs the JavaScript GC.
*/ */
virtual void Collect() = 0; virtual void Collect(bool shrinkingGC = false) = 0;
}; };
#ifdef DEBUG #ifdef DEBUG