Bug 1276112. Stop using GetScriptContextFromJSContext in CycleCollectedJSRuntime::UsefulToMergeZones. r=mccr8

This commit is contained in:
Boris Zbarsky 2016-05-27 13:28:26 -04:00
Родитель 4ec7cc4fc1
Коммит 74ebb7940f
4 изменённых файлов: 34 добавлений и 31 удалений

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

@ -596,6 +596,38 @@ CompartmentSizeOfIncludingThisCallback(MallocSizeOf mallocSizeOf, JSCompartment*
return priv ? priv->SizeOfIncludingThis(mallocSizeOf) : 0;
}
/*
* Return true if there exists a non-system inner window which is a current
* inner window and whose reflector is gray. We don't merge system
* compartments, so we don't use them to trigger merging CCs.
*/
bool XPCJSRuntime::UsefulToMergeZones() const
{
MOZ_ASSERT(NS_IsMainThread());
nsGlobalWindow::WindowByIdTable* windowsById =
nsGlobalWindow::GetWindowsTable();
if (!windowsById) {
return false;
}
for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) {
nsGlobalWindow* window = iter.Data();
if (!window->IsInnerWindow() ||
!window->AsInner()->IsCurrentInnerWindow()) {
continue;
}
JSObject* reflector = window->FastGetGlobalJSObject();
if (JS::ObjectIsMarkedGray(reflector) &&
!js::IsSystemCompartment(js::GetObjectCompartment(reflector))) {
return true;
}
}
return false;
}
void XPCJSRuntime::TraceNativeBlackRoots(JSTracer* trc)
{
// Skip this part if XPConnect is shutting down. We get into

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

@ -543,6 +543,7 @@ public:
return mStrings[index];
}
virtual bool UsefulToMergeZones() const override;
void TraceNativeBlackRoots(JSTracer* trc) override;
void TraceAdditionalNativeGrayRoots(JSTracer* aTracer) override;
void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb) override;

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

@ -1176,39 +1176,9 @@ CycleCollectedJSRuntime::TraverseRoots(nsCycleCollectionNoteRootCallback& aCb)
return NS_OK;
}
/*
* Return true if there exists a JSContext with a default global whose current
* inner is gray. The intent is to look for JS Object windows. We don't merge
* system compartments, so we don't use them to trigger merging CCs.
*/
bool
CycleCollectedJSRuntime::UsefulToMergeZones() const
{
MOZ_ASSERT(mJSRuntime);
if (!NS_IsMainThread()) {
return false;
}
JSContext* iter = nullptr;
JSContext* cx;
JSAutoRequest ar(nsContentUtils::GetSafeJSContext());
while ((cx = JS_ContextIterator(mJSRuntime, &iter))) {
// Skip anything without an nsIScriptContext.
nsIScriptContext* scx = GetScriptContextFromJSContext(cx);
JS::RootedObject obj(cx, scx ? scx->GetWindowProxyPreserveColor() : nullptr);
if (!obj) {
continue;
}
MOZ_ASSERT(js::IsWindowProxy(obj));
// Grab the global from the WindowProxy.
obj = js::ToWindowIfWindowProxy(obj);
MOZ_ASSERT(JS_IsGlobalObject(obj));
if (JS::ObjectIsMarkedGray(obj) &&
!js::IsSystemCompartment(js::GetObjectCompartment(obj))) {
return true;
}
}
return false;
}

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

@ -299,7 +299,7 @@ public:
nsCycleCollectionParticipant* ZoneParticipant();
nsresult TraverseRoots(nsCycleCollectionNoteRootCallback& aCb);
bool UsefulToMergeZones() const;
virtual bool UsefulToMergeZones() const;
void FixWeakMappingGrayBits() const;
bool AreGCGrayBitsValid() const;
void GarbageCollect(uint32_t aReason) const;