Followup fixes to making cycle collector use more efficient hashtables: shrink size of table and fix warnings on 64-bit machines. b=377606 sr=peterv r=graydon

This commit is contained in:
dbaron@dbaron.org 2007-04-23 16:34:33 -07:00
Родитель 2019f586fe
Коммит be3b7ec321
2 изменённых файлов: 14 добавлений и 17 удалений

Просмотреть файл

@ -114,8 +114,6 @@ nsXPConnect::nsXPConnect()
typedef nsBaseHashtable<nsVoidPtrHashKey, nsISupports*, nsISupports*> ScopeSet; typedef nsBaseHashtable<nsVoidPtrHashKey, nsISupports*, nsISupports*> ScopeSet;
#endif #endif
#define OBJ_REFCOUNT_ENTRIES 100000
static const PLDHashTableOps RefCountOps = static const PLDHashTableOps RefCountOps =
{ {
PL_DHashAllocTable, PL_DHashAllocTable,
@ -158,15 +156,16 @@ struct JSObjectRefcounts
void InitRefCounts() void InitRefCounts()
{ {
if(!PL_DHashTableInit(&mRefCounts, &RefCountOps, nsnull, if(!PL_DHashTableInit(&mRefCounts, &RefCountOps, nsnull,
sizeof(ObjRefCount), sizeof(ObjRefCount), 65536))
PL_DHASH_DEFAULT_CAPACITY(OBJ_REFCOUNT_ENTRIES)))
mRefCounts.ops = nsnull; mRefCounts.ops = nsnull;
} }
void Clear() void Clear()
{ {
if(!mRefCounts.ops || mRefCounts.entryCount > 0) {
if(mRefCounts.ops) if(mRefCounts.ops)
PL_DHashTableFinish(&mRefCounts); PL_DHashTableFinish(&mRefCounts);
InitRefCounts(); InitRefCounts();
}
#ifndef XPCONNECT_STANDALONE #ifndef XPCONNECT_STANDALONE
mScopes.Clear(); mScopes.Clear();
#endif #endif

Просмотреть файл

@ -296,13 +296,11 @@ enum NodeColor { black, white, grey };
struct PtrInfo struct PtrInfo
: public PLDHashEntryStub : public PLDHashEntryStub
{ {
#define WORD_MINUS_2_BITS ((PR_BYTES_PER_WORD * 8) - 2)
PRUint32 mColor : 2; PRUint32 mColor : 2;
PRUint32 mInternalRefs : WORD_MINUS_2_BITS; PRUint32 mInternalRefs : 30;
// FIXME: mLang expands back to a full word when bug 368774 lands. // FIXME: mLang expands back to a full word when bug 368774 lands.
PRUint32 mLang : 2; PRUint32 mLang : 2;
PRUint32 mRefCount : WORD_MINUS_2_BITS; PRUint32 mRefCount : 30;
#undef WORD_MINUS_2_BITS
#ifdef DEBUG_CC #ifdef DEBUG_CC
size_t mBytes; size_t mBytes;
@ -326,8 +324,6 @@ InitPtrInfo(PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)
return PR_TRUE; return PR_TRUE;
} }
#define GCTABLE_N_ENTRIES 100000
static PLDHashTableOps GCTableOps = { static PLDHashTableOps GCTableOps = {
PL_DHashAllocTable, PL_DHashAllocTable,
PL_DHashFreeTable, PL_DHashFreeTable,
@ -356,15 +352,17 @@ struct GCTable
void Init() void Init()
{ {
if (!PL_DHashTableInit(&mTab, &GCTableOps, nsnull, sizeof(PtrInfo), if (!PL_DHashTableInit(&mTab, &GCTableOps, nsnull, sizeof(PtrInfo),
PL_DHASH_DEFAULT_CAPACITY(GCTABLE_N_ENTRIES))) 32768))
mTab.ops = nsnull; mTab.ops = nsnull;
} }
void Clear() void Clear()
{ {
if (!mTab.ops || mTab.entryCount > 0) {
if (mTab.ops) if (mTab.ops)
PL_DHashTableFinish(&mTab); PL_DHashTableFinish(&mTab);
Init(); Init();
} }
}
PtrInfo *Lookup(void *key) PtrInfo *Lookup(void *key)
{ {