зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1414974 - Part 5: Rework nsWindowMemoryReporter to only examine inner windows, r=mccr8
MozReview-Commit-ID: 3be0C8OXSKo
This commit is contained in:
Родитель
2cb3ebf10d
Коммит
71760158e8
|
@ -3551,9 +3551,8 @@ nsGlobalWindow::DetachFromDocShell()
|
|||
inner->FreeInnerObjects();
|
||||
}
|
||||
|
||||
if (auto* reporter = nsWindowMemoryReporter::Get()) {
|
||||
reporter->ObserveDOMWindowDetached(this);
|
||||
}
|
||||
// Don't report that we were detached to the nsWindowMemoryReporter, as it
|
||||
// only tracks inner windows.
|
||||
|
||||
NotifyWindowIDDestroyed("outer-window-destroyed");
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ NS_IMPL_ISUPPORTS(nsWindowMemoryReporter, nsIMemoryReporter, nsIObserver,
|
|||
nsISupportsWeakReference)
|
||||
|
||||
static nsresult
|
||||
AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow,
|
||||
AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindowOuter* aWindow,
|
||||
nsTabSizes* aSizes)
|
||||
{
|
||||
// Measure the window.
|
||||
|
@ -58,8 +58,7 @@ AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow,
|
|||
aWindow->AddSizeOfIncludingThis(windowSizes);
|
||||
|
||||
// Measure the inner window, if there is one.
|
||||
nsGlobalWindow* inner = aWindow->IsOuterWindow() ? aWindow->GetCurrentInnerWindowInternal()
|
||||
: nullptr;
|
||||
nsGlobalWindowInner* inner = aWindow->GetCurrentInnerWindowInternal();
|
||||
if (inner) {
|
||||
inner->AddSizeOfIncludingThis(windowSizes);
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_STATE(child);
|
||||
|
||||
nsGlobalWindow* childWin = nsGlobalWindow::Cast(child);
|
||||
nsGlobalWindowOuter* childWin = nsGlobalWindowOuter::Cast(child);
|
||||
|
||||
rv = AddNonJSSizeOfWindowAndItsDescendents(childWin, aSizes);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -131,7 +130,7 @@ nsWindowMemoryReporter::Get()
|
|||
}
|
||||
|
||||
static already_AddRefed<nsIURI>
|
||||
GetWindowURI(nsGlobalWindow* aWindow)
|
||||
GetWindowURI(nsGlobalWindowInner* aWindow)
|
||||
{
|
||||
NS_ENSURE_TRUE(aWindow, nullptr);
|
||||
|
||||
|
@ -162,8 +161,16 @@ GetWindowURI(nsGlobalWindow* aWindow)
|
|||
return uri.forget();
|
||||
}
|
||||
|
||||
// Forward to the inner window if we need to when getting the window's URI.
|
||||
static already_AddRefed<nsIURI>
|
||||
GetWindowURI(nsGlobalWindowOuter* aWindow)
|
||||
{
|
||||
NS_ENSURE_TRUE(aWindow, nullptr);
|
||||
return GetWindowURI(aWindow->GetCurrentInnerWindowInternal());
|
||||
}
|
||||
|
||||
static void
|
||||
AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize)
|
||||
AppendWindowURI(nsGlobalWindowInner *aWindow, nsACString& aStr, bool aAnonymize)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
|
||||
|
||||
|
@ -233,7 +240,7 @@ ReportCount(const nsCString& aBasePath, const char* aPathTail,
|
|||
}
|
||||
|
||||
static void
|
||||
CollectWindowReports(nsGlobalWindow *aWindow,
|
||||
CollectWindowReports(nsGlobalWindowInner *aWindow,
|
||||
amIAddonManager *addonManager,
|
||||
nsWindowSizes *aWindowTotalSizes,
|
||||
nsTHashtable<nsUint64HashKey> *aGhostWindowIDs,
|
||||
|
@ -247,7 +254,7 @@ CollectWindowReports(nsGlobalWindow *aWindow,
|
|||
|
||||
// Avoid calling aWindow->GetTop() if there's no outer window. It will work
|
||||
// just fine, but will spew a lot of warnings.
|
||||
nsGlobalWindow *top = nullptr;
|
||||
nsGlobalWindowOuter *top = nullptr;
|
||||
nsCOMPtr<nsIURI> location;
|
||||
if (aWindow->GetOuterWindow()) {
|
||||
// Our window should have a null top iff it has a null docshell.
|
||||
|
@ -276,7 +283,7 @@ CollectWindowReports(nsGlobalWindow *aWindow,
|
|||
|
||||
if (top) {
|
||||
windowPath += NS_LITERAL_CSTRING("top(");
|
||||
AppendWindowURI(top, windowPath, aAnonymize);
|
||||
AppendWindowURI(top->GetCurrentInnerWindowInternal(), windowPath, aAnonymize);
|
||||
windowPath.AppendPrintf(", id=%" PRIu64 ")", top->WindowID());
|
||||
|
||||
aTopWindowPaths->Put(aWindow->WindowID(), windowPath);
|
||||
|
@ -538,14 +545,14 @@ CollectWindowReports(nsGlobalWindow *aWindow,
|
|||
#undef REPORT_COUNT
|
||||
}
|
||||
|
||||
typedef nsTArray< RefPtr<nsGlobalWindow> > WindowArray;
|
||||
typedef nsTArray< RefPtr<nsGlobalWindowInner> > WindowArray;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
nsISupports* aData, bool aAnonymize)
|
||||
{
|
||||
nsGlobalWindow::WindowByIdTable* windowsById =
|
||||
nsGlobalWindow::GetWindowsTable();
|
||||
nsGlobalWindowInner::InnerWindowByIdTable* windowsById =
|
||||
nsGlobalWindowInner::GetWindowsTable();
|
||||
NS_ENSURE_TRUE(windowsById, NS_OK);
|
||||
|
||||
// Hold on to every window in memory so that window objects can't be
|
||||
|
@ -560,14 +567,14 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||
nsTHashtable<nsUint64HashKey> ghostWindows;
|
||||
CheckForGhostWindows(&ghostWindows);
|
||||
for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
nsGlobalWindow::WindowByIdTable* windowsById =
|
||||
nsGlobalWindow::GetWindowsTable();
|
||||
nsGlobalWindowInner::InnerWindowByIdTable* windowsById =
|
||||
nsGlobalWindowInner::GetWindowsTable();
|
||||
if (!windowsById) {
|
||||
NS_WARNING("Couldn't get window-by-id hashtable?");
|
||||
continue;
|
||||
}
|
||||
|
||||
nsGlobalWindow* window = windowsById->Get(iter.Get()->GetKey());
|
||||
nsGlobalWindowInner* window = windowsById->Get(iter.Get()->GetKey());
|
||||
if (!window) {
|
||||
NS_WARNING("Could not look up window?");
|
||||
continue;
|
||||
|
@ -784,7 +791,7 @@ nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
}
|
||||
|
||||
void
|
||||
nsWindowMemoryReporter::ObserveDOMWindowDetached(nsGlobalWindow* aWindow)
|
||||
nsWindowMemoryReporter::ObserveDOMWindowDetached(nsGlobalWindowInner* aWindow)
|
||||
{
|
||||
nsWeakPtr weakWindow = do_GetWeakReference(static_cast<nsIDOMEventTarget*>(aWindow));
|
||||
if (!weakWindow) {
|
||||
|
@ -881,8 +888,8 @@ nsWindowMemoryReporter::CheckForGhostWindows(
|
|||
return;
|
||||
}
|
||||
|
||||
nsGlobalWindow::WindowByIdTable *windowsById =
|
||||
nsGlobalWindow::GetWindowsTable();
|
||||
nsGlobalWindowInner::InnerWindowByIdTable *windowsById =
|
||||
nsGlobalWindowInner::GetWindowsTable();
|
||||
if (!windowsById) {
|
||||
NS_WARNING("GetWindowsTable returned null");
|
||||
return;
|
||||
|
@ -898,7 +905,7 @@ nsWindowMemoryReporter::CheckForGhostWindows(
|
|||
for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) {
|
||||
// Null outer window implies null top, but calling GetTop() when there's no
|
||||
// outer window causes us to spew debug warnings.
|
||||
nsGlobalWindow* window = iter.UserData();
|
||||
nsGlobalWindowInner* window = iter.UserData();
|
||||
if (!window->GetOuterWindow() || !window->GetTopInternal()) {
|
||||
// This window is detached, so we don't care about its domain.
|
||||
continue;
|
||||
|
@ -948,7 +955,7 @@ nsWindowMemoryReporter::CheckForGhostWindows(
|
|||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri = GetWindowURI(nsGlobalWindow::Cast(window));
|
||||
nsCOMPtr<nsIURI> uri = GetWindowURI(nsGlobalWindowInner::Cast(window));
|
||||
|
||||
nsAutoCString domain;
|
||||
if (uri) {
|
||||
|
@ -1004,8 +1011,8 @@ nsWindowMemoryReporter::UnlinkGhostWindows()
|
|||
return;
|
||||
}
|
||||
|
||||
nsGlobalWindow::WindowByIdTable* windowsById =
|
||||
nsGlobalWindow::GetWindowsTable();
|
||||
nsGlobalWindowInner::InnerWindowByIdTable* windowsById =
|
||||
nsGlobalWindowInner::GetWindowsTable();
|
||||
if (!windowsById) {
|
||||
return;
|
||||
}
|
||||
|
@ -1021,13 +1028,13 @@ nsWindowMemoryReporter::UnlinkGhostWindows()
|
|||
nsTHashtable<nsUint64HashKey> ghostWindows;
|
||||
sWindowReporter->CheckForGhostWindows(&ghostWindows);
|
||||
for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) {
|
||||
nsGlobalWindow::WindowByIdTable* windowsById =
|
||||
nsGlobalWindow::GetWindowsTable();
|
||||
nsGlobalWindowInner::InnerWindowByIdTable* windowsById =
|
||||
nsGlobalWindowInner::GetWindowsTable();
|
||||
if (!windowsById) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<nsGlobalWindow> window = windowsById->Get(iter.Get()->GetKey());
|
||||
RefPtr<nsGlobalWindowInner> window = windowsById->Get(iter.Get()->GetKey());
|
||||
if (window) {
|
||||
window->RiskyUnlink();
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
#endif
|
||||
|
||||
static nsWindowMemoryReporter* Get();
|
||||
void ObserveDOMWindowDetached(nsGlobalWindow* aWindow);
|
||||
void ObserveDOMWindowDetached(nsGlobalWindowInner* aWindow);
|
||||
|
||||
static int64_t GhostWindowsDistinguishedAmount();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче