author | Nicholas Nethercote <nnethercote@mozilla.com> |
Thu, 17 Jan 2013 21:21:43 -0800 | |
changeset 119237 | de2ab911692d91f6ea017d1d0f9d0a6d295ce6b5 |
parent 119236 | b924819d71a5e1e30d00cd36820440562ce48a3d |
child 119238 | e7b94c8df70c6ee84fce581803644c021f0dccd5 |
push id | 24195 |
push user | Ms2ger@gmail.com |
push date | Sat, 19 Jan 2013 16:10:11 +0000 |
treeherder | mozilla-central@02e12a80aef9 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bz |
bugs | 826521 |
milestone | 21.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -1,10 +1,10 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 sw=2 et tw=80: */ +/* -*- 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 "mozilla/Util.h" #include "nsXMLHttpRequest.h" #include "nsISimpleEnumerator.h" @@ -633,30 +633,58 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_ NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) NS_INTERFACE_MAP_ENTRY(nsIStreamListener) NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink) NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) NS_INTERFACE_MAP_ENTRY(nsITimerCallback) + NS_INTERFACE_MAP_ENTRY(nsISizeOfEventTarget) NS_INTERFACE_MAP_END_INHERITING(nsXHREventTarget) NS_IMPL_ADDREF_INHERITED(nsXMLHttpRequest, nsXHREventTarget) NS_IMPL_RELEASE_INHERITED(nsXMLHttpRequest, nsXHREventTarget) NS_IMPL_EVENT_HANDLER(nsXMLHttpRequest, readystatechange) void nsXMLHttpRequest::DisconnectFromOwner() { nsXHREventTarget::DisconnectFromOwner(); Abort(); } +size_t +nsXMLHttpRequest::SizeOfEventTargetIncludingThis( + nsMallocSizeOfFun aMallocSizeOf) const +{ + size_t n = aMallocSizeOf(this); + n += mResponseBody.SizeOfExcludingThisIfUnshared(aMallocSizeOf); + + // Why is this safe? Because no-one else will report this string. The + // other possible sharers of this string are as follows. + // + // - The JS engine could hold copies if the JS code holds references, e.g. + // |var text = XHR.responseText|. However, those references will be via JS + // external strings, for which the JS memory reporter does *not* report the + // chars. + // + // - Binary extensions, but they're *extremely* unlikely to do any memory + // reporting. + // + n += mResponseText.SizeOfExcludingThisEvenIfShared(aMallocSizeOf); + + return n; + + // Measurement of the following members may be added later if DMD finds it is + // worthwhile: + // - lots +} + /* readonly attribute nsIChannel channel; */ NS_IMETHODIMP nsXMLHttpRequest::GetChannel(nsIChannel **aChannel) { NS_ENSURE_ARG_POINTER(aChannel); NS_IF_ADDREF(*aChannel = mChannel); return NS_OK;
--- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -1,9 +1,10 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- 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/. */ #ifndef nsXMLHttpRequest_h__ #define nsXMLHttpRequest_h__ #include "nsIXMLHttpRequest.h" @@ -30,16 +31,17 @@ #include "nsITimer.h" #include "nsIDOMProgressEvent.h" #include "nsDOMEventTargetHelper.h" #include "nsContentUtils.h" #include "nsDOMFile.h" #include "nsDOMBlobBuilder.h" #include "nsIPrincipal.h" #include "nsIScriptObjectPrincipal.h" +#include "nsISizeOfEventTarget.h" #include "mozilla/Assertions.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/TypedArray.h" #include "mozilla/dom/XMLHttpRequestBinding.h" #include "mozilla/dom/XMLHttpRequestUploadBinding.h" #include "mozilla/dom/EventHandlerBinding.h" @@ -119,17 +121,18 @@ class nsXMLHttpRequest : public nsXHREve public nsIXMLHttpRequest, public nsIJSXMLHttpRequest, public nsIStreamListener, public nsIChannelEventSink, public nsIProgressEventSink, public nsIInterfaceRequestor, public nsSupportsWeakReference, public nsIJSNativeInitializer, - public nsITimerCallback + public nsITimerCallback, + public nsISizeOfEventTarget { friend class nsXHRParseEndListener; friend class nsXMLHttpRequestXPCOMifier; public: nsXMLHttpRequest(); virtual ~nsXMLHttpRequest(); @@ -224,16 +227,20 @@ public: // nsITimerCallback NS_DECL_NSITIMERCALLBACK // nsIJSNativeInitializer NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj, uint32_t argc, jsval* argv); + // nsISizeOfEventTarget + virtual size_t + SizeOfEventTargetIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const; + NS_FORWARD_NSIDOMEVENTTARGET(nsXHREventTarget::) #ifdef DEBUG void StaticAssertions(); #endif // event handler IMPL_EVENT_HANDLER(readystatechange) @@ -486,16 +493,17 @@ public: void SetRequestObserver(nsIRequestObserver* aObserver); NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(nsXMLHttpRequest, nsXHREventTarget) bool AllowUploadProgress(); void RootJSResultObjects(); virtual void DisconnectFromOwner(); + protected: friend class nsMultipartProxyListener; nsresult DetectCharset(); nsresult AppendToResponseText(const char * aBuffer, uint32_t aBufferLen); static NS_METHOD StreamReaderFunc(nsIInputStream* in, void* closure, const char* fromRawSegment, @@ -568,17 +576,17 @@ protected: nsCString mResponseBody; // The text version of our response body. This is incrementally decoded into // as we receive network data. However for the DEFAULT responseType we // lazily decode into this from mResponseBody only when .responseText is // accessed. // Only used for DEFAULT and TEXT responseTypes. nsString mResponseText; - + // For DEFAULT responseType we use this to keep track of how far we've // lazily decoded from mResponseBody to mResponseText uint32_t mResponseBodyDecodedPos; // Decoder used for decoding into mResponseText // Only used for DEFAULT, TEXT and JSON responseTypes. // In cases where we've only received half a surrogate, the decoder itself // carries the state to remember this. Next time we receive more data we
--- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1,10 +1,10 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=2 et tw=78: */ +/* -*- 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 "base/basictypes.h" #include <algorithm> /* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */ @@ -18,16 +18,17 @@ #include "nsPerformance.h" #include "nsDOMNavigationTiming.h" #include "nsBarProps.h" #include "nsDOMStorage.h" #include "nsDOMOfflineResourceList.h" #include "nsError.h" #include "nsIIdleService.h" #include "nsIPowerManagerService.h" +#include "nsISizeOfEventTarget.h" #ifdef XP_WIN #ifdef GetClassName #undef GetClassName #endif // GetClassName #endif // XP_WIN // Helper Classes @@ -11058,16 +11059,27 @@ nsGlobalWindow::HasIndexedDBSupport() // static bool nsPIDOMWindow::HasPerformanceSupport() { return Preferences::GetBool("dom.enable_performance", false); } +static size_t +SizeOfEventTargetObjectsEntryExcludingThisFun( + nsPtrHashKey<nsDOMEventTargetHelper> *aEntry, + nsMallocSizeOfFun aMallocSizeOf, + void *arg) +{ + nsISupports *supports = aEntry->GetKey(); + nsCOMPtr<nsISizeOfEventTarget> iface = do_QueryInterface(supports); + return iface ? iface->SizeOfEventTargetIncludingThis(aMallocSizeOf) : 0; +} + void nsGlobalWindow::SizeOfIncludingThis(nsWindowSizes* aWindowSizes) const { aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this); if (IsInnerWindow()) { nsEventListenerManager* elm = const_cast<nsGlobalWindow*>(this)->GetListenerManager(false); @@ -11078,16 +11090,21 @@ nsGlobalWindow::SizeOfIncludingThis(nsWi if (mDoc) { mDoc->DocSizeOfIncludingThis(aWindowSizes); } } aWindowSizes->mDOMOther += mNavigator ? mNavigator->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf) : 0; + + aWindowSizes->mDOMEventTargets += + mEventTargetObjects.SizeOfExcludingThis( + SizeOfEventTargetObjectsEntryExcludingThisFun, + aWindowSizes->mMallocSizeOf); } // nsGlobalChromeWindow implementation NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalChromeWindow, nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserDOMWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
new file mode 100644 --- /dev/null +++ b/dom/base/nsISizeOfEventTarget.h @@ -0,0 +1,39 @@ +/* -*- 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/. */ + +#ifndef nsISizeOfEventTarget_h___ +#define nsISizeOfEventTarget_h___ + +#include "nsISupports.h" + +#define NS_ISIZEOFEVENTTARGET_IID \ + {0xa1e08cb9, 0x5455, 0x4593, \ + { 0xb4, 0x1f, 0x38, 0x7a, 0x85, 0x44, 0xd0, 0xb5 }} + +/** + * This class is much the same as nsISizeOf, but is specifically for measuring + * the contents of nsGlobalWindow::mEventTargetObjects. + * + * We don't use nsISizeOf because if we did, any object belonging to + * mEventTargetObjects that implements nsISizeOf would be measured, which we + * may not want (perhaps because the object is also measured elsewhere). + */ +class nsISizeOfEventTarget : public nsISupports +{ +public: + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISIZEOFEVENTTARGET_IID) + + /** + * Measures the size of the things pointed to by the object, plus the object + * itself. + */ + virtual size_t + SizeOfEventTargetIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0; +}; + +NS_DEFINE_STATIC_IID_ACCESSOR(nsISizeOfEventTarget, NS_ISIZEOFEVENTTARGET_IID) + +#endif /* nsISizeOfEventTarget_h___ */
--- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -1,9 +1,10 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- 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 "nsWindowMemoryReporter.h" #include "nsGlobalWindow.h" #include "nsIEffectiveTLDService.h" #include "mozilla/Services.h" @@ -164,37 +165,42 @@ CollectWindowReports(nsGlobalWindow *aWi NS_LITERAL_CSTRING(_desc), aClosure); \ NS_ENSURE_SUCCESS(rv, rv); \ } \ } while (0) nsWindowSizes windowSizes(WindowsMallocSizeOf); aWindow->SizeOfIncludingThis(&windowSizes); - REPORT("/dom/other", windowSizes.mDOMOther, - "Memory used by a window's DOM, excluding element, text, CDATA, " - "and comment nodes."); - aWindowTotalSizes->mDOMOther += windowSizes.mDOMOther; - REPORT("/dom/element-nodes", windowSizes.mDOMElementNodes, "Memory used by the element nodes in a window's DOM."); aWindowTotalSizes->mDOMElementNodes += windowSizes.mDOMElementNodes; REPORT("/dom/text-nodes", windowSizes.mDOMTextNodes, "Memory used by the text nodes in a window's DOM."); aWindowTotalSizes->mDOMTextNodes += windowSizes.mDOMTextNodes; REPORT("/dom/cdata-nodes", windowSizes.mDOMCDATANodes, "Memory used by the CDATA nodes in a window's DOM."); aWindowTotalSizes->mDOMCDATANodes += windowSizes.mDOMCDATANodes; REPORT("/dom/comment-nodes", windowSizes.mDOMCommentNodes, "Memory used by the comment nodes in a window's DOM."); aWindowTotalSizes->mDOMCommentNodes += windowSizes.mDOMCommentNodes; + REPORT("/dom/event-targets", windowSizes.mDOMEventTargets, + "Memory used by the event targets table in a window's DOM, and the " + "objects it points to, which include XHRs."); + aWindowTotalSizes->mDOMEventTargets += windowSizes.mDOMEventTargets; + + REPORT("/dom/other", windowSizes.mDOMOther, + "Memory used by a window's DOM that isn't measured by the other " + "'dom/' numbers."); + aWindowTotalSizes->mDOMOther += windowSizes.mDOMOther; + REPORT("/property-tables", windowSizes.mPropertyTables, "Memory used for the property tables within a window."); aWindowTotalSizes->mPropertyTables += windowSizes.mPropertyTables; REPORT("/style-sheets", windowSizes.mStyleSheets, "Memory used by style sheets within a window."); aWindowTotalSizes->mStyleSheets += windowSizes.mStyleSheets; @@ -258,17 +264,17 @@ CollectWindowReports(nsGlobalWindow *aWi #include "nsFrameIdList.h" #undef FRAME_ID if (frameSundriesSize > 0) { REPORT("/layout/frames/sundries", frameSundriesSize, "The sum of all memory used by frames which were too small " "to be shown individually."); } - + #undef REPORT return NS_OK; } typedef nsTArray< nsRefPtr<nsGlobalWindow> > WindowArray; static @@ -327,90 +333,77 @@ nsWindowMemoryReporter::CollectReports(n nsresult rv; \ rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \ nsIMemoryReporter::KIND_OTHER, \ nsIMemoryReporter::UNITS_BYTES, _amount, \ NS_LITERAL_CSTRING(_desc), aClosure); \ NS_ENSURE_SUCCESS(rv, rv); \ } while (0) - REPORT("window-objects/dom/other", windowTotalSizes.mDOMOther, - "Memory used for the DOM within windows, " - "excluding element, text, CDATA, and comment nodes. " - "This is the sum of all windows' 'dom/other' numbers."); - REPORT("window-objects/dom/element-nodes", windowTotalSizes.mDOMElementNodes, - "Memory used for DOM element nodes within windows. " "This is the sum of all windows' 'dom/element-nodes' numbers."); REPORT("window-objects/dom/text-nodes", windowTotalSizes.mDOMTextNodes, - "Memory used for DOM text nodes within windows. " "This is the sum of all windows' 'dom/text-nodes' numbers."); REPORT("window-objects/dom/cdata-nodes", windowTotalSizes.mDOMCDATANodes, - "Memory used for DOM CDATA nodes within windows. " "This is the sum of all windows' 'dom/cdata-nodes' numbers."); REPORT("window-objects/dom/comment-nodes", windowTotalSizes.mDOMCommentNodes, - "Memory used for DOM comment nodes within windows. " "This is the sum of all windows' 'dom/comment-nodes' numbers."); + REPORT("window-objects/dom/event-targets", windowTotalSizes.mDOMEventTargets, + "This is the sum of all windows' 'dom/event-targets' numbers."); + + REPORT("window-objects/dom/other", windowTotalSizes.mDOMOther, + "This is the sum of all windows' 'dom/other' numbers."); + REPORT("window-objects/property-tables", windowTotalSizes.mPropertyTables, - "Memory used for property tables within windows. " "This is the sum of all windows' 'property-tables' numbers."); - REPORT("window-objects/style-sheets", windowTotalSizes.mStyleSheets, - "Memory used for style sheets within windows. " + REPORT("window-objects/style-sheets", windowTotalSizes.mStyleSheets, "This is the sum of all windows' 'style-sheets' numbers."); - - REPORT("window-objects/layout/pres-shell", windowTotalSizes.mLayoutPresShell, - "Memory used by layout PresShell and other related " - "areas within windows. This is the sum of all windows' " - "'layout/arenas' numbers."); - + + REPORT("window-objects/layout/pres-shell", windowTotalSizes.mLayoutPresShell, + "This is the sum of all windows' 'layout/arenas' numbers."); + REPORT("window-objects/layout/line-boxes", - windowTotalSizes.mArenaStats.mLineBoxes, - "Memory used for line-boxes within windows. " + windowTotalSizes.mArenaStats.mLineBoxes, "This is the sum of all windows' 'layout/line-boxes' numbers."); REPORT("window-objects/layout/rule-nodes", windowTotalSizes.mArenaStats.mRuleNodes, - "Memory used for CSS rule nodes within windows. " "This is the sum of all windows' 'layout/rule-nodes' numbers."); REPORT("window-objects/layout/style-contexts", windowTotalSizes.mArenaStats.mStyleContexts, - "Memory used for style contexts within windows. " "This is the sum of all windows' 'layout/style-contexts' numbers."); - REPORT("window-objects/layout/style-sets", windowTotalSizes.mLayoutStyleSets, - "Memory used for style sets within windows. " + REPORT("window-objects/layout/style-sets", windowTotalSizes.mLayoutStyleSets, "This is the sum of all windows' 'layout/style-sets' numbers."); - - REPORT("window-objects/layout/text-runs", windowTotalSizes.mLayoutTextRuns, - "Memory used for text runs within windows. " + + REPORT("window-objects/layout/text-runs", windowTotalSizes.mLayoutTextRuns, "This is the sum of all windows' 'layout/text-runs' numbers."); REPORT("window-objects/layout/pres-contexts", windowTotalSizes.mLayoutPresContext, - "Memory used for layout PresContexts within windows. " "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; } NS_IMETHODIMP nsWindowMemoryReporter::GetExplicitNonHeap(int64_t* aAmount) { // This reporter only measures heap memory, so we don't need to report any // bytes for it. However, the JS multi-reporter needs to be invoked. @@ -458,17 +451,17 @@ nsWindowMemoryReporter::ObserveDOMWindow } } 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
--- a/dom/base/nsWindowMemoryReporter.h +++ b/dom/base/nsWindowMemoryReporter.h @@ -1,9 +1,10 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- 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/. */ #ifndef nsWindowMemoryReporter_h__ #define nsWindowMemoryReporter_h__ #include "nsIMemoryReporter.h" @@ -29,16 +30,17 @@ public: mMallocSizeOf = aMallocSizeOf; } nsMallocSizeOfFun mMallocSizeOf; nsArenaMemoryStats mArenaStats; size_t mDOMElementNodes; size_t mDOMTextNodes; size_t mDOMCDATANodes; size_t mDOMCommentNodes; + size_t mDOMEventTargets; size_t mDOMOther; size_t mStyleSheets; size_t mLayoutPresShell; size_t mLayoutStyleSets; size_t mLayoutTextRuns; size_t mLayoutPresContext; size_t mPropertyTables; };
--- a/xpcom/base/nsISizeOf.h +++ b/xpcom/base/nsISizeOf.h @@ -1,9 +1,10 @@ -/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- 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/. */ #ifndef nsISizeOf_h___ #define nsISizeOf_h___ #include "nsISupports.h"