Backout c375efe78e07 (bug 1161377 part 3) for (probably) increasing the static constructor count and regressing Fennec start-up time. r=me.

This commit is contained in:
Nicholas Nethercote 2015-05-10 22:16:18 -07:00
parent a11787749a
commit bdb7128dd1
9 changed files with 125 additions and 58 deletions

View File

@ -287,18 +287,21 @@ nsPropertyTable::PropertyList::PropertyList(nsIAtom *aName,
void *aDtorData,
bool aTransfer)
: mName(aName),
mObjectValueMap(PL_DHashGetStubOps(), sizeof(PropertyListMapEntry)),
mDtorFunc(aDtorFunc),
mDtorData(aDtorData),
mTransfer(aTransfer),
mNext(nullptr)
{
PL_DHashTableInit(&mObjectValueMap, PL_DHashGetStubOps(),
sizeof(PropertyListMapEntry));
}
nsPropertyTable::PropertyList::~PropertyList()
{
PL_DHashTableFinish(&mObjectValueMap);
}
static PLDHashOperator
DestroyPropertyEnumerator(PLDHashTable *table, PLDHashEntryHdr *hdr,
uint32_t number, void *arg)

View File

@ -617,9 +617,18 @@ FT2FontFamily::AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList,
class FontNameCache {
public:
FontNameCache()
: mMap(&sMapOps, sizeof(FNCMapEntry), 0)
, mWriteNeeded(false)
: mWriteNeeded(false)
{
mOps = (PLDHashTableOps) {
StringHash,
HashMatchEntry,
MoveEntry,
PL_DHashClearEntryStub,
nullptr
};
PL_DHashTableInit(&mMap, &mOps, sizeof(FNCMapEntry), 0);
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
"StartupCacheFontNameCache should only be used in chrome "
"process");
@ -630,12 +639,17 @@ public:
~FontNameCache()
{
if (!mMap.IsInitialized()) {
return;
}
if (!mWriteNeeded || !mCache) {
PL_DHashTableFinish(&mMap);
return;
}
nsAutoCString buf;
PL_DHashTableEnumerate(&mMap, WriteOutMap, &buf);
PL_DHashTableFinish(&mMap);
mCache->PutBuffer(CACHE_KEY, buf.get(), buf.Length() + 1);
}
@ -737,7 +751,7 @@ private:
PLDHashTable mMap;
bool mWriteNeeded;
static const PLDHashTableOps sMapOps;
PLDHashTableOps mOps;
static PLDHashOperator WriteOutMap(PLDHashTable *aTable,
PLDHashEntryHdr *aHdr,
@ -796,15 +810,6 @@ private:
}
};
/* static */ const PLDHashTableOps FontNameCache::sMapOps =
{
FontNameCache::StringHash,
FontNameCache::HashMatchEntry,
FontNameCache::MoveEntry,
PL_DHashClearEntryStub,
nullptr
};
/***************************************************************
*
* gfxFT2FontList

View File

@ -489,14 +489,6 @@ protected:
RuleHash::RuleHash(bool aQuirksMode)
: mRuleCount(0),
mIdTable(aQuirksMode ? &RuleHash_IdTable_CIOps.ops
: &RuleHash_IdTable_CSOps.ops,
sizeof(RuleHashTableEntry)),
mClassTable(aQuirksMode ? &RuleHash_ClassTable_CIOps.ops
: &RuleHash_ClassTable_CSOps.ops,
sizeof(RuleHashTableEntry)),
mTagTable(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
mNameSpaceTable(&RuleHash_NameSpaceTable_Ops, sizeof(RuleHashTableEntry)),
mUniversalRules(0),
mEnumList(nullptr), mEnumListSize(0),
mQuirksMode(aQuirksMode)
@ -516,6 +508,20 @@ RuleHash::RuleHash(bool aQuirksMode)
#endif
{
MOZ_COUNT_CTOR(RuleHash);
PL_DHashTableInit(&mIdTable, aQuirksMode ? &RuleHash_IdTable_CIOps.ops
: &RuleHash_IdTable_CSOps.ops,
sizeof(RuleHashTableEntry));
PL_DHashTableInit(&mClassTable, aQuirksMode ? &RuleHash_ClassTable_CIOps.ops
: &RuleHash_ClassTable_CSOps.ops,
sizeof(RuleHashTableEntry));
PL_DHashTableInit(&mTagTable, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
PL_DHashTableInit(&mNameSpaceTable, &RuleHash_NameSpaceTable_Ops,
sizeof(RuleHashTableEntry));
}
RuleHash::~RuleHash()
@ -557,6 +563,11 @@ RuleHash::~RuleHash()
if (nullptr != mEnumList) {
delete [] mEnumList;
}
// delete arena for strings and small objects
PL_DHashTableFinish(&mIdTable);
PL_DHashTableFinish(&mClassTable);
PL_DHashTableFinish(&mTagTable);
PL_DHashTableFinish(&mNameSpaceTable);
}
void RuleHash::AppendRuleToTable(PLDHashTable* aTable, const void* aKey,
@ -855,31 +866,42 @@ struct RuleCascadeData {
: mRuleHash(aQuirksMode),
mStateSelectors(),
mSelectorDocumentStates(0),
mClassSelectors(aQuirksMode ? &AtomSelector_CIOps.ops
: &AtomSelector_CSOps,
sizeof(AtomSelectorEntry)),
mIdSelectors(aQuirksMode ? &AtomSelector_CIOps.ops
: &AtomSelector_CSOps,
sizeof(AtomSelectorEntry)),
// mAttributeSelectors is matching on the attribute _name_, not the
// value, and we case-fold names at parse-time, so this is a
// case-sensitive match.
mAttributeSelectors(&AtomSelector_CSOps, sizeof(AtomSelectorEntry)),
mAnonBoxRules(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
#ifdef MOZ_XUL
mXULTreeRules(&RuleHash_TagTable_Ops, sizeof(RuleHashTagTableEntry)),
#endif
mKeyframesRuleTable(),
mCounterStyleRuleTable(),
mCacheKey(aMedium),
mNext(nullptr),
mQuirksMode(aQuirksMode)
{
// mAttributeSelectors is matching on the attribute _name_, not the value,
// and we case-fold names at parse-time, so this is a case-sensitive match.
PL_DHashTableInit(&mAttributeSelectors, &AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
PL_DHashTableInit(&mAnonBoxRules, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
PL_DHashTableInit(&mIdSelectors,
aQuirksMode ? &AtomSelector_CIOps.ops :
&AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
PL_DHashTableInit(&mClassSelectors,
aQuirksMode ? &AtomSelector_CIOps.ops :
&AtomSelector_CSOps,
sizeof(AtomSelectorEntry));
memset(mPseudoElementRuleHashes, 0, sizeof(mPseudoElementRuleHashes));
#ifdef MOZ_XUL
PL_DHashTableInit(&mXULTreeRules, &RuleHash_TagTable_Ops,
sizeof(RuleHashTagTableEntry));
#endif
}
~RuleCascadeData()
{
PL_DHashTableFinish(&mAttributeSelectors);
PL_DHashTableFinish(&mAnonBoxRules);
PL_DHashTableFinish(&mIdSelectors);
PL_DHashTableFinish(&mClassSelectors);
#ifdef MOZ_XUL
PL_DHashTableFinish(&mXULTreeRules);
#endif
for (uint32_t i = 0; i < ArrayLength(mPseudoElementRuleHashes); ++i) {
delete mPseudoElementRuleHashes[i];
}
@ -3298,9 +3320,11 @@ struct CascadeEnumData {
mPageRules(aPageRules),
mCounterStyleRules(aCounterStyleRules),
mCacheKey(aKey),
mRulesByWeight(&gRulesByWeightOps, sizeof(RuleByWeightEntry), 32),
mSheetType(aSheetType)
{
PL_DHashTableInit(&mRulesByWeight, &gRulesByWeightOps,
sizeof(RuleByWeightEntry), 32);
// Initialize our arena
PL_INIT_ARENA_POOL(&mArena, "CascadeEnumDataArena",
NS_CASCADEENUMDATA_ARENA_BLOCK_SIZE);
@ -3308,6 +3332,8 @@ struct CascadeEnumData {
~CascadeEnumData()
{
if (mRulesByWeight.IsInitialized())
PL_DHashTableFinish(&mRulesByWeight);
PL_FinishArenaPool(&mArena);
}

View File

@ -39,15 +39,22 @@ static const PLDHashTableOps gSetOps = {
nsNSSShutDownList *nsNSSShutDownList::singleton = nullptr;
nsNSSShutDownList::nsNSSShutDownList()
: mListLock("nsNSSShutDownList.mListLock")
, mActiveSSLSockets(0)
, mObjects(&gSetOps, sizeof(ObjectHashEntry))
, mPK11LogoutCancelObjects(&gSetOps, sizeof(ObjectHashEntry))
:mListLock("nsNSSShutDownList.mListLock")
{
mActiveSSLSockets = 0;
PL_DHashTableInit(&mObjects, &gSetOps, sizeof(ObjectHashEntry));
PL_DHashTableInit(&mPK11LogoutCancelObjects, &gSetOps,
sizeof(ObjectHashEntry));
}
nsNSSShutDownList::~nsNSSShutDownList()
{
if (mObjects.IsInitialized()) {
PL_DHashTableFinish(&mObjects);
}
if (mPK11LogoutCancelObjects.IsInitialized()) {
PL_DHashTableFinish(&mPK11LogoutCancelObjects);
}
PR_ASSERT(this == singleton);
singleton = nullptr;
}

View File

@ -157,8 +157,8 @@ private:
protected:
mozilla::Mutex mListLock;
static nsNSSShutDownList *singleton;
uint32_t mActiveSSLSockets;
PLDHashTable mObjects;
uint32_t mActiveSSLSockets;
PLDHashTable mPK11LogoutCancelObjects;
nsNSSActivityState mActivityState;
};

View File

@ -91,22 +91,12 @@ class nsDefaultComparator <nsDocLoader::nsListenerInfo, nsIWebProgressListener*>
}
};
/* static */ const PLDHashTableOps nsDocLoader::sRequestInfoHashOps =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
nsDocLoader::RequestInfoHashClearEntry,
nsDocLoader::RequestInfoHashInitEntry
};
nsDocLoader::nsDocLoader()
: mParent(nullptr),
mCurrentSelfProgress(0),
mMaxSelfProgress(0),
mCurrentTotalProgress(0),
mMaxTotalProgress(0),
mRequestInfoHash(&sRequestInfoHashOps, sizeof(nsRequestInfo)),
mCompletedTotalProgress(0),
mIsLoadingDocument(false),
mIsRestoringDocument(false),
@ -117,6 +107,17 @@ nsDocLoader::nsDocLoader()
gDocLoaderLog = PR_NewLogModule("DocLoader");
}
static const PLDHashTableOps hash_table_ops =
{
PL_DHashVoidPtrKeyStub,
PL_DHashMatchEntryStub,
PL_DHashMoveEntryStub,
RequestInfoHashClearEntry,
RequestInfoHashInitEntry
};
PL_DHashTableInit(&mRequestInfoHash, &hash_table_ops, sizeof(nsRequestInfo));
ClearInternalProgress();
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
@ -133,6 +134,10 @@ nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
nsresult
nsDocLoader::Init()
{
if (!mRequestInfoHash.IsInitialized()) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
if (NS_FAILED(rv)) return rv;
@ -161,6 +166,10 @@ nsDocLoader::~nsDocLoader()
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: deleted.\n", this));
if (mRequestInfoHash.IsInitialized()) {
PL_DHashTableFinish(&mRequestInfoHash);
}
}
@ -1352,6 +1361,12 @@ RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, uint32_t number,
void nsDocLoader::ClearRequestInfoHash(void)
{
if (!mRequestInfoHash.IsInitialized() || !mRequestInfoHash.EntryCount()) {
// No hash, or the hash is empty, nothing to do here then...
return;
}
PL_DHashTableEnumerate(&mRequestInfoHash, RemoveInfoCallback, nullptr);
}

View File

@ -302,8 +302,6 @@ protected:
bool mIsFlushingLayout;
private:
static const PLDHashTableOps sRequestInfoHashOps;
// A list of kids that are in the middle of their onload calls and will let
// us know once they're done. We don't want to fire onload for "normal"
// DocLoaderIsEmpty calls (those coming from requests finishing in our

View File

@ -460,14 +460,19 @@ nsPropertiesParser::ParseBuffer(const char16_t* aBuffer,
nsPersistentProperties::nsPersistentProperties()
: mIn(nullptr)
, mTable(&property_HashTableOps, sizeof(PropertyTableEntry), 16)
{
PL_DHashTableInit(&mTable, &property_HashTableOps,
sizeof(PropertyTableEntry), 16);
PL_INIT_ARENA_POOL(&mArena, "PersistentPropertyArena", 2048);
}
nsPersistentProperties::~nsPersistentProperties()
{
PL_FinishArenaPool(&mArena);
if (mTable.IsInitialized()) {
PL_DHashTableFinish(&mTable);
}
}
nsresult

View File

@ -53,7 +53,8 @@ static bool test_pldhash_Init_capacity_ok()
static bool test_pldhash_lazy_storage()
{
PLDHashTable t(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub));
PLDHashTable t;
PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(PLDHashEntryStub));
// PLDHashTable allocates entry storage lazily. Check that all the non-add
// operations work appropriately when the table is empty and the storage
@ -106,6 +107,8 @@ static bool test_pldhash_lazy_storage()
return false; // size is non-zero?
}
PL_DHashTableFinish(&t);
return true;
}
@ -128,15 +131,19 @@ static bool test_pldhash_move_semantics()
nullptr
};
PLDHashTable t1(&ops, sizeof(PLDHashEntryStub));
PLDHashTable t1, t2;
PL_DHashTableInit(&t1, &ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t1, (const void*)88);
PLDHashTable t2(&ops, sizeof(PLDHashEntryStub));
PL_DHashTableInit(&t2, &ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t2, (const void*)99);
t1 = mozilla::Move(t1); // self-move
t1 = mozilla::Move(t2); // inited overwritten with inited
PL_DHashTableFinish(&t1);
PL_DHashTableFinish(&t2);
PLDHashTable t3, t4;
PL_DHashTableInit(&t3, &ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t3, (const void*)88);
@ -158,7 +165,8 @@ static bool test_pldhash_move_semantics()
PLDHashTable t7;
PLDHashTable t8(mozilla::Move(t7)); // new table constructed with uninited
PLDHashTable t9(&ops, sizeof(PLDHashEntryStub));
PLDHashTable t9;
PL_DHashTableInit(&t9, &ops, sizeof(PLDHashEntryStub));
PL_DHashTableAdd(&t9, (const void*)88);
PLDHashTable t10(mozilla::Move(t9)); // new table constructed with inited