Bug 772292 - Convert JSObject2WrappedJSMap to a new-style HashTable; r=mrbkap

--HG--
extra : rebase_source : a51ae61fde535ba18e84bec484509099101247ab
This commit is contained in:
Terrence Cole 2012-07-07 16:11:54 -07:00
Родитель 58ac09c54d
Коммит 84c4cce3bb
3 изменённых файлов: 69 добавлений и 125 удалений

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

@ -68,25 +68,6 @@ const char* XPCJSRuntime::mStrings[] = {
/***************************************************************************/
static JSDHashOperator
WrappedJSDyingJSObjectFinder(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
nsTArray<nsXPCWrappedJS*>* array = static_cast<nsTArray<nsXPCWrappedJS*>*>(arg);
nsXPCWrappedJS* wrapper = ((JSObject2WrappedJSMap::Entry*)hdr)->value;
NS_ASSERTION(wrapper, "found a null JS wrapper!");
// walk the wrapper chain and find any whose JSObject is to be finalized
while (wrapper) {
if (wrapper->IsSubjectToFinalization()) {
if (JS_IsAboutToBeFinalized(wrapper->GetJSObjectPreserveColor()))
array->AppendElement(wrapper);
}
wrapper = wrapper->GetNextWrapper();
}
return JS_DHASH_NEXT;
}
struct CX_AND_XPCRT_Data
{
JSContext* cx;
@ -651,8 +632,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
// We add them to the array now and Release the array members
// later to avoid the posibility of doing any JS GCThing
// allocations during the gc cycle.
self->mWrappedJSMap->
Enumerate(WrappedJSDyingJSObjectFinder, dyingWrappedJSArray);
self->mWrappedJSMap->FindDyingJSObjects(dyingWrappedJSArray);
// Find dying scopes.
XPCWrappedNativeScope::StartFinalizationPhaseOfGC(fop, self);
@ -944,18 +924,6 @@ DEBUG_WrapperChecker(JSDHashTable *table, JSDHashEntryHdr *hdr,
}
#endif
static JSDHashOperator
WrappedJSShutdownMarker(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
JSRuntime* rt = (JSRuntime*) arg;
nsXPCWrappedJS* wrapper = ((JSObject2WrappedJSMap::Entry*)hdr)->value;
NS_ASSERTION(wrapper, "found a null JS wrapper!");
NS_ASSERTION(wrapper->IsValid(), "found an invalid JS wrapper!");
wrapper->SystemIsBeingShutDown(rt);
return JS_DHASH_NEXT;
}
static JSDHashOperator
DetachedWrappedNativeProtoShutdownMarker(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32_t number, void *arg)
@ -1038,7 +1006,7 @@ XPCJSRuntime::~XPCJSRuntime()
if (count)
printf("deleting XPCJSRuntime with %d live wrapped JSObject\n", (int)count);
#endif
mWrappedJSMap->Enumerate(WrappedJSShutdownMarker, mJSRuntime);
mWrappedJSMap->ShutdownMarker(mJSRuntime);
delete mWrappedJSMap;
}
@ -2204,13 +2172,6 @@ WrappedJSClassMapDumpEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
return JS_DHASH_NEXT;
}
static JSDHashOperator
WrappedJSMapDumpEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
((JSObject2WrappedJSMap::Entry*)hdr)->value->DebugDump(*(PRInt16*)arg);
return JS_DHASH_NEXT;
}
static JSDHashOperator
NativeSetDumpEnumerator(JSDHashTable *table, JSDHashEntryHdr *hdr,
uint32_t number, void *arg)
{
@ -2263,7 +2224,7 @@ XPCJSRuntime::DebugDump(PRInt16 depth)
// iterate wrappers...
if (depth && mWrappedJSMap && mWrappedJSMap->Count()) {
XPC_LOG_INDENT();
mWrappedJSMap->Enumerate(WrappedJSMapDumpEnumerator, &depth);
mWrappedJSMap->Dump(depth);
XPC_LOG_OUTDENT();
}

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

@ -80,43 +80,33 @@ HashNativeKey(JSDHashTable *table, const void *key)
/***************************************************************************/
// implement JSObject2WrappedJSMap...
// static
JSObject2WrappedJSMap*
JSObject2WrappedJSMap::newMap(int size)
void
JSObject2WrappedJSMap::FindDyingJSObjects(nsTArray<nsXPCWrappedJS*>* dying)
{
JSObject2WrappedJSMap* map = new JSObject2WrappedJSMap(size);
if (map && map->mTable)
return map;
delete map;
return nsnull;
for (Map::Range r = mTable.all(); !r.empty(); r.popFront()) {
nsXPCWrappedJS* wrapper = r.front().value;
NS_ASSERTION(wrapper, "found a null JS wrapper!");
// walk the wrapper chain and find any whose JSObject is to be finalized
while (wrapper) {
if (wrapper->IsSubjectToFinalization()) {
if (JS_IsAboutToBeFinalized(wrapper->GetJSObjectPreserveColor()))
dying->AppendElement(wrapper);
}
wrapper = wrapper->GetNextWrapper();
}
}
}
JSObject2WrappedJSMap::JSObject2WrappedJSMap(int size)
void
JSObject2WrappedJSMap::ShutdownMarker(JSRuntime* rt)
{
mTable = JS_NewDHashTable(JS_DHashGetStubOps(), nsnull,
sizeof(Entry), size);
}
JSObject2WrappedJSMap::~JSObject2WrappedJSMap()
{
if (mTable)
JS_DHashTableDestroy(mTable);
}
size_t
JSObject2WrappedJSMap::SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf)
{
size_t n = 0;
n += mallocSizeOf(this);
n += mTable ? JS_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf) : 0;
return n;
}
/* static */ size_t
JSObject2WrappedJSMap::SizeOfEntryExcludingThis(JSDHashEntryHdr *hdr,
JSMallocSizeOfFun mallocSizeOf, void *)
{
return mallocSizeOf(((JSObject2WrappedJSMap::Entry*)hdr)->value);
for (Map::Range r = mTable.all(); !r.empty(); r.popFront()) {
nsXPCWrappedJS* wrapper = r.front().value;
NS_ASSERTION(wrapper, "found a null JS wrapper!");
NS_ASSERTION(wrapper->IsValid(), "found an invalid JS wrapper!");
wrapper->SystemIsBeingShutDown(rt);
}
}
/***************************************************************************/

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

@ -25,62 +25,60 @@
class JSObject2WrappedJSMap
{
typedef js::HashMap<JSObject*, nsXPCWrappedJS*, js::PointerHasher<JSObject*, 3>,
js::SystemAllocPolicy> Map;
public:
struct Entry : public JSDHashEntryHdr
{
JSObject* key;
nsXPCWrappedJS* value;
};
static JSObject2WrappedJSMap* newMap(int size);
inline nsXPCWrappedJS* Find(JSObject* Obj)
{
NS_PRECONDITION(Obj,"bad param");
Entry* entry = (Entry*)
JS_DHashTableOperate(mTable, Obj, JS_DHASH_LOOKUP);
if (JS_DHASH_ENTRY_IS_FREE(entry))
return nsnull;
return entry->value;
static JSObject2WrappedJSMap* newMap(int size) {
JSObject2WrappedJSMap* map = new JSObject2WrappedJSMap();
if (map && map->mTable.init(size))
return map;
delete map;
return nsnull;
}
inline nsXPCWrappedJS* Add(nsXPCWrappedJS* wrapper)
{
inline nsXPCWrappedJS* Find(JSObject* Obj) {
NS_PRECONDITION(Obj,"bad param");
Map::Ptr p = mTable.lookup(Obj);
return p ? p->value : nsnull;
}
inline nsXPCWrappedJS* Add(nsXPCWrappedJS* wrapper) {
NS_PRECONDITION(wrapper,"bad param");
JSObject* obj = wrapper->GetJSObjectPreserveColor();
Entry* entry = (Entry*)
JS_DHashTableOperate(mTable, obj, JS_DHASH_ADD);
if (!entry)
return nsnull;
if (entry->key)
return entry->value;
entry->key = obj;
entry->value = wrapper;
return wrapper;
Map::AddPtr p = mTable.lookupForAdd(obj);
if (p)
return p->value;
return mTable.add(p, obj, wrapper) ? wrapper : nsnull;
}
inline void Remove(nsXPCWrappedJS* wrapper)
{
inline void Remove(nsXPCWrappedJS* wrapper) {
NS_PRECONDITION(wrapper,"bad param");
JS_DHashTableOperate(mTable, wrapper->GetJSObjectPreserveColor(),
JS_DHASH_REMOVE);
mTable.remove(wrapper->GetJSObjectPreserveColor());
}
inline uint32_t Count() {return mTable->entryCount;}
inline uint32_t Enumerate(JSDHashEnumerator f, void *arg)
{return JS_DHashTableEnumerate(mTable, f, arg);}
inline uint32_t Count() {return mTable.count();}
size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
inline void Dump(PRInt16 depth) {
for (Map::Range r = mTable.all(); !r.empty(); r.popFront())
r.front().value->DebugDump(depth);
}
~JSObject2WrappedJSMap();
private:
JSObject2WrappedJSMap(); // no implementation
JSObject2WrappedJSMap(int size);
void FindDyingJSObjects(nsTArray<nsXPCWrappedJS*>* dying);
static size_t SizeOfEntryExcludingThis(JSDHashEntryHdr *hdr, JSMallocSizeOfFun mallocSizeOf, void *);
void ShutdownMarker(JSRuntime* rt);
size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf) {
size_t n = 0;
n += mallocSizeOf(this);
n += mTable.sizeOfIncludingThis(mallocSizeOf);
return n;
}
private:
JSDHashTable *mTable;
JSObject2WrappedJSMap() {}
Map mTable;
};
/*************************/
@ -609,10 +607,9 @@ class JSObject2JSObjectMap
js::SystemAllocPolicy> Map;
public:
static JSObject2JSObjectMap* newMap(int size)
{
JSObject2JSObjectMap* map = new JSObject2JSObjectMap(size);
if (map && map->mTable.initialized())
static JSObject2JSObjectMap* newMap(int size) {
JSObject2JSObjectMap* map = new JSObject2JSObjectMap();
if (map && map->mTable.init(size))
return map;
delete map;
return nsnull;
@ -669,12 +666,8 @@ public:
}
private:
JSObject2JSObjectMap() MOZ_DELETE;
JSObject2JSObjectMap(int size) {
mTable.init(size);
}
JSObject2JSObjectMap() {}
private:
Map mTable;
};