Bug 882893: Move observer notifications out of the cycle collector and into the runtime. r=smaug

This commit is contained in:
Kyle Huey 2013-06-19 14:06:50 -07:00
parent 1f59b0c2e7
commit c696ced296
4 changed files with 29 additions and 9 deletions

View File

@ -15,6 +15,7 @@
#include "dom_quickstubs.h"
#include "nsIMemoryReporter.h"
#include "nsIObserverService.h"
#include "amIAddonManager.h"
#include "nsPIDOMWindow.h"
#include "nsPrintfCString.h"
@ -532,6 +533,24 @@ XPCJSRuntime::UnmarkSkippableJSHolders()
CycleCollectedJSRuntime::UnmarkSkippableJSHolders();
}
void
XPCJSRuntime::PrepareForForgetSkippable()
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr, "cycle-collector-forget-skippable", nullptr);
}
}
void
XPCJSRuntime::PrepareForCollection()
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr, "cycle-collector-begin", nullptr);
}
}
void
xpc_UnmarkSkippableJSHolders()
{

View File

@ -742,6 +742,8 @@ public:
void TraceAdditionalNativeGrayRoots(JSTracer* aTracer);
void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb);
void UnmarkSkippableJSHolders();
void PrepareForForgetSkippable() MOZ_OVERRIDE;
void PrepareForCollection() MOZ_OVERRIDE;
static void GCCallback(JSRuntime *rt, JSGCStatus status);
static void GCSliceCallback(JSRuntime *rt,

View File

@ -171,6 +171,9 @@ public:
bool NeedCollect() const;
void Collect(uint32_t reason) const;
virtual void PrepareForForgetSkippable() {}
virtual void PrepareForCollection() {}
private:
typedef const CCParticipantVTable<JSGCThingParticipant>::Type GCThingParticipantVTable;
const GCThingParticipantVTable mGCThingCycleCollectorGlobal;

View File

@ -116,12 +116,10 @@
#include "plstr.h"
#include "nsPrintfCString.h"
#include "nsTArray.h"
#include "nsIObserverService.h"
#include "nsIConsoleService.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "nsTArray.h"
#include "mozilla/Services.h"
#include "mozilla/Attributes.h"
#include "nsICycleCollectorListener.h"
#include "nsIXPConnect.h"
@ -2191,9 +2189,8 @@ nsCycleCollector::SelectPurple(GCGraphBuilder &builder)
void
nsCycleCollector::ForgetSkippable(bool removeChildlessNodes)
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr, "cycle-collector-forget-skippable", nullptr);
if (mJSRuntime) {
mJSRuntime->PrepareForForgetSkippable();
}
mPurpleBuf.RemoveSkippable(removeChildlessNodes);
if (mForgetSkippableCB) {
@ -2695,10 +2692,9 @@ nsCycleCollector::PrepareForCollection(nsCycleCollectorResults *aResults,
mCollectionInProgress = true;
nsCOMPtr<nsIObserverService> obs =
mozilla::services::GetObserverService();
if (obs)
obs->NotifyObservers(nullptr, "cycle-collector-begin", nullptr);
if (mJSRuntime) {
mJSRuntime->PrepareForCollection();
}
mFollowupCollection = false;