mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 807850 - Add a memory reporter for the nsScriptNameSpaceManager. r=jst.
--HG-- extra : rebase_source : bd6e263678aab5477ba11c70015b1537278914b3
This commit is contained in:
parent
90f909caac
commit
e03f6bee47
@ -174,7 +174,26 @@ static uint32_t sCleanupsSinceLastGC = UINT32_MAX;
|
||||
static bool sNeedsFullCC = false;
|
||||
static nsJSContext *sContextList = nullptr;
|
||||
|
||||
nsScriptNameSpaceManager *gNameSpaceManager;
|
||||
static nsScriptNameSpaceManager *gNameSpaceManager;
|
||||
static nsIMemoryReporter *gReporter;
|
||||
|
||||
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(ScriptNameSpaceManagerMallocSizeOf,
|
||||
"script-namespace-manager")
|
||||
|
||||
static int64_t
|
||||
GetScriptNameSpaceManagerSize()
|
||||
{
|
||||
MOZ_ASSERT(gNameSpaceManager);
|
||||
return gNameSpaceManager->SizeOfIncludingThis(
|
||||
ScriptNameSpaceManagerMallocSizeOf);
|
||||
}
|
||||
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(ScriptNameSpaceManager,
|
||||
"explicit/script-namespace-manager",
|
||||
KIND_HEAP,
|
||||
nsIMemoryReporter::UNITS_BYTES,
|
||||
GetScriptNameSpaceManagerSize,
|
||||
"Memory used for the script namespace manager.")
|
||||
|
||||
static nsIJSRuntimeService *sRuntimeService;
|
||||
JSRuntime *nsJSRuntime::sRuntime;
|
||||
@ -3644,6 +3663,7 @@ nsJSRuntime::Startup()
|
||||
sDisableExplicitCompartmentGC = false;
|
||||
sNeedsFullCC = false;
|
||||
gNameSpaceManager = nullptr;
|
||||
gReporter = nullptr;
|
||||
sRuntimeService = nullptr;
|
||||
sRuntime = nullptr;
|
||||
sIsInitialized = false;
|
||||
@ -3986,6 +4006,9 @@ nsJSRuntime::GetNameSpaceManager()
|
||||
|
||||
nsresult rv = gNameSpaceManager->Init();
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
gReporter = new NS_MEMORY_REPORTER_NAME(ScriptNameSpaceManager);
|
||||
NS_RegisterMemoryReporter(gReporter);
|
||||
}
|
||||
|
||||
return gNameSpaceManager;
|
||||
@ -4002,6 +4025,10 @@ nsJSRuntime::Shutdown()
|
||||
nsJSContext::KillInterSliceGCTimer();
|
||||
|
||||
NS_IF_RELEASE(gNameSpaceManager);
|
||||
if (gReporter) {
|
||||
(void)::NS_UnregisterMemoryReporter(gReporter);
|
||||
gReporter = nullptr;
|
||||
}
|
||||
|
||||
if (!sContextCount) {
|
||||
// We're being shutdown, and there are no more contexts
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
@ -37,6 +38,13 @@ public:
|
||||
// Our hash table ops don't care about the order of these members
|
||||
nsString mKey;
|
||||
nsGlobalNameStruct mGlobalName;
|
||||
|
||||
size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) {
|
||||
// Measurement of the following members may be added later if DMD finds it
|
||||
// is worthwhile:
|
||||
// - mGlobalName
|
||||
return mKey.SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -793,3 +801,22 @@ nsScriptNameSpaceManager::RegisterDefineDOMInterface(const nsAFlatString& aName,
|
||||
s->mPrefEnabled = aPrefEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
SizeOfEntryExcludingThis(PLDHashEntryHdr *aHdr, nsMallocSizeOfFun aMallocSizeOf,
|
||||
void *aArg)
|
||||
{
|
||||
GlobalNameMapEntry* entry = static_cast<GlobalNameMapEntry*>(aHdr);
|
||||
return entry->SizeOfExcludingThis(aMallocSizeOf);
|
||||
}
|
||||
|
||||
size_t
|
||||
nsScriptNameSpaceManager::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
||||
{
|
||||
size_t n = 0;
|
||||
n += PL_DHashTableSizeOfExcludingThis(&mGlobalNames,
|
||||
SizeOfEntryExcludingThis, aMallocSizeOf);
|
||||
n += PL_DHashTableSizeOfExcludingThis(&mNavigatorNames,
|
||||
SizeOfEntryExcludingThis, aMallocSizeOf);
|
||||
return n;
|
||||
}
|
||||
|
@ -143,6 +143,8 @@ public:
|
||||
mozilla::dom::DefineInterface aDefineDOMInterface,
|
||||
mozilla::dom::PrefEnabled aPrefEnabled);
|
||||
|
||||
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
||||
|
||||
private:
|
||||
// Adds a new entry to the hash and returns the nsGlobalNameStruct
|
||||
// that aKey will be mapped to. If mType in the returned
|
||||
|
Loading…
Reference in New Issue
Block a user