Bug 1675820 - Part 6: Make DocGroup cycle-collected, r=farre,smaug

Previously, the DocGroup type was not cycle-collected, as it needed to have
references from other threads for Quantum DOM. Nowadays the only off-main-thread
use of DocGroup is for dispatching runnables to the main thread which should be
tracked using a performance counter for about:performance. This means we can
remove the DocGroup references from these dispatching callsites, only storing
the Performance Counter we're interested in, and simplify make DocGroup be
cycle-collected itself.

This fixes a leak caused by adding the WindowGlobalChild getter to
WindowContext, by allowing cycles between the document and its BrowsingContext
to be broken by the cycle-collector.

Differential Revision: https://phabricator.services.mozilla.com/D108865
This commit is contained in:
Nika Layzell
2021-03-18 19:24:50 +00:00
parent 62a56e6213
commit 1dab7892f1
12 changed files with 80 additions and 77 deletions

View File

@@ -1256,14 +1256,15 @@ nsresult nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest) {
// previous normal load in the history.
mReparseForbidden = !(mMode == NORMAL || mMode == PLAIN_TEXT);
mDocGroup = mExecutor->GetDocument()->GetDocGroup();
mNetworkEventTarget =
mExecutor->GetDocument()->EventTargetFor(TaskCategory::Network);
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mRequest, &rv));
if (NS_SUCCEEDED(rv)) {
// Non-HTTP channels are bogus enough that we let them work with unlabeled
// runnables for now. Asserting for HTTP channels only.
MOZ_ASSERT(mDocGroup || mMode == LOAD_AS_DATA,
"How come the doc group is still null?");
MOZ_ASSERT(mNetworkEventTarget || mMode == LOAD_AS_DATA,
"How come the network event target is still null?");
nsAutoCString method;
Unused << httpChannel->GetRequestMethod(method);
@@ -2189,8 +2190,8 @@ void nsHtml5StreamParser::MarkAsBroken(nsresult aRv) {
nsresult nsHtml5StreamParser::DispatchToMain(
already_AddRefed<nsIRunnable>&& aRunnable) {
if (mDocGroup) {
return mDocGroup->Dispatch(TaskCategory::Network, std::move(aRunnable));
if (mNetworkEventTarget) {
return mNetworkEventTarget->Dispatch(std::move(aRunnable));
}
return SchedulerGroup::UnlabeledDispatch(TaskCategory::Network,
std::move(aRunnable));