Bug 718899 - Implement Cu.forceShrinkingGC / Cu.schedulePreciseShrinkingGC r=gwagner

This commit is contained in:
John Schoenick 2012-01-19 10:58:25 -08:00
Родитель 3887b09c1f
Коммит 4d537b2c65
2 изменённых файлов: 40 добавлений и 5 удалений

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

@ -152,7 +152,7 @@ interface ScheduledGCCallback : nsISupports
/**
* interface of Components.utils
*/
[scriptable, uuid(b032a8f1-9149-4cbe-bee6-4ac5dfe7c80a)]
[scriptable, uuid(9e9ba9d6-a0fa-4767-9f49-9b74bb2368cd)]
interface nsIXPCComponents_Utils : nsISupports
{
@ -263,6 +263,14 @@ interface nsIXPCComponents_Utils : nsISupports
*/
[implicit_jscontext]
void forceGC();
/*
* To be called from JS only.
*
* Force an immediate shrinking garbage collection cycle.
*/
[implicit_jscontext]
void forceShrinkingGC();
/*
* Schedule a garbage collection cycle for a point in the future when no JS
@ -270,6 +278,13 @@ interface nsIXPCComponents_Utils : nsISupports
*/
[implicit_jscontext]
void schedulePreciseGC(in ScheduledGCCallback callback);
/*
* Schedule a shrinking garbage collection cycle for a point in the future
* when no JS is running. Call the provided function once this has occured.
*/
[implicit_jscontext]
void schedulePreciseShrinkingGC(in ScheduledGCCallback callback);
/**
* Return the keys in a weak map. This operation is

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

@ -3604,11 +3604,19 @@ nsXPCComponents_Utils::ForceGC(JSContext *cx)
return NS_OK;
}
/* void forceShrinkingGC (); */
NS_IMETHODIMP
nsXPCComponents_Utils::ForceShrinkingGC(JSContext *cx)
{
JS_ShrinkingGC(cx);
return NS_OK;
}
class PreciseGCRunnable : public nsRunnable
{
public:
PreciseGCRunnable(JSContext *aCx, ScheduledGCCallback* aCallback)
: mCallback(aCallback), mCx(aCx) {}
PreciseGCRunnable(JSContext *aCx, ScheduledGCCallback* aCallback, bool aShrinking)
: mCallback(aCallback), mCx(aCx), mShrinking(aShrinking) {}
NS_IMETHOD Run()
{
@ -3627,7 +3635,10 @@ class PreciseGCRunnable : public nsRunnable
}
}
JS_GC(mCx);
if (mShrinking)
JS_ShrinkingGC(mCx);
else
JS_GC(mCx);
mCallback->Callback();
return NS_OK;
@ -3636,13 +3647,22 @@ class PreciseGCRunnable : public nsRunnable
private:
nsRefPtr<ScheduledGCCallback> mCallback;
JSContext *mCx;
bool mShrinking;
};
/* [inline_jscontext] void schedulePreciseGC(in ScheduledGCCallback callback); */
NS_IMETHODIMP
nsXPCComponents_Utils::SchedulePreciseGC(ScheduledGCCallback* aCallback, JSContext* aCx)
{
nsRefPtr<PreciseGCRunnable> event = new PreciseGCRunnable(aCx, aCallback);
nsRefPtr<PreciseGCRunnable> event = new PreciseGCRunnable(aCx, aCallback, false);
return NS_DispatchToMainThread(event);
}
/* [inline_jscontext] void schedulePreciseShrinkingGC(in ScheduledGCCallback callback); */
NS_IMETHODIMP
nsXPCComponents_Utils::SchedulePreciseShrinkingGC(ScheduledGCCallback* aCallback, JSContext* aCx)
{
nsRefPtr<PreciseGCRunnable> event = new PreciseGCRunnable(aCx, aCallback, true);
return NS_DispatchToMainThread(event);
}