mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
5499b4356b
- Bug 1155371 - Include DOMMediaStream and MediaSource object URLs in memory reports. r=khuey (b62513f5c6)
- Bug 1187782 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (aa14b536c4)
- Bug 1187782 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (1645a9b910)
- Bug 1187782 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (67a83f37d5)
- Bug 1187782 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (bf1f7a8dfe)
- Bug 1187782 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (b76f1f34c8)
- Bug 1187782 (part 6) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (f44312f3a9)
- Bug 1187782 (part 7) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (33bb281955)
- Bug 1187782 (part 8) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (52f7bc040e)
- Bug 1187782 (part 9) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey. (7e797025a3)
- Bug 1207355 (Part 1) - Stop requesting decodes in nsDocument. r=tn (b2e6eb49c0)
- Bug 1202085 - Part 1: Remove imgICache::RemoveEntry(); r=seth (b5e4e2242f)
- Bug 1202085 - Part 2: Add an optional document argument to imgICache::FindEntryProperties(); r=seth (3f3138e5ba)
- Bug 1202085 - Part 3: Relax the assertion in ServiceWorkerManager::IsControlled to only happen when we think the document is controlled; r=jdm (6a829a6985)
- Bug 1202085 - Part 4: Add an ID for controlled document to the image cache key; r=seth (525ca69231)
- Bug 1202085 - Part 5: Add an automated test for the interaction of image cache with controlled documents; r=jdm (627e28d58d)
- Bug 1202085 - Part 6: Clear the entries in the image cache belonging to a controlled document when it gets destroyed; r=seth (935b858eac)
- Bug 1221279 Don't crash while clearing imgLoader cache when disconnected document is destroyed. r=smaug (040d3fa2be)
- Bug 1207084 - keep sheet level on tokenstream for use in ruledata when resolving variables, to fix hcm issues with CSS variables, r=heycam (2d8f5af005)
- Bug 1207084 - addendum: fix operator== for nsCSSValueTokenStream, implied-r=heycam (ee66d21638)
- Bug 1209124 - Bail out of nsStyleSet::GatherRuleProcessors and PresShell::Observe if we're called during/after shutdown. r=dbaron (7043eb3ee7)
- Bug 1216043 - Rename nsStyleSheet::sheetType and make it an enum class. r=dbaron (f03c5328e6)
- Bug 1168158 - Make URLValue::mString a smart pointer. r=heycam (06e37619be)
- Bug 1216038 - Deduce underlying integer type for MakeEnumeratedRange starting at 0. r=froydnj (883c74fb6b)
- Bug 1216040 - Make ArrayLength support mozilla::EnumeratedArray. r=froydnj (d1fc4aa43c)
- Bug 1216041 - Add ranged iterator support to mozilla::{Array,RangedArray,EnumerationArray}. r=froydnj (bf71f0ea1f)
- Bug 1128787 part.1 Add test r=ehsan (97016bbd85)
- Bug 1128787 part.2 nsHTMLDocument should clear focus before making itself editable when designMode is enabled and it makes the focused content non-focusable r=smaug+enndeakin (eccab99994)
- Bug 1171342 - Store contenteditable.css and designmode.css in the style sheet cache. r=jwatt (7e6aa290d2)
- Bug 1164279 - Disable font-variant-east-asian: ruby for <rt> on Windows. r=jfkthame (04117062d7)
- Bug 1126230 part 9 - Remove fullscreen override and related test. r=dbaron (18818d67fa)
- Bug 1126230 part 1 - Use delegated constructor to simplify constructor of nsFrameConstructorState. r=bz (5c1193f9f5)
- Bug 1126230 part 2 - Refactor part of nsFrameConstructorState::AddChild. r=bz (3c02f9e8c2)
- Bug 1126230 part 3 - Add :-moz-browser-frame pseudo class for HTML browser frame elements. r=dbaron (6a7b01f092)
- Bug 1211040 - Restrict -moz-window-{dragging,shadow} to be chrome-only. r=dbaron (005f02f673)
- Bug 1126230 part 4 - Add -moz-top-layer internal CSS property and set it for fullscreen elements. r=dbaron (02d841cab7)
- Bug 1203405 - Ignore order of abs/fixed-pos frames in the frame list. r=roc (d67696d0ea)
- Bug 1126230 part 5 - Give proper geometric parent for top layer frames. r=bz,dbaron (19504f223e)
- Bug 1126230 part 6 - Add nsIDocument::GetFullscreenStack() method. r=smaug (d401d534d1)
- Bug 1126230 part 7 - Add static method nsDisplayListBuilder::GetOutOfFlowData(). r=roc (3bdafef9b2)
- Bug 1126230 part 8 - Implement painting part for the top layer. r=roc (8875115dc1)
- Bug 1126230 part 10 - Add test for fullscreen top layer. r=dbaron (d095d85cd0)
- Bug 1069192 part 1 - Force users of nsCSSProps::IsEnabled() to pass in the enabled state. r=dbaron (38e40ebf1d)
- Bug 1195978 - set line number when re-parsing sheet. r=heycam (41cdf15319)
- Bug 1202095 - re-use @imported style sheets from inIDOMUtils.parseStyleSheet. r=heycam (2f54fdacf0)
- Bug 1099557 followup - Put the default setting for control-character visibility behind a runtime pref, and keep it off-by-default on release builds for now. r=dbaron (3ada076d9b)
- Bug 1069192 part 2 - Add a flag for chrome-only properties and change semantics of enabling flags. r=dbaron (2e887397ac)
- Bug 1220496 - Create PresHint/StyleAttr rule processors in nsStyleSet::Init and make DirtyRuleProcessors private. r=bzbarsky (0b538fe7cc)
- No bug - Cleanup the layout/style mochitest manifest. (e26676496f)
- Bug 1183461 part 1 - Move InitialAdvance to CSSAnimation; r=heycam (dac91a759a)
- Bug 1183461 part 2 - Reorder the parameters to EventInfo constructors; r=heycam (29fc1b2096)
- Bug 1183461 part 3 - Add Animation::AnimationTimeToTimeStamp; r=heycam (d3410ccc01)
- Bug 1183461 part 4 - Add CSSAnimation::ElapsedTimeToTimeStamp; r=heycam (10bac42e8e)
- Bug 1183461 part 5 - Store event TimeStamp along with event info; r=heycam (0250a63ee8)
- Bug 1220599 - Fix erroneous nsHTMLDocument::Open comment to note that we reuse the document rather than creating a new one. r=baku (5d492865d3)
- Bug 1220827 - Replace question comment in nsHTMLDocument::Open with an explanatory comment to explain why we create a new Window. r=smaug (69f16ef5dc)
- missing bits of Bug 1170911 - Add pref for switching off execCommand("cut"/"copy"). r=ehsan (613644fa39)
- Bug 1183461 part 6 - Store the generating animation on the event; r=heycam (c490af70cc)
- Bug 1194037 part 4 - Remove ticking from FlushAnimations; r=dholbert (8df1f3eec4)
- Bug 1200568 - Don't create animations for elements that are not part of the document tree; r=dbaron (3027949d8b)
- Bug 1183461 part 7 - Add EventInfoComparator and sort events; r=heycam (550aad09bc)
- Bug 1183461 part 8 - Add tests for event order dispatch; r=heycam (964ee5fe23)
- Bug 978833 patch 1 - Add mochitest for bug 978833. r=heycam (4b4579d3f7)
- Bug 1208951 - Part 1: Split half of KeyframeValueEntry into a base class. r=birtles (32d7cbd477)
- Bug 1208951 - Part 2: Use a comparator object instead of operator< onKeyframeValueEntry. r=birtles (3b83723ef0)
- Bug 1209603 patch 1 - Add comments to RuleNodeCacheConditions.h . r=heycam (444eabdddc)
- Bug 1209603 patch 2 - Reduce calls to StyleVisibility() in WritingMode constructor. r=heycam (f079fb5765)
- Bug 1209603 patch 3 - Don't call SetFontSizeDependency for 0em. r=heycam (7a87fe5229)
- Bug 1209603 patch 4 - Add reftest for bug 1209603. r=heycam (1680144fc2)
- Bug 1209603 patch 5 - Move inline method nsStyleContext::GetCachedStyleData into header file, and make it public. r=heycam (32c38f790e)
- Bug 1209603 patch 6 - Prepare to use a different meaning of mBits when cached style data pointer is null. r=heycam (15e6471e58)
- Bug 1209603 patch 7 - Add assertions that we don't ask the rule node for data when we have cached data on the style context. r=heycam (0f27687446)
- Bug 1209603 patch 8 - Record in mBits when we have gotten a reset style struct that is cached on the rule node. r=heycam (b5e693a986)
- Bug 1209603 patch 9 - Cache inherited style structs on the style context when we found already-cached data in the rule tree. r=heycam (bfa6a169cb)
- Bug 1209603 patch 10 - Make PeekStyle* exact, i.e., guaranteed to return null if we haven't computed the data for this context. r=heycam (6ffdf7f0bf)
- Bug 1209603 patch 11 - Assert that PeekStyle* results don't change during difference computation. r=heycam (a3d7336dce)
- Bug 1193518 - Ensure that when we update a WritingMode after resolving dir=auto, we set the inline-dir bit appropriately as well as the inline-bidi bit. r=dholbert (072c062ddc)
- Bug 1216431 patch 1 - Give WritingMode an nsStyleVisibility* constructor. r=heycam (b7efb1204c)
- Bug 1216431 patch 2 - Pass nsStyleVisibility to nsStylePosition::CalcDifference to avoid computing new nsStyleVisibility during nsStyleContext::CalcStyleDifference. r=heycam (b842123d9b)
- Bug 1216431 patch 3 - Cache structs that are stored with conditions on the rule node all the time, rather than only when freshly computed. r=heycam (d4ea9adc19)
- Bug 1216431 patch 4 - Don't trigger computation of new structs via testing of conditions for conditionally-stored structs on the rule node. r=heycam (95cc7e8a52)
- Bug 1216431 patch 5 - Back out half of bug 1209603 patch 10. r=heycam (5949a2e9d0)
- Bug 1216431 patch 6 - Back out bug 1209603 patch 8. r=heycam (45a05ad60e)
- Bug 1209603 patch 6b - Rename nsStyleContext::HasCachedInheritedStyleData to HasCachedDependentStyleData. r=heycam (c4f52f00d0)
- Bug 1216431 patch 7 - Back out bug 1209603 patch 6. r=heycam (6eb8677af2)
- Bug 1216431 patch 8 - Fix whitespace error I made when addressing review comments. (19abf29215)
- Bug 1214958 - Add operators &=, |=, and ^= to mozilla::DebugOnly. r=froydnj (c76229e817)
- Bug 1208951 - Part 3: Expose nsCSSValue -> nsTimingFunction computation function. r=birtles (f0124bbbf2)
- Bug 1208951 - Part 4: Add an nsCSSParser entry point to parse a single longhand property and return an nsCSSValue. r=birtles (a317aa3255)
- Bug 1208951 - Part 5: Add nsCSSProps method to look a property by its IDL name. r=bzbarsky (1d0b78374d)
- Bug 1208951 - Part 6: Add method to compare nsCSSPropertySets for equality. r=birtles (9039197290)
- Bug 1208951 - Part 7: Add a StyleAnimationValue::ComputeValues method to compute components of a shorthand. r=birtles (36149d8c82)
- Bug 1208951 - Part 8: Don't warn if StyleAnimationValue::ComputeValue fails to parse a CSS property. r=birtles (12e06d0356)
- Bug 1208385 part 1 - Store a pointer to the owning animation on each KeyframeEffect; r=heycam (8f48533047)
- Bug 1208385 part 2 - Remove stored parent time from KeyframeEffectReadOnly and get the time directly from the owning animation; r=heycam (7bd25845be)
- Bug 1208951 - Part 9: Implement KeyframeEffectReadOnly constructor. r=bzbarsky r=birtles (49049edfac)
- Bug 1208951 - Part 10: Make GetFrames aware of initial/final zero-length segments and discontinuities between segments. r=birtles (71066c4941)
- Bug 1208951 - Part 11: Tests. r=birtles (308ad9ba9f)
- Bug 1210575 part 1: Rename CSS parser function "ParseWebkitPrefixedGradient()" to be more specific, now that we'll have several ways of parsing these expressions. r=heycam (060a01b43a)
- Bug 1210575 part 2: Refactor out the body of a long compound "if" expression into a helper function, IsFunctionTokenValidForBackgroundImage. r=heycam (ed784fb98d)
- Bug 1210575 part 3: Refactor CSS gradient-parsing code to use a flags bitfield instead of multiple bool args for customizing behavior. r=heycam (5c9df6466c)
- Bug 1210575 part 4: Prevent CSS parser from invoking CSSUnprefixingService if native webkit prefix support is enabled. r=heycam (d4c7997c94)
- Bug 1210575 part 5: Allow CSS -webkit-{linear|radial}-gradient expressions (& 'repeating' variants) to make it to our gradient-parsing code, if webkit prefix support is preffed on. r=heycam (4113bb47c4)
- Bug 1207002 - Use CSS property flag to restrict MathML-related internal properties. r=dbaron (9b021c7819)
- Bug 1199610 - Correctly handle parsing failures inside CSS functions. r=dbaron (5255fe445d)
- Bug 1210575 part 6: Implement -webkit-radial-gradient parse quirks with contain/cover keywords, sized shapes, "at" keyword, & angles. r=heycam (ba1002fbae)
- Bug 1210575 part 7: Refactor linear-gradient parsing code slightly & add/extend comments. r=heycam (1bd144ff04)
- Bug 1210575 part 8: Implement -webkit-linear-gradient parse quirks with "to", angles, and "center". r=heycam (97587d49ea)
- Bug 1210575 part 9: Remove some obsolete XXXdholbert comments from property_database.js. (no review, comment-only so DONTBUILD) (961a2c43e9)
- Bug 978833 patch 2 - Make css::Declaration reference-counted. r=heycam (4aab911856)
919 lines
32 KiB
C++
919 lines
32 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "amIAddonManager.h"
|
|
#include "nsWindowMemoryReporter.h"
|
|
#include "nsGlobalWindow.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIDOMWindowCollection.h"
|
|
#include "nsIEffectiveTLDService.h"
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/StaticPtr.h"
|
|
#include "nsNetCID.h"
|
|
#include "nsPrintfCString.h"
|
|
#include "XPCJSMemoryReporter.h"
|
|
#include "js/MemoryMetrics.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
StaticRefPtr<nsWindowMemoryReporter> sWindowReporter;
|
|
|
|
/**
|
|
* Don't trigger a ghost window check when a DOM window is detached if we've
|
|
* run it this recently.
|
|
*/
|
|
const int32_t kTimeBetweenChecks = 45; /* seconds */
|
|
|
|
nsWindowMemoryReporter::nsWindowMemoryReporter()
|
|
: mLastCheckForGhostWindows(TimeStamp::NowLoRes()),
|
|
mCycleCollectorIsRunning(false),
|
|
mCheckTimerWaitingForCCEnd(false)
|
|
{
|
|
}
|
|
|
|
nsWindowMemoryReporter::~nsWindowMemoryReporter()
|
|
{
|
|
KillCheckTimer();
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(nsWindowMemoryReporter, nsIMemoryReporter, nsIObserver,
|
|
nsISupportsWeakReference)
|
|
|
|
static nsresult
|
|
AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow,
|
|
nsTabSizes* aSizes)
|
|
{
|
|
// Measure the window.
|
|
nsWindowSizes windowSizes(moz_malloc_size_of);
|
|
aWindow->AddSizeOfIncludingThis(&windowSizes);
|
|
windowSizes.addToTabSizes(aSizes);
|
|
|
|
// Measure the inner window, if there is one.
|
|
nsWindowSizes innerWindowSizes(moz_malloc_size_of);
|
|
nsGlobalWindow* inner = aWindow->IsOuterWindow() ? aWindow->GetCurrentInnerWindowInternal()
|
|
: nullptr;
|
|
if (inner) {
|
|
inner->AddSizeOfIncludingThis(&innerWindowSizes);
|
|
innerWindowSizes.addToTabSizes(aSizes);
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMWindowCollection> frames;
|
|
nsresult rv = aWindow->GetFrames(getter_AddRefs(frames));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
uint32_t length;
|
|
rv = frames->GetLength(&length);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Measure this window's descendents.
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
nsCOMPtr<nsIDOMWindow> child;
|
|
rv = frames->Item(i, getter_AddRefs(child));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
NS_ENSURE_STATE(child);
|
|
|
|
nsGlobalWindow* childWin =
|
|
static_cast<nsGlobalWindow*>(static_cast<nsIDOMWindow *>(child.get()));
|
|
|
|
rv = AddNonJSSizeOfWindowAndItsDescendents(childWin, aSizes);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
static nsresult
|
|
NonJSSizeOfTab(nsPIDOMWindow* aWindow, size_t* aDomSize, size_t* aStyleSize, size_t* aOtherSize)
|
|
{
|
|
nsGlobalWindow* window = static_cast<nsGlobalWindow*>(aWindow);
|
|
|
|
nsTabSizes sizes;
|
|
nsresult rv = AddNonJSSizeOfWindowAndItsDescendents(window, &sizes);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
*aDomSize = sizes.mDom;
|
|
*aStyleSize = sizes.mStyle;
|
|
*aOtherSize = sizes.mOther;
|
|
return NS_OK;
|
|
}
|
|
|
|
/* static */ void
|
|
nsWindowMemoryReporter::Init()
|
|
{
|
|
MOZ_ASSERT(!sWindowReporter);
|
|
sWindowReporter = new nsWindowMemoryReporter();
|
|
ClearOnShutdown(&sWindowReporter);
|
|
RegisterStrongMemoryReporter(sWindowReporter);
|
|
RegisterNonJSSizeOfTab(NonJSSizeOfTab);
|
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
|
if (os) {
|
|
// DOM_WINDOW_DESTROYED_TOPIC announces what we call window "detachment",
|
|
// when a window's docshell is set to nullptr.
|
|
os->AddObserver(sWindowReporter, DOM_WINDOW_DESTROYED_TOPIC,
|
|
/* weakRef = */ true);
|
|
os->AddObserver(sWindowReporter, "after-minimize-memory-usage",
|
|
/* weakRef = */ true);
|
|
os->AddObserver(sWindowReporter, "cycle-collector-begin",
|
|
/* weakRef = */ true);
|
|
os->AddObserver(sWindowReporter, "cycle-collector-end",
|
|
/* weakRef = */ true);
|
|
}
|
|
|
|
RegisterStrongMemoryReporter(new GhostWindowsReporter());
|
|
RegisterGhostWindowsDistinguishedAmount(GhostWindowsReporter::DistinguishedAmount);
|
|
}
|
|
|
|
static already_AddRefed<nsIURI>
|
|
GetWindowURI(nsIDOMWindow *aWindow)
|
|
{
|
|
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(aWindow);
|
|
NS_ENSURE_TRUE(pWindow, nullptr);
|
|
|
|
nsCOMPtr<nsIDocument> doc = pWindow->GetExtantDoc();
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (doc) {
|
|
uri = doc->GetDocumentURI();
|
|
}
|
|
|
|
if (!uri) {
|
|
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrincipal =
|
|
do_QueryInterface(aWindow);
|
|
NS_ENSURE_TRUE(scriptObjPrincipal, nullptr);
|
|
|
|
// GetPrincipal() will print a warning if the window does not have an outer
|
|
// window, so check here for an outer window first. This code is
|
|
// functionally correct if we leave out the GetOuterWindow() check, but we
|
|
// end up printing a lot of warnings during debug mochitests.
|
|
if (pWindow->GetOuterWindow()) {
|
|
nsIPrincipal* principal = scriptObjPrincipal->GetPrincipal();
|
|
if (principal) {
|
|
principal->GetURI(getter_AddRefs(uri));
|
|
}
|
|
}
|
|
}
|
|
|
|
return uri.forget();
|
|
}
|
|
|
|
static void
|
|
AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize)
|
|
{
|
|
nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
|
|
|
|
if (uri) {
|
|
if (aAnonymize && !aWindow->IsChromeWindow()) {
|
|
aStr.AppendPrintf("<anonymized-%d>", aWindow->WindowID());
|
|
} else {
|
|
nsCString spec;
|
|
uri->GetSpec(spec);
|
|
|
|
// A hack: replace forward slashes with '\\' so they aren't
|
|
// treated as path separators. Users of the reporters
|
|
// (such as about:memory) have to undo this change.
|
|
spec.ReplaceChar('/', '\\');
|
|
|
|
aStr += spec;
|
|
}
|
|
} else {
|
|
// If we're unable to find a URI, we're dealing with a chrome window with
|
|
// no document in it (or somesuch), so we call this a "system window".
|
|
aStr += NS_LITERAL_CSTRING("[system]");
|
|
}
|
|
}
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(WindowsMallocSizeOf)
|
|
|
|
// The key is the window ID.
|
|
typedef nsDataHashtable<nsUint64HashKey, nsCString> WindowPaths;
|
|
|
|
static nsresult
|
|
ReportAmount(const nsCString& aBasePath, const char* aPathTail,
|
|
size_t aAmount, const nsCString& aDescription,
|
|
uint32_t aKind, uint32_t aUnits,
|
|
nsIMemoryReporterCallback* aCb,
|
|
nsISupports* aClosure)
|
|
{
|
|
if (aAmount == 0) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsAutoCString path(aBasePath);
|
|
path += aPathTail;
|
|
|
|
return aCb->Callback(EmptyCString(), path, aKind, aUnits,
|
|
aAmount, aDescription, aClosure);
|
|
}
|
|
|
|
static nsresult
|
|
ReportSize(const nsCString& aBasePath, const char* aPathTail,
|
|
size_t aAmount, const nsCString& aDescription,
|
|
nsIMemoryReporterCallback* aCb,
|
|
nsISupports* aClosure)
|
|
{
|
|
return ReportAmount(aBasePath, aPathTail, aAmount, aDescription,
|
|
nsIMemoryReporter::KIND_HEAP,
|
|
nsIMemoryReporter::UNITS_BYTES, aCb, aClosure);
|
|
}
|
|
|
|
static nsresult
|
|
ReportCount(const nsCString& aBasePath, const char* aPathTail,
|
|
size_t aAmount, const nsCString& aDescription,
|
|
nsIMemoryReporterCallback* aCb,
|
|
nsISupports* aClosure)
|
|
{
|
|
return ReportAmount(aBasePath, aPathTail, aAmount, aDescription,
|
|
nsIMemoryReporter::KIND_OTHER,
|
|
nsIMemoryReporter::UNITS_COUNT, aCb, aClosure);
|
|
}
|
|
|
|
static nsresult
|
|
CollectWindowReports(nsGlobalWindow *aWindow,
|
|
amIAddonManager *addonManager,
|
|
nsWindowSizes *aWindowTotalSizes,
|
|
nsTHashtable<nsUint64HashKey> *aGhostWindowIDs,
|
|
WindowPaths *aWindowPaths,
|
|
WindowPaths *aTopWindowPaths,
|
|
nsIMemoryReporterCallback *aCb,
|
|
nsISupports *aClosure,
|
|
bool aAnonymize)
|
|
{
|
|
nsAutoCString windowPath("explicit/");
|
|
|
|
// 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;
|
|
nsCOMPtr<nsIURI> location;
|
|
if (aWindow->GetOuterWindow()) {
|
|
// Our window should have a null top iff it has a null docshell.
|
|
MOZ_ASSERT(!!aWindow->GetTopInternal() == !!aWindow->GetDocShell());
|
|
top = aWindow->GetTopInternal();
|
|
if (top) {
|
|
location = GetWindowURI(top);
|
|
}
|
|
}
|
|
if (!location) {
|
|
location = GetWindowURI(aWindow);
|
|
}
|
|
|
|
if (addonManager && location) {
|
|
bool ok;
|
|
nsAutoCString id;
|
|
if (NS_SUCCEEDED(addonManager->MapURIToAddonID(location, id, &ok)) && ok) {
|
|
// Add-on names are not privacy-sensitive, so we can use them with
|
|
// impunity.
|
|
windowPath += NS_LITERAL_CSTRING("add-ons/") + id +
|
|
NS_LITERAL_CSTRING("/");
|
|
}
|
|
}
|
|
|
|
windowPath += NS_LITERAL_CSTRING("window-objects/");
|
|
|
|
if (top) {
|
|
windowPath += NS_LITERAL_CSTRING("top(");
|
|
AppendWindowURI(top, windowPath, aAnonymize);
|
|
windowPath += NS_LITERAL_CSTRING(", id=");
|
|
windowPath.AppendInt(top->WindowID());
|
|
windowPath += NS_LITERAL_CSTRING(")");
|
|
|
|
aTopWindowPaths->Put(aWindow->WindowID(), windowPath);
|
|
|
|
windowPath += aWindow->IsFrozen() ? NS_LITERAL_CSTRING("/cached/")
|
|
: NS_LITERAL_CSTRING("/active/");
|
|
} else {
|
|
if (aGhostWindowIDs->Contains(aWindow->WindowID())) {
|
|
windowPath += NS_LITERAL_CSTRING("top(none)/ghost/");
|
|
} else {
|
|
windowPath += NS_LITERAL_CSTRING("top(none)/detached/");
|
|
}
|
|
}
|
|
|
|
windowPath += NS_LITERAL_CSTRING("window(");
|
|
AppendWindowURI(aWindow, windowPath, aAnonymize);
|
|
windowPath += NS_LITERAL_CSTRING(")");
|
|
|
|
// Use |windowPath|, but replace "explicit/" with "event-counts/".
|
|
nsCString censusWindowPath(windowPath);
|
|
censusWindowPath.Replace(0, strlen("explicit"), "event-counts");
|
|
|
|
// Remember the path for later.
|
|
aWindowPaths->Put(aWindow->WindowID(), windowPath);
|
|
|
|
#define REPORT_SIZE(_pathTail, _amount, _desc) \
|
|
do { \
|
|
nsresult rv = ReportSize(windowPath, _pathTail, _amount, \
|
|
NS_LITERAL_CSTRING(_desc), aCb, aClosure); \
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
} while (0)
|
|
|
|
#define REPORT_COUNT(_pathTail, _amount, _desc) \
|
|
do { \
|
|
nsresult rv = ReportCount(censusWindowPath, _pathTail, _amount, \
|
|
NS_LITERAL_CSTRING(_desc), aCb, aClosure); \
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
} while (0)
|
|
|
|
nsWindowSizes windowSizes(WindowsMallocSizeOf);
|
|
aWindow->AddSizeOfIncludingThis(&windowSizes);
|
|
|
|
REPORT_SIZE("/dom/element-nodes", windowSizes.mDOMElementNodesSize,
|
|
"Memory used by the element nodes in a window's DOM.");
|
|
aWindowTotalSizes->mDOMElementNodesSize += windowSizes.mDOMElementNodesSize;
|
|
|
|
REPORT_SIZE("/dom/text-nodes", windowSizes.mDOMTextNodesSize,
|
|
"Memory used by the text nodes in a window's DOM.");
|
|
aWindowTotalSizes->mDOMTextNodesSize += windowSizes.mDOMTextNodesSize;
|
|
|
|
REPORT_SIZE("/dom/cdata-nodes", windowSizes.mDOMCDATANodesSize,
|
|
"Memory used by the CDATA nodes in a window's DOM.");
|
|
aWindowTotalSizes->mDOMCDATANodesSize += windowSizes.mDOMCDATANodesSize;
|
|
|
|
REPORT_SIZE("/dom/comment-nodes", windowSizes.mDOMCommentNodesSize,
|
|
"Memory used by the comment nodes in a window's DOM.");
|
|
aWindowTotalSizes->mDOMCommentNodesSize += windowSizes.mDOMCommentNodesSize;
|
|
|
|
REPORT_SIZE("/dom/event-targets", windowSizes.mDOMEventTargetsSize,
|
|
"Memory used by the event targets table in a window's DOM, and "
|
|
"the objects it points to, which include XHRs.");
|
|
aWindowTotalSizes->mDOMEventTargetsSize += windowSizes.mDOMEventTargetsSize;
|
|
|
|
REPORT_COUNT("/dom/event-targets", windowSizes.mDOMEventTargetsCount,
|
|
"Number of non-node event targets in the event targets table "
|
|
"in a window's DOM, such as XHRs.");
|
|
aWindowTotalSizes->mDOMEventTargetsCount +=
|
|
windowSizes.mDOMEventTargetsCount;
|
|
|
|
REPORT_COUNT("/dom/event-listeners", windowSizes.mDOMEventListenersCount,
|
|
"Number of event listeners in a window, including event "
|
|
"listeners on nodes and other event targets.");
|
|
aWindowTotalSizes->mDOMEventListenersCount +=
|
|
windowSizes.mDOMEventListenersCount;
|
|
|
|
REPORT_SIZE("/dom/other", windowSizes.mDOMOtherSize,
|
|
"Memory used by a window's DOM that isn't measured by the "
|
|
"other 'dom/' numbers.");
|
|
aWindowTotalSizes->mDOMOtherSize += windowSizes.mDOMOtherSize;
|
|
|
|
REPORT_SIZE("/property-tables",
|
|
windowSizes.mPropertyTablesSize,
|
|
"Memory used for the property tables within a window.");
|
|
aWindowTotalSizes->mPropertyTablesSize += windowSizes.mPropertyTablesSize;
|
|
|
|
REPORT_SIZE("/style-sheets", windowSizes.mStyleSheetsSize,
|
|
"Memory used by style sheets within a window.");
|
|
aWindowTotalSizes->mStyleSheetsSize += windowSizes.mStyleSheetsSize;
|
|
|
|
REPORT_SIZE("/layout/pres-shell", windowSizes.mLayoutPresShellSize,
|
|
"Memory used by layout's PresShell, along with any structures "
|
|
"allocated in its arena and not measured elsewhere, "
|
|
"within a window.");
|
|
aWindowTotalSizes->mLayoutPresShellSize += windowSizes.mLayoutPresShellSize;
|
|
|
|
REPORT_SIZE("/layout/line-boxes", windowSizes.mArenaStats.mLineBoxes,
|
|
"Memory used by line boxes within a window.");
|
|
aWindowTotalSizes->mArenaStats.mLineBoxes
|
|
+= windowSizes.mArenaStats.mLineBoxes;
|
|
|
|
REPORT_SIZE("/layout/rule-nodes", windowSizes.mArenaStats.mRuleNodes,
|
|
"Memory used by CSS rule nodes within a window.");
|
|
aWindowTotalSizes->mArenaStats.mRuleNodes
|
|
+= windowSizes.mArenaStats.mRuleNodes;
|
|
|
|
REPORT_SIZE("/layout/style-contexts", windowSizes.mArenaStats.mStyleContexts,
|
|
"Memory used by style contexts within a window.");
|
|
aWindowTotalSizes->mArenaStats.mStyleContexts
|
|
+= windowSizes.mArenaStats.mStyleContexts;
|
|
|
|
REPORT_SIZE("/layout/style-structs", windowSizes.mArenaStats.mStyleStructs,
|
|
"Memory used by style structs within a window.");
|
|
aWindowTotalSizes->mArenaStats.mStyleStructs
|
|
+= windowSizes.mArenaStats.mStyleStructs;
|
|
|
|
REPORT_SIZE("/layout/style-sets", windowSizes.mLayoutStyleSetsSize,
|
|
"Memory used by style sets within a window.");
|
|
aWindowTotalSizes->mLayoutStyleSetsSize += windowSizes.mLayoutStyleSetsSize;
|
|
|
|
REPORT_SIZE("/layout/text-runs", windowSizes.mLayoutTextRunsSize,
|
|
"Memory used for text-runs (glyph layout) in the PresShell's "
|
|
"frame tree, within a window.");
|
|
aWindowTotalSizes->mLayoutTextRunsSize += windowSizes.mLayoutTextRunsSize;
|
|
|
|
REPORT_SIZE("/layout/pres-contexts", windowSizes.mLayoutPresContextSize,
|
|
"Memory used for the PresContext in the PresShell's frame "
|
|
"within a window.");
|
|
aWindowTotalSizes->mLayoutPresContextSize +=
|
|
windowSizes.mLayoutPresContextSize;
|
|
|
|
// There are many different kinds of frames, but it is very likely
|
|
// that only a few matter. Implement a cutoff so we don't bloat
|
|
// about:memory with many uninteresting entries.
|
|
const size_t FRAME_SUNDRIES_THRESHOLD =
|
|
js::MemoryReportingSundriesThreshold();
|
|
|
|
size_t frameSundriesSize = 0;
|
|
#define FRAME_ID(classname) \
|
|
{ \
|
|
size_t frameSize \
|
|
= windowSizes.mArenaStats.FRAME_ID_STAT_FIELD(classname); \
|
|
if (frameSize < FRAME_SUNDRIES_THRESHOLD) { \
|
|
frameSundriesSize += frameSize; \
|
|
} else { \
|
|
REPORT_SIZE("/layout/frames/" # classname, frameSize, \
|
|
"Memory used by frames of " \
|
|
"type " #classname " within a window."); \
|
|
} \
|
|
aWindowTotalSizes->mArenaStats.FRAME_ID_STAT_FIELD(classname) \
|
|
+= frameSize; \
|
|
}
|
|
#include "nsFrameIdList.h"
|
|
#undef FRAME_ID
|
|
|
|
if (frameSundriesSize > 0) {
|
|
REPORT_SIZE("/layout/frames/sundries", frameSundriesSize,
|
|
"The sum of all memory used by frames which were too small "
|
|
"to be shown individually.");
|
|
}
|
|
|
|
#undef REPORT_SIZE
|
|
#undef REPORT_COUNT
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
typedef nsTArray< RefPtr<nsGlobalWindow> > WindowArray;
|
|
|
|
static
|
|
PLDHashOperator
|
|
GetWindows(const uint64_t& aId, nsGlobalWindow*& aWindow, void* aClosure)
|
|
{
|
|
((WindowArray *)aClosure)->AppendElement(aWindow);
|
|
|
|
return PL_DHASH_NEXT;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsWindowMemoryReporter::CollectReports(nsIMemoryReporterCallback* aCb,
|
|
nsISupports* aClosure, bool aAnonymize)
|
|
{
|
|
nsGlobalWindow::WindowByIdTable* windowsById =
|
|
nsGlobalWindow::GetWindowsTable();
|
|
NS_ENSURE_TRUE(windowsById, NS_OK);
|
|
|
|
// Hold on to every window in memory so that window objects can't be
|
|
// destroyed while we're calling the memory reporter callback.
|
|
WindowArray windows;
|
|
windowsById->Enumerate(GetWindows, &windows);
|
|
|
|
// Get the IDs of all the "ghost" windows, and call aCb->Callback() for each
|
|
// one.
|
|
nsTHashtable<nsUint64HashKey> ghostWindows;
|
|
CheckForGhostWindows(&ghostWindows);
|
|
nsresult rv = NS_OK;
|
|
for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) {
|
|
nsGlobalWindow::WindowByIdTable* windowsById =
|
|
nsGlobalWindow::GetWindowsTable();
|
|
if (!windowsById) {
|
|
NS_WARNING("Couldn't get window-by-id hashtable?");
|
|
continue;
|
|
}
|
|
|
|
nsGlobalWindow* window = windowsById->Get(iter.Get()->GetKey());
|
|
if (!window) {
|
|
NS_WARNING("Could not look up window?");
|
|
continue;
|
|
}
|
|
|
|
nsAutoCString path;
|
|
path.AppendLiteral("ghost-windows/");
|
|
AppendWindowURI(window, path, aAnonymize);
|
|
|
|
nsresult callbackRv = aCb->Callback(
|
|
/* process = */ EmptyCString(),
|
|
path,
|
|
nsIMemoryReporter::KIND_OTHER,
|
|
nsIMemoryReporter::UNITS_COUNT,
|
|
/* amount = */ 1,
|
|
/* description = */ NS_LITERAL_CSTRING("A ghost window."),
|
|
aClosure);
|
|
if (NS_FAILED(callbackRv) && NS_SUCCEEDED(rv)) {
|
|
rv = callbackRv;
|
|
}
|
|
}
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
WindowPaths windowPaths;
|
|
WindowPaths topWindowPaths;
|
|
|
|
// Collect window memory usage.
|
|
nsWindowSizes windowTotalSizes(nullptr);
|
|
nsCOMPtr<amIAddonManager> addonManager;
|
|
if (XRE_IsParentProcess()) {
|
|
// Only try to access the service from the main process.
|
|
addonManager = do_GetService("@mozilla.org/addons/integration;1");
|
|
}
|
|
for (uint32_t i = 0; i < windows.Length(); i++) {
|
|
rv = CollectWindowReports(windows[i], addonManager,
|
|
&windowTotalSizes, &ghostWindows,
|
|
&windowPaths, &topWindowPaths, aCb,
|
|
aClosure, aAnonymize);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
}
|
|
|
|
// Report JS memory usage. We do this from here because the JS memory
|
|
// reporter needs to be passed |windowPaths|.
|
|
rv = xpc::JSReporter::CollectReports(&windowPaths, &topWindowPaths,
|
|
aCb, aClosure, aAnonymize);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
do { \
|
|
nsresult rv; \
|
|
rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
|
|
KIND_OTHER, UNITS_BYTES, _amount, \
|
|
NS_LITERAL_CSTRING(_desc), aClosure); \
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
} while (0)
|
|
|
|
REPORT("window-objects/dom/element-nodes", windowTotalSizes.mDOMElementNodesSize,
|
|
"This is the sum of all windows' 'dom/element-nodes' numbers.");
|
|
|
|
REPORT("window-objects/dom/text-nodes", windowTotalSizes.mDOMTextNodesSize,
|
|
"This is the sum of all windows' 'dom/text-nodes' numbers.");
|
|
|
|
REPORT("window-objects/dom/cdata-nodes", windowTotalSizes.mDOMCDATANodesSize,
|
|
"This is the sum of all windows' 'dom/cdata-nodes' numbers.");
|
|
|
|
REPORT("window-objects/dom/comment-nodes", windowTotalSizes.mDOMCommentNodesSize,
|
|
"This is the sum of all windows' 'dom/comment-nodes' numbers.");
|
|
|
|
REPORT("window-objects/dom/event-targets", windowTotalSizes.mDOMEventTargetsSize,
|
|
"This is the sum of all windows' 'dom/event-targets' numbers.");
|
|
|
|
REPORT("window-objects/dom/other", windowTotalSizes.mDOMOtherSize,
|
|
"This is the sum of all windows' 'dom/other' numbers.");
|
|
|
|
REPORT("window-objects/property-tables",
|
|
windowTotalSizes.mPropertyTablesSize,
|
|
"This is the sum of all windows' 'property-tables' numbers.");
|
|
|
|
REPORT("window-objects/style-sheets", windowTotalSizes.mStyleSheetsSize,
|
|
"This is the sum of all windows' 'style-sheets' numbers.");
|
|
|
|
REPORT("window-objects/layout/pres-shell", windowTotalSizes.mLayoutPresShellSize,
|
|
"This is the sum of all windows' 'layout/arenas' numbers.");
|
|
|
|
REPORT("window-objects/layout/line-boxes",
|
|
windowTotalSizes.mArenaStats.mLineBoxes,
|
|
"This is the sum of all windows' 'layout/line-boxes' numbers.");
|
|
|
|
REPORT("window-objects/layout/rule-nodes",
|
|
windowTotalSizes.mArenaStats.mRuleNodes,
|
|
"This is the sum of all windows' 'layout/rule-nodes' numbers.");
|
|
|
|
REPORT("window-objects/layout/style-contexts",
|
|
windowTotalSizes.mArenaStats.mStyleContexts,
|
|
"This is the sum of all windows' 'layout/style-contexts' numbers.");
|
|
|
|
REPORT("window-objects/layout/style-structs",
|
|
windowTotalSizes.mArenaStats.mStyleStructs,
|
|
"This is the sum of all windows' 'layout/style-structs' numbers.");
|
|
|
|
REPORT("window-objects/layout/style-sets", windowTotalSizes.mLayoutStyleSetsSize,
|
|
"This is the sum of all windows' 'layout/style-sets' numbers.");
|
|
|
|
REPORT("window-objects/layout/text-runs", windowTotalSizes.mLayoutTextRunsSize,
|
|
"This is the sum of all windows' 'layout/text-runs' numbers.");
|
|
|
|
REPORT("window-objects/layout/pres-contexts", windowTotalSizes.mLayoutPresContextSize,
|
|
"This is the sum of all windows' 'layout/pres-contexts' numbers.");
|
|
|
|
size_t frameTotal = 0;
|
|
#define FRAME_ID(classname) \
|
|
frameTotal += windowTotalSizes.mArenaStats.FRAME_ID_STAT_FIELD(classname);
|
|
#include "nsFrameIdList.h"
|
|
#undef FRAME_ID
|
|
|
|
REPORT("window-objects/layout/frames", frameTotal,
|
|
"Memory used for layout frames within windows. "
|
|
"This is the sum of all windows' 'layout/frames/' numbers.");
|
|
|
|
#undef REPORT
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
uint32_t
|
|
nsWindowMemoryReporter::GetGhostTimeout()
|
|
{
|
|
return Preferences::GetUint("memory.ghost_window_timeout_seconds", 60);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic,
|
|
const char16_t *aData)
|
|
{
|
|
if (!strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC)) {
|
|
ObserveDOMWindowDetached(aSubject);
|
|
} else if (!strcmp(aTopic, "after-minimize-memory-usage")) {
|
|
ObserveAfterMinimizeMemoryUsage();
|
|
} else if (!strcmp(aTopic, "cycle-collector-begin")) {
|
|
if (mCheckTimer) {
|
|
mCheckTimerWaitingForCCEnd = true;
|
|
KillCheckTimer();
|
|
}
|
|
mCycleCollectorIsRunning = true;
|
|
} else if (!strcmp(aTopic, "cycle-collector-end")) {
|
|
mCycleCollectorIsRunning = false;
|
|
if (mCheckTimerWaitingForCCEnd) {
|
|
mCheckTimerWaitingForCCEnd = false;
|
|
AsyncCheckForGhostWindows();
|
|
}
|
|
} else {
|
|
MOZ_ASSERT(false);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsWindowMemoryReporter::ObserveDOMWindowDetached(nsISupports* aWindow)
|
|
{
|
|
nsWeakPtr weakWindow = do_GetWeakReference(aWindow);
|
|
if (!weakWindow) {
|
|
NS_WARNING("Couldn't take weak reference to a window?");
|
|
return;
|
|
}
|
|
|
|
mDetachedWindows.Put(weakWindow, TimeStamp());
|
|
|
|
AsyncCheckForGhostWindows();
|
|
}
|
|
|
|
// static
|
|
void
|
|
nsWindowMemoryReporter::CheckTimerFired(nsITimer* aTimer, void* aClosure)
|
|
{
|
|
if (sWindowReporter) {
|
|
MOZ_ASSERT(!sWindowReporter->mCycleCollectorIsRunning);
|
|
sWindowReporter->CheckForGhostWindows();
|
|
}
|
|
}
|
|
|
|
void
|
|
nsWindowMemoryReporter::AsyncCheckForGhostWindows()
|
|
{
|
|
if (mCheckTimer) {
|
|
return;
|
|
}
|
|
|
|
if (mCycleCollectorIsRunning) {
|
|
mCheckTimerWaitingForCCEnd = true;
|
|
return;
|
|
}
|
|
|
|
// If more than kTimeBetweenChecks seconds have elapsed since the last check,
|
|
// timerDelay is 0. Otherwise, it is kTimeBetweenChecks, reduced by the time
|
|
// since the last check. Reducing the delay by the time since the last check
|
|
// prevents the timer from being completely starved if it is repeatedly killed
|
|
// and restarted.
|
|
int32_t timeSinceLastCheck = (TimeStamp::NowLoRes() - mLastCheckForGhostWindows).ToSeconds();
|
|
int32_t timerDelay = (kTimeBetweenChecks - std::min(timeSinceLastCheck, kTimeBetweenChecks)) * PR_MSEC_PER_SEC;
|
|
|
|
mCheckTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (mCheckTimer) {
|
|
mCheckTimer->InitWithFuncCallback(CheckTimerFired, nullptr,
|
|
timerDelay, nsITimer::TYPE_ONE_SHOT);
|
|
}
|
|
}
|
|
|
|
static PLDHashOperator
|
|
BackdateTimeStampsEnumerator(nsISupports *aKey, TimeStamp &aTimeStamp,
|
|
void* aClosure)
|
|
{
|
|
TimeStamp *minTimeStamp = static_cast<TimeStamp*>(aClosure);
|
|
|
|
if (!aTimeStamp.IsNull() && aTimeStamp > *minTimeStamp) {
|
|
aTimeStamp = *minTimeStamp;
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
}
|
|
|
|
void
|
|
nsWindowMemoryReporter::ObserveAfterMinimizeMemoryUsage()
|
|
{
|
|
// Someone claims they've done enough GC/CCs so that all eligible windows
|
|
// have been free'd. So we deem that any windows which satisfy ghost
|
|
// criteria (1) and (2) now satisfy criterion (3) as well.
|
|
//
|
|
// To effect this change, we'll backdate some of our timestamps.
|
|
|
|
TimeStamp minTimeStamp = TimeStamp::Now() -
|
|
TimeDuration::FromSeconds(GetGhostTimeout());
|
|
|
|
mDetachedWindows.Enumerate(BackdateTimeStampsEnumerator,
|
|
&minTimeStamp);
|
|
}
|
|
|
|
struct CheckForGhostWindowsEnumeratorData
|
|
{
|
|
nsTHashtable<nsCStringHashKey> *nonDetachedDomains;
|
|
nsTHashtable<nsUint64HashKey> *ghostWindowIDs;
|
|
nsIEffectiveTLDService *tldService;
|
|
uint32_t ghostTimeout;
|
|
TimeStamp now;
|
|
};
|
|
|
|
static PLDHashOperator
|
|
CheckForGhostWindowsEnumerator(nsISupports *aKey, TimeStamp& aTimeStamp,
|
|
void* aClosure)
|
|
{
|
|
CheckForGhostWindowsEnumeratorData *data =
|
|
static_cast<CheckForGhostWindowsEnumeratorData*>(aClosure);
|
|
|
|
nsWeakPtr weakKey = do_QueryInterface(aKey);
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(weakKey);
|
|
if (!window) {
|
|
// The window object has been destroyed. Stop tracking its weak ref in our
|
|
// hashtable.
|
|
return PL_DHASH_REMOVE;
|
|
}
|
|
|
|
// Avoid calling GetTop() if we have no outer window. Nothing will break if
|
|
// we do, but it will spew debug output, which can cause our test logs to
|
|
// overflow.
|
|
nsCOMPtr<nsIDOMWindow> top;
|
|
if (window->GetOuterWindow()) {
|
|
top = window->GetOuterWindow()->GetTop();
|
|
}
|
|
|
|
if (top) {
|
|
// The window is no longer detached, so we no longer want to track it.
|
|
return PL_DHASH_REMOVE;
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri = GetWindowURI(window);
|
|
|
|
nsAutoCString domain;
|
|
if (uri) {
|
|
// GetBaseDomain works fine if |uri| is null, but it outputs a warning
|
|
// which ends up overrunning the mochitest logs.
|
|
data->tldService->GetBaseDomain(uri, 0, domain);
|
|
}
|
|
|
|
if (data->nonDetachedDomains->Contains(domain)) {
|
|
// This window shares a domain with a non-detached window, so reset its
|
|
// clock.
|
|
aTimeStamp = TimeStamp();
|
|
} else {
|
|
// This window does not share a domain with a non-detached window, so it
|
|
// meets ghost criterion (2).
|
|
if (aTimeStamp.IsNull()) {
|
|
// This may become a ghost window later; start its clock.
|
|
aTimeStamp = data->now;
|
|
} else if ((data->now - aTimeStamp).ToSeconds() > data->ghostTimeout) {
|
|
// This definitely is a ghost window, so add it to ghostWindowIDs, if
|
|
// that is not null.
|
|
if (data->ghostWindowIDs) {
|
|
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(window);
|
|
if (pWindow) {
|
|
data->ghostWindowIDs->PutEntry(pWindow->WindowID());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
}
|
|
|
|
/**
|
|
* Iterate over mDetachedWindows and update it to reflect the current state of
|
|
* the world. In particular:
|
|
*
|
|
* - Remove weak refs to windows which no longer exist.
|
|
*
|
|
* - Remove references to windows which are no longer detached.
|
|
*
|
|
* - Reset the timestamp on detached windows which share a domain with a
|
|
* non-detached window (they no longer meet ghost criterion (2)).
|
|
*
|
|
* - If a window now meets ghost criterion (2) but didn't before, set its
|
|
* timestamp to now.
|
|
*
|
|
* Additionally, if aOutGhostIDs is not null, fill it with the window IDs of
|
|
* all ghost windows we found.
|
|
*/
|
|
void
|
|
nsWindowMemoryReporter::CheckForGhostWindows(
|
|
nsTHashtable<nsUint64HashKey> *aOutGhostIDs /* = nullptr */)
|
|
{
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService = do_GetService(
|
|
NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
if (!tldService) {
|
|
NS_WARNING("Couldn't get TLDService.");
|
|
return;
|
|
}
|
|
|
|
nsGlobalWindow::WindowByIdTable *windowsById =
|
|
nsGlobalWindow::GetWindowsTable();
|
|
if (!windowsById) {
|
|
NS_WARNING("GetWindowsTable returned null");
|
|
return;
|
|
}
|
|
|
|
mLastCheckForGhostWindows = TimeStamp::NowLoRes();
|
|
KillCheckTimer();
|
|
|
|
nsTHashtable<nsCStringHashKey> nonDetachedWindowDomains;
|
|
|
|
// Populate nonDetachedWindowDomains.
|
|
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();
|
|
if (!window->GetOuterWindow() || !window->GetTopInternal()) {
|
|
// This window is detached, so we don't care about its domain.
|
|
continue;
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri = GetWindowURI(window);
|
|
nsAutoCString domain;
|
|
if (uri) {
|
|
tldService->GetBaseDomain(uri, 0, domain);
|
|
}
|
|
nonDetachedWindowDomains.PutEntry(domain);
|
|
}
|
|
|
|
// Update mDetachedWindows and write the ghost window IDs into aOutGhostIDs,
|
|
// if it's not null.
|
|
CheckForGhostWindowsEnumeratorData ghostEnumData =
|
|
{ &nonDetachedWindowDomains, aOutGhostIDs, tldService,
|
|
GetGhostTimeout(), mLastCheckForGhostWindows };
|
|
mDetachedWindows.Enumerate(CheckForGhostWindowsEnumerator,
|
|
&ghostEnumData);
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(nsWindowMemoryReporter::GhostWindowsReporter,
|
|
nsIMemoryReporter)
|
|
|
|
/* static */ int64_t
|
|
nsWindowMemoryReporter::GhostWindowsReporter::DistinguishedAmount()
|
|
{
|
|
nsTHashtable<nsUint64HashKey> ghostWindows;
|
|
sWindowReporter->CheckForGhostWindows(&ghostWindows);
|
|
return ghostWindows.Count();
|
|
}
|
|
|
|
void
|
|
nsWindowMemoryReporter::KillCheckTimer()
|
|
{
|
|
if (mCheckTimer) {
|
|
mCheckTimer->Cancel();
|
|
mCheckTimer = nullptr;
|
|
}
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
/* static */ void
|
|
nsWindowMemoryReporter::UnlinkGhostWindows()
|
|
{
|
|
if (!sWindowReporter) {
|
|
return;
|
|
}
|
|
|
|
nsGlobalWindow::WindowByIdTable* windowsById =
|
|
nsGlobalWindow::GetWindowsTable();
|
|
if (!windowsById) {
|
|
return;
|
|
}
|
|
|
|
// Hold on to every window in memory so that window objects can't be
|
|
// destroyed while we're calling the UnlinkGhostWindows callback.
|
|
WindowArray windows;
|
|
windowsById->Enumerate(GetWindows, &windows);
|
|
|
|
// Get the IDs of all the "ghost" windows, and unlink them all.
|
|
nsTHashtable<nsUint64HashKey> ghostWindows;
|
|
sWindowReporter->CheckForGhostWindows(&ghostWindows);
|
|
for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) {
|
|
nsGlobalWindow::WindowByIdTable* windowsById =
|
|
nsGlobalWindow::GetWindowsTable();
|
|
if (!windowsById) {
|
|
continue;
|
|
}
|
|
|
|
RefPtr<nsGlobalWindow> window = windowsById->Get(iter.Get()->GetKey());
|
|
if (window) {
|
|
window->RiskyUnlink();
|
|
}
|
|
}
|
|
}
|
|
#endif
|