Bug 934442 - Defer finalization of object ID table until after minor GC r=terrence

This commit is contained in:
Jon Coppeard 2013-11-18 17:21:43 +00:00
parent 15af5c4f84
commit 6d139a1da0
2 changed files with 24 additions and 12 deletions

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "JavaScriptShared.h"
#include "mozilla/dom/BindingUtils.h"
#include "jsfriendapi.h"
#include "xpcprivate.h"
@ -57,20 +58,30 @@ ObjectStore::remove(ObjectId id)
}
ObjectIdCache::ObjectIdCache()
: table_(SystemAllocPolicy())
: table_(nullptr)
{
}
ObjectIdCache::~ObjectIdCache()
{
if (table_) {
dom::AddForDeferredFinalization<ObjectIdTable, nsAutoPtr>(table_);
table_ = nullptr;
}
}
bool
ObjectIdCache::init()
{
return table_.init(32);
MOZ_ASSERT(!table_);
table_ = new ObjectIdTable(SystemAllocPolicy());
return table_ && table_->init(32);
}
void
ObjectIdCache::trace(JSTracer *trc)
{
for (ObjectIdTable::Range r(table_.all()); !r.empty(); r.popFront()) {
for (ObjectIdTable::Range r(table_->all()); !r.empty(); r.popFront()) {
JSObject *obj = r.front().key;
JS_CallObjectTracer(trc, &obj, "ipc-id");
MOZ_ASSERT(obj == r.front().key);
@ -80,7 +91,7 @@ ObjectIdCache::trace(JSTracer *trc)
ObjectId
ObjectIdCache::find(JSObject *obj)
{
ObjectIdTable::Ptr p = table_.lookup(obj);
ObjectIdTable::Ptr p = table_->lookup(obj);
if (!p)
return 0;
return p->value;
@ -89,9 +100,9 @@ ObjectIdCache::find(JSObject *obj)
bool
ObjectIdCache::add(JSContext *cx, JSObject *obj, ObjectId id)
{
if (!table_.put(obj, id))
if (!table_->put(obj, id))
return false;
JS_StoreObjectPostBarrierCallback(cx, keyMarkCallback, obj, this);
JS_StoreObjectPostBarrierCallback(cx, keyMarkCallback, obj, table_);
return true;
}
@ -100,18 +111,18 @@ ObjectIdCache::add(JSContext *cx, JSObject *obj, ObjectId id)
* been moved.
*/
/* static */ void
ObjectIdCache::keyMarkCallback(JSTracer *trc, void *k, void *d) {
JSObject *key = static_cast<JSObject*>(k);
ObjectIdCache* self = static_cast<ObjectIdCache*>(d);
ObjectIdCache::keyMarkCallback(JSTracer *trc, void *keyArg, void *dataArg) {
JSObject *key = static_cast<JSObject*>(keyArg);
ObjectIdTable* table = static_cast<ObjectIdTable*>(dataArg);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "ObjectIdCache::table_ key");
self->table_.rekeyIfMoved(prior, key);
table->rekeyIfMoved(prior, key);
}
void
ObjectIdCache::remove(JSObject *obj)
{
table_.remove(obj);
table_->remove(obj);
}
bool

View File

@ -65,6 +65,7 @@ class ObjectIdCache
public:
ObjectIdCache();
~ObjectIdCache();
bool init();
void trace(JSTracer *trc);
@ -76,7 +77,7 @@ class ObjectIdCache
private:
static void keyMarkCallback(JSTracer *trc, void *key, void *data);
ObjectIdTable table_;
ObjectIdTable *table_;
};
class JavaScriptShared