Skip to content

Commit

Permalink
Backout c375efe78e07 (bug 1161377 part 3) for (probably) increasing t…
Browse files Browse the repository at this point in the history
…he static constructor count and regressing Fennec start-up time. r=me.
  • Loading branch information
nnethercote committed May 11, 2015
1 parent bf83499 commit 425242e
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 58 deletions.
5 changes: 4 additions & 1 deletion dom/base/nsPropertyTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 17 additions & 12 deletions gfx/thebes/gfxFT2FontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -630,12 +639,17 @@ class FontNameCache {

~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);
}

Expand Down Expand Up @@ -737,7 +751,7 @@ class FontNameCache {
PLDHashTable mMap;
bool mWriteNeeded;

static const PLDHashTableOps sMapOps;
PLDHashTableOps mOps;

static PLDHashOperator WriteOutMap(PLDHashTable *aTable,
PLDHashEntryHdr *aHdr,
Expand Down Expand Up @@ -796,15 +810,6 @@ class FontNameCache {
}
};

/* static */ const PLDHashTableOps FontNameCache::sMapOps =
{
FontNameCache::StringHash,
FontNameCache::HashMatchEntry,
FontNameCache::MoveEntry,
PL_DHashClearEntryStub,
nullptr
};

/***************************************************************
*
* gfxFT2FontList
Expand Down
72 changes: 49 additions & 23 deletions layout/style/nsCSSRuleProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,6 @@ class RuleHash {

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)
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -3298,16 +3320,20 @@ 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);
}

~CascadeEnumData()
{
if (mRulesByWeight.IsInitialized())
PL_DHashTableFinish(&mRulesByWeight);
PL_FinishArenaPool(&mArena);
}

Expand Down
15 changes: 11 additions & 4 deletions security/manager/ssl/src/nsNSSShutDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion security/manager/ssl/src/nsNSSShutDown.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class nsNSSShutDownList
protected:
mozilla::Mutex mListLock;
static nsNSSShutDownList *singleton;
uint32_t mActiveSSLSockets;
PLDHashTable mObjects;
uint32_t mActiveSSLSockets;
PLDHashTable mPK11LogoutCancelObjects;
nsNSSActivityState mActivityState;
};
Expand Down
35 changes: 25 additions & 10 deletions uriloader/base/nsDocLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -161,6 +166,10 @@ nsDocLoader::~nsDocLoader()

PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: deleted.\n", this));

if (mRequestInfoHash.IsInitialized()) {
PL_DHashTableFinish(&mRequestInfoHash);
}
}


Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions uriloader/base/nsDocLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ class nsDocLoader : public nsIDocumentLoader,
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
Expand Down
7 changes: 6 additions & 1 deletion xpcom/ds/nsPersistentProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 425242e

Please sign in to comment.