Bug 736563 - mark global objects held by live windows black during GC. r=smaug

This commit is contained in:
Andrew McCreight 2012-03-27 12:22:10 -07:00
parent 280bbd5154
commit d1c47fdce5
3 changed files with 39 additions and 2 deletions

View File

@ -378,3 +378,29 @@ nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
static PLDHashOperator
TraceActiveWindowGlobal(const PRUint64& aId, nsGlobalWindow*& aWindow, void* aClosure)
{
if (aWindow->GetDocShell() && aWindow->IsOuterWindow()) {
if (JSObject* global = aWindow->FastGetGlobalJSObject()) {
JSTracer* trc = static_cast<JSTracer *>(aClosure);
JS_CALL_OBJECT_TRACER(trc, global, "active window global");
}
}
return PL_DHASH_NEXT;
}
void
mozilla::dom::TraceBlackJS(JSTracer* aTrc)
{
if (!nsCCUncollectableMarker::sGeneration) {
return;
}
// Mark globals of active windows black.
nsGlobalWindow::WindowByIdTable* windowsById =
nsGlobalWindow::GetWindowsTable();
if (windowsById) {
windowsById->Enumerate(TraceActiveWindowGlobal, aTrc);
}
}

View File

@ -38,6 +38,8 @@
#include "nsIObserver.h"
#include "nsCycleCollectionParticipant.h"
struct JSTracer;
class nsCCUncollectableMarker : public nsIObserver
{
NS_DECL_ISUPPORTS
@ -56,10 +58,10 @@ class nsCCUncollectableMarker : public nsIObserver
return aGeneration && aGeneration == sGeneration;
}
static bool InGeneration(nsCycleCollectionTraversalCallback &cb,
static bool InGeneration(nsCycleCollectionTraversalCallback& aCb,
PRUint32 aGeneration)
{
return InGeneration(aGeneration) && !cb.WantAllTraces();
return InGeneration(aGeneration) && !aCb.WantAllTraces();
}
static PRUint32 sGeneration;
@ -68,3 +70,9 @@ private:
nsCCUncollectableMarker() {}
};
namespace mozilla {
namespace dom {
void TraceBlackJS(JSTracer* aTrc);
}
}

View File

@ -347,6 +347,9 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data)
for (e = self->mObjectHolderRoots; e; e = e->GetNextRoot())
static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
}
dom::TraceBlackJS(trc);
}
// static