Bug 1223078 - Release WrappedJS eagerly; r=mccr8

This commit is contained in:
Terrence Cole 2015-11-10 08:45:42 -08:00
parent f7dc84e977
commit d2eb4c48c0
3 changed files with 3 additions and 36 deletions

View File

@ -680,21 +680,6 @@ xpc_UnmarkSkippableJSHolders()
}
}
template<class T> static void
DoDeferredRelease(nsTArray<T>& array)
{
while (1) {
uint32_t count = array.Length();
if (!count) {
array.Compact();
break;
}
T wrapper = array[count-1];
array.RemoveElementAt(count-1);
NS_RELEASE(wrapper);
}
}
/* static */ void
XPCJSRuntime::GCSliceCallback(JSRuntime* rt,
JS::GCProgress progress,
@ -747,10 +732,6 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp* fop,
MOZ_ASSERT(self->mDoingFinalization, "bad state");
self->mDoingFinalization = false;
// Release all the members whose JSObjects are now known
// to be dead.
DoDeferredRelease(self->mWrappedJSToReleaseArray);
// Sweep scopes needing cleanup
XPCWrappedNativeScope::KillDyingScopes();
@ -945,7 +926,6 @@ XPCJSRuntime::WeakPointerZoneGroupCallback(JSRuntime* rt, void* data)
// about to be finalized and update any pointers to moved GC things.
XPCJSRuntime* self = static_cast<XPCJSRuntime*>(data);
MOZ_ASSERT(self->WrappedJSToReleaseArray().IsEmpty());
self->mWrappedJSMap->UpdateWeakPointersAfterGC(self);
XPCWrappedNativeScope::UpdateWeakPointersAfterGC(self);
@ -3336,7 +3316,6 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mDyingWrappedNativeProtoMap(XPCWrappedNativeProtoMap::newMap(XPC_DYING_NATIVE_PROTO_MAP_LENGTH)),
mDetachedWrappedNativeProtoMap(XPCWrappedNativeProtoMap::newMap(XPC_DETACHED_NATIVE_PROTO_MAP_LENGTH)),
mGCIsRunning(false),
mWrappedJSToReleaseArray(),
mNativesToReleaseArray(),
mDoingFinalization(false),
mVariantRoots(nullptr),
@ -3675,10 +3654,6 @@ XPCJSRuntime::DebugDump(int16_t depth)
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mJSRuntime @ %x", Runtime()));
XPC_LOG_ALWAYS(("mWrappedJSToReleaseArray @ %x with %d wrappers(s)",
&mWrappedJSToReleaseArray,
mWrappedJSToReleaseArray.Length()));
int cxCount = 0;
JSContext* iter = nullptr;
while (JS_ContextIterator(Runtime(), &iter))

View File

@ -88,14 +88,9 @@ void
JSObject2WrappedJSMap::UpdateWeakPointersAfterGC(XPCJSRuntime* runtime)
{
// Check all wrappers and update their JSObject pointer if it has been
// moved, or if it is about to be finalized queue the wrapper for
// destruction by adding it to an array held by the runtime.
// Note that we do not want to be changing the refcount of these wrappers.
// We add them to the array now and Release the array members later to avoid
// the posibility of doing any JS GCThing allocations during the gc cycle.
nsTArray<nsXPCWrappedJS*>& dying = runtime->WrappedJSToReleaseArray();
// moved. Release any wrappers whose weakly held JSObject has died.
nsTArray<RefPtr<nsXPCWrappedJS>> dying;
for (Map::Enum e(mTable); !e.empty(); e.popFront()) {
nsXPCWrappedJS* wrapper = e.front().value();
MOZ_ASSERT(wrapper, "found a null JS wrapper!");
@ -117,7 +112,7 @@ JSObject2WrappedJSMap::UpdateWeakPointersAfterGC(XPCJSRuntime* runtime)
if (wrapper->IsSubjectToFinalization()) {
wrapper->UpdateObjectPointerAfterGC();
if (!wrapper->GetJSObjectPreserveColor())
dying.AppendElement(wrapper);
dying.AppendElement(dont_AddRef(wrapper));
}
wrapper = wrapper->GetNextWrapper();
}

View File

@ -612,8 +612,6 @@ public:
PRTime GetWatchdogTimestamp(WatchdogTimestampCategory aCategory);
nsTArray<nsXPCWrappedJS*>& WrappedJSToReleaseArray() { return mWrappedJSToReleaseArray; }
private:
XPCJSRuntime() = delete;
explicit XPCJSRuntime(nsXPConnect* aXPConnect);
@ -639,7 +637,6 @@ private:
XPCWrappedNativeProtoMap* mDyingWrappedNativeProtoMap;
XPCWrappedNativeProtoMap* mDetachedWrappedNativeProtoMap;
bool mGCIsRunning;
nsTArray<nsXPCWrappedJS*> mWrappedJSToReleaseArray;
nsTArray<nsISupports*> mNativesToReleaseArray;
bool mDoingFinalization;
XPCRootSetElem* mVariantRoots;