Bug 1450359, part 2 - Inline mWorkingSet into XPTInterfaceInfoManager.
This class is only used in one place, so having two distinct classes
serves no purpose.
MozReview-Commit-ID: DO03ivBJ9in
--- a/xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
+++ b/xpcom/reflect/xptinfo/XPTInterfaceInfoManager.h
@@ -50,28 +50,15 @@ private:
void InitMemoryReporter();
// idx is the index of this interface in the XPTHeader
void VerifyAndAddEntryIfNew(const XPTInterfaceDescriptor* iface,
uint16_t idx,
xptiTypelibGuts* typelib);
-private:
- class xptiWorkingSet
- {
- public:
- xptiWorkingSet();
- ~xptiWorkingSet();
-
- void InvalidateInterfaceInfos();
-
- // XXX make these private with accessors
- nsDataHashtable<nsIDHashKey, xptiInterfaceEntry*> mIIDTable;
- nsDataHashtable<nsDepCharHashKey, xptiInterfaceEntry*> mNameTable;
- };
-
- xptiWorkingSet mWorkingSet;
+ nsDataHashtable<nsIDHashKey, xptiInterfaceEntry*> mIIDTable;
+ nsDataHashtable<nsDepCharHashKey, xptiInterfaceEntry*> mNameTable;
};
} // namespace mozilla
#endif
--- a/xpcom/reflect/xptinfo/moz.build
+++ b/xpcom/reflect/xptinfo/moz.build
@@ -4,17 +4,16 @@
# 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/.
UNIFIED_SOURCES += [
'ShimInterfaceInfo.cpp',
'xptiInterfaceInfo.cpp',
'xptiInterfaceInfoManager.cpp',
'xptiTypelibGuts.cpp',
- 'xptiWorkingSet.cpp',
]
XPIDL_SOURCES += [
'nsIInterfaceInfo.idl',
'nsIInterfaceInfoManager.idl',
]
XPIDL_MODULE = 'xpcom_xpti'
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -16,31 +16,35 @@
#include "nsDependentString.h"
#include "nsString.h"
#include "nsArrayEnumerator.h"
#include "nsDirectoryService.h"
#include "nsIMemoryReporter.h"
using namespace mozilla;
+static const size_t XPTI_ARENA8_BLOCK_SIZE = 16 * 1024;
+static const size_t XPTI_ARENA1_BLOCK_SIZE = 8 * 1024;
+static const uint32_t XPTI_HASHTABLE_LENGTH = 1024;
+
NS_IMPL_ISUPPORTS(XPTInterfaceInfoManager,
nsIInterfaceInfoManager,
nsIMemoryReporter)
static StaticRefPtr<XPTInterfaceInfoManager> gInterfaceInfoManager;
size_t
XPTInterfaceInfoManager::SizeOfIncludingThis(
mozilla::MallocSizeOf aMallocSizeOf)
{
size_t n = aMallocSizeOf(this);
// The entries themselves are allocated out of an arena accounted
// for elsewhere, so don't measure them
- n += mWorkingSet.mIIDTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
- n += mWorkingSet.mNameTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
+ n += mIIDTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
+ n += mNameTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}
MOZ_DEFINE_MALLOC_SIZE_OF(XPTIMallocSizeOf)
NS_IMETHODIMP
XPTInterfaceInfoManager::CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData,
@@ -75,31 +79,43 @@ XPTInterfaceInfoManager::GetSingleton()
void
XPTInterfaceInfoManager::FreeInterfaceInfoManager()
{
gInterfaceInfoManager = nullptr;
}
XPTInterfaceInfoManager::XPTInterfaceInfoManager()
- : mWorkingSet()
+ : mIIDTable(XPTI_HASHTABLE_LENGTH)
+ , mNameTable(XPTI_HASHTABLE_LENGTH)
{
+ gXPTIStructArena =
+ XPT_NewArena(XPTI_ARENA8_BLOCK_SIZE, XPTI_ARENA1_BLOCK_SIZE);
+
xptiTypelibGuts* typelib = xptiTypelibGuts::Create();
for (uint16_t k = 0; k < XPTHeader::kNumInterfaces; k++) {
VerifyAndAddEntryIfNew(XPTHeader::kInterfaces + k, k, typelib);
}
}
XPTInterfaceInfoManager::~XPTInterfaceInfoManager()
{
- // We only do this on shutdown of the service.
- mWorkingSet.InvalidateInterfaceInfos();
+ for (auto iter = mNameTable.Iter(); !iter.Done(); iter.Next()) {
+ xptiInterfaceEntry* entry = iter.UserData();
+ entry->InvalidateInterfaceInfo();
+ }
UnregisterWeakMemoryReporter(this);
+
+ // Only destroy the arena if we're doing leak stats. Why waste shutdown
+ // time touching pages if we don't have to?
+#ifdef NS_FREE_PERMANENT_DATA
+ XPT_DestroyArena(gXPTIStructArena);
+#endif
}
void
XPTInterfaceInfoManager::InitMemoryReporter()
{
RegisterWeakMemoryReporter(this);
}
@@ -121,46 +137,46 @@ XPTInterfaceInfoManager::VerifyAndAddEnt
// in xpcom/reflect/xptcall/genstubs.pl; do not change this value
// without changing that one or you WILL see problems.
if (iface->mNumMethods > 250 && !iface->IsBuiltinClass()) {
NS_ASSERTION(0, "Too many methods to handle for the stub, cannot load");
fprintf(stderr, "ignoring too large interface: %s\n", iface->Name());
return;
}
- xptiInterfaceEntry* entry = mWorkingSet.mIIDTable.Get(iface->mIID);
+ xptiInterfaceEntry* entry = mIIDTable.Get(iface->mIID);
if (entry) {
// XXX validate this info to find possible inconsistencies
return;
}
// Build a new xptiInterfaceEntry object and hook it up.
entry = xptiInterfaceEntry::Create(iface, typelib);
if (!entry)
return;
- mWorkingSet.mIIDTable.Put(entry->IID(), entry);
- mWorkingSet.mNameTable.Put(entry->GetTheName(), entry);
+ mIIDTable.Put(entry->IID(), entry);
+ mNameTable.Put(entry->GetTheName(), entry);
typelib->SetEntryAt(idx, entry);
}
xptiInterfaceEntry*
XPTInterfaceInfoManager::GetInterfaceEntry(const XPTInterfaceDescriptor* aIface)
{
static const nsID zeroIID = {
0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
};
if (aIface->mIID.Equals(zeroIID)) {
- return mWorkingSet.mNameTable.Get(aIface->Name());
+ return mNameTable.Get(aIface->Name());
}
- return mWorkingSet.mIIDTable.Get(aIface->mIID);
+ return mIIDTable.Get(aIface->mIID);
}
// this is a private helper
static nsresult
EntryToInfo(xptiInterfaceEntry* entry, nsIInterfaceInfo** _retval)
{
if (!entry) {
*_retval = nullptr;
@@ -170,51 +186,53 @@ EntryToInfo(xptiInterfaceEntry* entry, n
RefPtr<xptiInterfaceInfo> info = entry->InterfaceInfo();
info.forget(_retval);
return NS_OK;
}
xptiInterfaceEntry*
XPTInterfaceInfoManager::GetInterfaceEntryForIID(const nsIID* iid)
{
- return mWorkingSet.mIIDTable.Get(*iid);
+ return mIIDTable.Get(*iid);
}
NS_IMETHODIMP
XPTInterfaceInfoManager::GetInfoForIID(const nsIID* iid,
nsIInterfaceInfo** _retval)
{
NS_ASSERTION(iid, "bad param");
NS_ASSERTION(_retval, "bad param");
- xptiInterfaceEntry* entry = mWorkingSet.mIIDTable.Get(*iid);
+ xptiInterfaceEntry* entry = mIIDTable.Get(*iid);
return EntryToInfo(entry, _retval);
}
NS_IMETHODIMP
XPTInterfaceInfoManager::GetInfoForName(const char* name,
nsIInterfaceInfo** _retval)
{
NS_ASSERTION(name, "bad param");
NS_ASSERTION(_retval, "bad param");
- xptiInterfaceEntry* entry = mWorkingSet.mNameTable.Get(name);
+ xptiInterfaceEntry* entry = mNameTable.Get(name);
return EntryToInfo(entry, _retval);
}
void
XPTInterfaceInfoManager::GetScriptableInterfaces(
nsCOMArray<nsIInterfaceInfo>& aInterfaces)
{
// I didn't want to incur the size overhead of using nsHashtable just to
// make building an enumerator easier. So, this code makes a snapshot of
// the table using an nsCOMArray and builds an enumerator for that.
// We can afford this transient cost.
- aInterfaces.SetCapacity(mWorkingSet.mNameTable.Count());
- for (auto iter = mWorkingSet.mNameTable.Iter(); !iter.Done(); iter.Next()) {
+ aInterfaces.SetCapacity(mNameTable.Count());
+ for (auto iter = mNameTable.Iter(); !iter.Done(); iter.Next()) {
xptiInterfaceEntry* entry = iter.UserData();
if (entry->GetScriptableFlag()) {
nsCOMPtr<nsIInterfaceInfo> ii = entry->InterfaceInfo();
aInterfaces.AppendElement(ii);
}
}
}
+
+XPTArena* gXPTIStructArena;
deleted file mode 100644
--- a/xpcom/reflect/xptinfo/xptiWorkingSet.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- 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/. */
-
-/* Implementation of xptiWorkingSet. */
-
-#include "mozilla/XPTInterfaceInfoManager.h"
-
-#include "xptiprivate.h"
-#include "nsString.h"
-
-using namespace mozilla;
-
-static const size_t XPTI_ARENA8_BLOCK_SIZE = 16 * 1024;
-static const size_t XPTI_ARENA1_BLOCK_SIZE = 8 * 1024;
-
-static const uint32_t XPTI_HASHTABLE_LENGTH = 1024;
-
-XPTInterfaceInfoManager::xptiWorkingSet::xptiWorkingSet()
- : mIIDTable(XPTI_HASHTABLE_LENGTH)
- , mNameTable(XPTI_HASHTABLE_LENGTH)
-{
- MOZ_COUNT_CTOR(xptiWorkingSet);
-
- gXPTIStructArena =
- XPT_NewArena(XPTI_ARENA8_BLOCK_SIZE, XPTI_ARENA1_BLOCK_SIZE);
-}
-
-void
-XPTInterfaceInfoManager::xptiWorkingSet::InvalidateInterfaceInfos()
-{
- for (auto iter = mNameTable.Iter(); !iter.Done(); iter.Next()) {
- xptiInterfaceEntry* entry = iter.UserData();
- entry->InvalidateInterfaceInfo();
- }
-}
-
-XPTInterfaceInfoManager::xptiWorkingSet::~xptiWorkingSet()
-{
- MOZ_COUNT_DTOR(xptiWorkingSet);
-
- // Only destroy the arena if we're doing leak stats. Why waste shutdown
- // time touching pages if we don't have to?
-#ifdef NS_FREE_PERMANENT_DATA
- XPT_DestroyArena(gXPTIStructArena);
-#endif
-}
-
-XPTArena* gXPTIStructArena;